This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
linux:webserver:php [2016/09/24 22:09] tkilla created |
linux:webserver:php [2023/03/25 10:58] (current) tkilla [Install PHP 7.4 in Debian Buster / SURY REPO] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP ====== | ====== PHP ====== | ||
+ | |||
+ | |||
+ | |||
+ | ===== PHP-FPM Setup ===== | ||
+ | |||
+ | Configure pools for each domain/ | ||
+ | |||
+ | **Pool per domain config:** | ||
+ | |||
+ | cd / | ||
+ | cp www.conf {user1.conf, | ||
+ | |||
+ | replace all appearances of " | ||
+ | / | ||
+ | |||
+ | **Add a user for each pool:** | ||
+ | |||
+ | The username must be an exisiting user in the system. e.g.: | ||
+ | adduser --disabled-login USERNAME | ||
+ | adduser www-data USERNAME | ||
+ | mkdir / | ||
+ | chown -R USERNAME: | ||
+ | chmod 750 / | ||
+ | |||
+ | |||
+ | ===== nginx & PHP-FPM ===== | ||
+ | |||
+ | PHP-FPM can run over a http connection or a unix socket. unix socket is faster. | ||
+ | |||
+ | **vhost php config via unix socket: | ||
+ | |||
+ | server { | ||
+ | ... | ||
+ | | ||
+ | location ~ \.php$ { | ||
+ | fastcgi_split_path_info ^(.+\.php)(/ | ||
+ | include fastcgi_params; | ||
+ | fastcgi_intercept_errors on; | ||
+ | fastcgi_index index.php; | ||
+ | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
+ | | ||
+ | # replace USERNAME by system/ | ||
+ | fastcgi_pass unix:/ | ||
+ | } | ||
+ | |||
+ | |||
+ | ===== PHP Modules ===== | ||
+ | |||
+ | Wordpress required: | ||
+ | |||
+ | apt install php-iconv php-exif php-memcached php-soap | ||
+ | |||
+ | ===== Apache & PHP-FPM ===== | ||
+ | |||
+ | Use php-fpm for better performance and better security: run each domain in its own " | ||
+ | |||
+ | apt-get install apache2 libapache2-mod-fastcgi php5-fpm | ||
+ | a2enmod actions | ||
+ | | ||
+ | cp / | ||
+ | | ||
+ | mcedit / | ||
+ | | ||
+ | < | ||
+ | AddType application/ | ||
+ | Action application/ | ||
+ | Alias /php5-fcgi / | ||
+ | FastCgiExternalServer / | ||
+ | < | ||
+ | Require all granted | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | apache2ctl configtest | ||
+ | / | ||
+ | |||
+ | check if a phpfpm " | ||
+ | |||
+ | |||
+ | |||
+ | You need to edit your vhosts to use the new pool. | ||
+ | Replace USERNAME by the poolname you just created and VHOSTNAME by a dfifferent name in each vhost: | ||
+ | |||
+ | |||
+ | < | ||
+ | ... | ||
+ | < | ||
+ | Alias /php5-fcgi / | ||
+ | FastCgiExternalServer / | ||
+ | </ | ||
+ | ... | ||
+ | |||
+ | Links: | ||
+ | * https:// | ||
+ | * http:// | ||
+ | |||
+ | |||
+ | ===== Performance ===== | ||
+ | |||
+ | For PHP-FPM the same optimization as for default php modules apply. | ||
+ | |||
+ | ==== Configure pool ==== | ||
+ | |||
+ | These settings with initial pm.start_servers = 5 is quite good for a server with 32gb RAM and up to 20-30 sites. This starts 5 processes, which take up to php_admin_value[memory_limit] = 512M each, but usually around 100mb per process when running a small wordpress. So this pool always uses 5*100mb = 500mb and may required much more, if the site is busy and more servers are started. | ||
+ | |||
+ | On small servers, use pm = ondemand, which starts servers only when used. This is slower than pm = dynamic | ||
+ | |||
+ | pm = dynamic | ||
+ | pm.max_children = 50 | ||
+ | pm.start_servers = 5 | ||
+ | pm.min_spare_servers = 2 | ||
+ | pm.max_spare_servers = 5 | ||
+ | |||
+ | |||
+ | High performance server with one busy site: | ||
+ | pm = dynamic | ||
+ | pm.max_children = 50 | ||
+ | pm.start_servers = 25 | ||
+ | pm.min_spare_servers = 20 | ||
+ | pm.max_spare_servers = 25 | ||
+ | |||
+ | Test how much RAM your site needs. This is the max, not the regular used memory. Most sites run with ~100mb, but require more for special tasks. | ||
+ | php_admin_value[memory_limit] = 512M | ||
+ | |||
+ | |||
+ | ==== PHP-FPM Status Page in Console ==== | ||
+ | |||
+ | apt-get install libfcgi0ldbl | ||
+ | | ||
+ | SCRIPT_NAME=/ | ||
+ | |||
+ | |||
+ | * https:// | ||
+ | |||
+ | |||
+ | ==== php.ini settings ==== | ||
+ | |||
+ | * zlib.output_compression = On # + test compression setting from 1-9 | ||
+ | * short_tags = Off | ||
+ | * ... | ||
+ | |||
+ | |||
+ | ==== Opcache ==== | ||
+ | |||
+ | APC is deprecated and incompatible with latest php verions. Just use opache. Install, enable module and configure: | ||
+ | |||
+ | / | ||
+ | |||
+ | zend_extension=opcache.so | ||
+ | | ||
+ | opcache.enable=1 | ||
+ | | ||
+ | ; moooore cache: | ||
+ | opcache.memory_consumption=1024 | ||
+ | opcache.max_accelerated_files=50000 | ||
+ | | ||
+ | ; php script changes will appear after one minute, but this is faster than the default: | ||
+ | opcache.revalidate_freq=60 | ||
+ | | ||
+ | opcache.interned_strings_buffer=16 | ||
+ | |||
+ | ; required for nextcloud / paypal sdk / ..: | ||
+ | opcache.save_comments=1 | ||
+ | opcache.load_comments=1 | ||
+ | | ||
+ | opcache.validate_timestamps=1 | ||
+ | opcache.consistency_checks=0 | ||
+ | opcache.error_log=/ | ||
+ | opcache.log_verbosity_level=1 | ||
+ | |||
+ | |||
+ | |||
+ | ===== HHVM ===== | ||
+ | |||
+ | rocks! | ||
+ | |||
+ | in nginx vhost config, just disable the fpm block and include the included config in the vhost: | ||
+ | |||
+ | include hhvm.conf; | ||
+ | |||
+ | |||
+ | ===== PHP5-FPM and PHP7.0 parallel Setup ===== | ||
+ | |||
+ | On debian jessie this works very well. Just install all php7.0 packages from backports. | ||
+ | |||
+ | ==== Install packages: ==== | ||
+ | |||
+ | | ||
+ | |||
+ | ==== Check which version is the default now and adjust: ==== | ||
+ | |||
+ | php -v | ||
+ | update-alternatives --co==== Headline ==== | ||
+ | nfig php | ||
+ | |||
+ | ==== Nginx Config - just replace the socket: ==== | ||
+ | |||
+ | fastcgi_pass unix:/ | ||
+ | |||
+ | fastcgi.conf, | ||
+ | |||
+ | ==== PHP7.0-FPM Config: ==== | ||
+ | |||
+ | edit or copy configs from php5: | ||
+ | * / | ||
+ | * / | ||
+ | * all configs in / | ||
+ | |||
+ | Pools: | ||
+ | Move a site-pool from php5 or create a new one in: / | ||
+ | |||
+ | You only need to adjust the socket line, to point to / | ||
+ | |||
+ | Check, if all required php modules are installed and configured.. good luck :) | ||
+ | |||
+ | ===== Install PHP 7.4 in Debian Buster / SURY REPO ===== | ||
+ | |||
+ | php7.4-fpm needs systemd :( | ||
+ | |||
+ | Add Sury Repo: | ||
+ | apt -y install lsb-release apt-transport-https ca-certificates | ||
+ | wget -O / | ||
+ | echo "deb https:// | ||
+ | apt update | ||
+ | apt install php7.4 | ||
+ | |||
+ | Install Modules: | ||
+ | apt-get install php7.4-{fpm, | ||
+ | |||
+ | / | ||
+ | |||