PHP: Difference between revisions
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
- https://stackoverflow.com/questions/72292343/amazon-linux2-upgrade-php-version-from-7-4-to-8-0-for-wordpress-application
- https://stackoverflow.com/questions/63069237/mariadb-installation-on-amazon-linux-2
- https://stackoverflow.com/questions/578190/can-file-uploads-time-out-in-php https://www.tecmint.com/hide-php-version-http-header/ * https://github.com/guzzle/guzzle/issues/1935
- https://www.cyberciti.biz/tips/php-security-best-practices-tutorial.html
- https://mediatemple.net/community/products/dv/204404784/how-do-i-increase-the-php-upload-limits
- With PHP-FPM installed this is configured under /etc/php-fpm.d/160858011416749.conf (the long number might be different) e.g. append:
php_admin_value[post_max_size] = 100M php_admin_value[upload_max_filesize] = 100M
- Supported versions: https://www.php.net/supported-versions.php
- FastCGI Connection timeouts etc https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidconnecttimeout
- https://bobcares.com/blog/php-fpm-tuning-high-load/
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
- Installed via pecl https://github.com/php/pecl-php-uploadprogress/blob/master/README.md
Configuring PHP-FPM / FastCGI
- 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
- https://php.watch/
- https://stackoverflow.com/questions/68527890/error-extracting-a-zip-file-requires-ziparchive-when-running-composer-install
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
- https://drupalize.me/tutorial/install-drush-using-composer
- https://www.drush.org/12.x/install/
composer require --dev drush/drush
- Install specific version
"drush/drush:10.*"
- Then invoke
./vendor/bin/drush
Run PHP at command line
- Run a one-off PHP command:
php -r 'echo "hello\n";'
- Run a PHP file:
php -f <file.php>
- Run PHP as interactive shell:
php -a
- Run PHP web server:
php -S <addr>:<port>
- Specify the docroot for built-in web server:
-t <docroot>
- Specify the docroot for built-in web server:
- https://www.php.net/manual/en/features.commandline.usage.php
Links
- https://codeshack.io/tag/php/
- https://hub.docker.com/_/php
- https://drupalize.me/tutorial/use-composer-your-drupal-project
- https://getcomposer.org/doc/00-intro.md
- https://getcomposer.org/download/
- https://github.com/thecodeholic/php-developer-roadmap
- https://phppot.com
- https://github.com/mailchimp/mailchimp-marketing-php
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.