PHP: Difference between revisions

From DWAMconsult Wiki
Jump to navigation Jump to search
Line 125: Line 125:


* https://tecadmin.net/install-apache-php-fpm-debian-10/
* https://tecadmin.net/install-apache-php-fpm-debian-10/
* Troubleshooting PHP-FPM: https://stackoverflow.com/questions/35261922/how-to-debug-fastcgi-sent-in-stderr-primary-script-unknown-while-reading-respo


== Links ==
== Links ==

Revision as of 10:40, 14 May 2024

Installation

Centos 7

yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

yum -y install yum-utils
yum-config-manager --enable remi-php74
yum update
  • Set the default version of PHP by enabling the repo as above or editing the repo in /etc/yum.repos.d and changing enabled to 1
  • Install additional versions e.g. yum install php82 (the repo doesn't need to be enabled to do this, just present in the yum.repos.d directory)

Centos 8/Rocky Linux/Alma

  • Base OS comes with limit PHP versions
dnf module reset php
dnf module enable php:7.4
dnf update
  • Add Remi repo for more versions:
dnf -y install epel-release
dnf config-manager --set-enabled powertools
dnf -y install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf -y makecache
dnf -y repolist
dnf module list php
dnf install php82 # Using this to install PHP 8.2 as a new version alongside existing versions
                  # if you want to upgrade current version, first do the reset command, enable php:remi-<version> then update as above
  • List enabled modules: php --modules
  • install additional modules:
dnf install -y epel-release
dnf config-manager --set-enabled PowerTools
dnf -y install ImageMagick ImageMagick-devel
dnf -y install php-intl

Rocky/RHEL 9 etc

  • Appstream

Debian

# apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list
curl -fsSL  https://packages.sury.org/php/apt.gpg| gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-keyring.gpg
(if you have a local copy of the apt.gpg key, use cat apt.gpg | gpg... etc)
apt update
apt install php8.1

Ubuntu

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Set version of PHP to use

# update-alternatives --set php /usr/bin/php8.1

Amazon Linux

amazon-linux-extras (should be preinstalled on AWS Linux, if not install it with yum)

Command typed on its own shows additional available software

Enable additional software e.g. amazon-linux-extras enable memcached2

e.g. disable php7.2 and enable php7.3

amazon-linux-extras disable php7.2
amazon-linux-extras enable php7.3

This enables the ‘stream’ for php7.3, then you can install the packages:

sudo yum clean metadata
sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap}


Check version of php using php -v 
php_admin_value[post_max_size] = 100M
php_admin_value[upload_max_filesize] = 100M

phpMyAdmin

  • (Optional) Graphical utility can be used to modify MariaDB using web page frontend
  • May need to have EPEL repos installed - see above
  • yum install phpmyadmin
    • Configuration file: /etc/httpd/conf.d/phpMyAdmin.conf
    • Notice sections under <RequireAny> where it lists source IPs. These are IPs that you can access phpMyAdmin from - any other source IP is rejected
    • If want to permit access from any source IP (e.g. using some other way to restrict access) add this line Require all granted in this section
    • Restart httpd after making modifications to this file
  • Login to phpMyAdmin: http://server/phpmyadmin

pecl

  • x

xdebug

uploadprogress

Configuring PHP-FPM / FastCGI

Links

composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

Drush

Run PHP at command line

Links

Check PHP file for syntax errors (linter)

  • php -l <filename>.php

Notes

  • PHP upload limit can also be defined in a .user.ini file (e.g. this might be in the public_html directory)
  • When I display phpinfo(); I see two columns: local value and master value. When will the web server choose local value and when will it choose master value?
    • The hosted website will check local values in .htaccess or .user.ini first. (These files are in your local website folder and also can say local level configuration files.) Local values override Master values, so php will check the local values first.