linux_server_manuals:apache_http_2_php-fpm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
linux_server_manuals:apache_http_2_php-fpm [2018/01/13 07:33] – ronney | linux_server_manuals:apache_http_2_php-fpm [2021/08/18 14:46] (current) – ronney | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | apache + php-fpm | + | ====== Apache Web Server with mpm_event, mod_proxy_fcgi, |
- | php 7 nicht thread safe. | + | When installing a web server, there are certain chances that you will use webapplications which depend on PHP. Unfortunately |
- | d.h. für mod_php muss man mpm_prefork | + | |
- | deshalb um mpm_event zu verwenden, umstellefn auf php-fpm + mod_proxy_fcgi | + | |
- | aptitude install | + | ===== Enable |
- | a2enmod proxy_fcgi | + | So let's go: |
- | if enabled: | + | If previously default mod-php was installed, remove it: |
- | a2dismod php7.0 | + | < |
- | aptitude purge libapache2-mod-php | + | aptitude purge libapache2-mod-php |
+ | </ | ||
+ | |||
+ | Then install php-fpm, | ||
+ | |||
+ | < | ||
+ | aptitude install php-fpm | ||
+ | a2enmod proxy_fcgi | ||
+ | a2enconf php7.0-fpm | ||
a2dismod mpm_prefork | a2dismod mpm_prefork | ||
a2enmod mpm_event | a2enmod mpm_event | ||
- | create file | + | </code> |
- | /etc/ | + | |
- | < | + | Then restart apache |
- | < | + | |
- | <If "-f %{REQUEST_FILENAME}"> | + | |
- | SetHandler " | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | restart | + | < |
+ | systemctl | ||
+ | </ | ||
- | see https:// | + | For further information, |
- | especially about ulimit and future issues if too many connection are opened. | + | |
- | and especially | + | |
+ | ==== Increase pm.max_children ==== | ||
- | /etc/apache2/mods-enalbed/ | + | PHP-fpm has a maximal amount of children processes which it uses to serve requests. The default setting of 5 most propably is too low for almost any kind of server. Check for similar messages in your log /var/log/php7.3-fpm.log< |
+ | [05-Mar-2019 13:01:21] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, | ||
+ | [05-Mar-2019 13:01:22] WARNING: [pool www] server reached pm.max_children setting (50), consider raising it | ||
+ | |||
+ | </ | ||
+ | |||
+ | To change it edit / | ||
+ | |||
+ | < | ||
+ | pm.max_children = 20 | ||
+ | pm.start_servers = 5 | ||
+ | pm.min_spare_servers = 1 | ||
+ | pm.max_spare_servers = 5 | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Increase PHP Execution Timeout ==== | ||
+ | |||
+ | If you use php scripts which run for a long time (>30s) then you need to change several settings, otherwise the script will timeout and the connection aborted. | ||
+ | |||
+ | To increase the php max execution time, change following line in the file / | ||
+ | |||
+ | < | ||
+ | #Max time you want a script to be able to be running | ||
+ | max_execution_time = 300 | ||
+ | |||
+ | </ | ||
+ | |||
+ | That alone won't work, you will still get following error (or similar) if the script runs longer than 30 seconds: | ||
+ | |||
+ | < | ||
+ | [proxy_fcgi: | ||
+ | |||
+ | </ | ||
+ | |||
+ | To avoid that, edit the file / | ||
+ | |||
+ | < | ||
+ | # Timeout for proxy_fcgi module | ||
+ | # This line needs to be added | ||
+ | ProxyTimeout 300 | ||
+ | |||
+ | # That line already exists and is the general apache timeout. | ||
+ | # If you want to increase the timeout over 300, you also need to change that line | ||
+ | Timeout 300 | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Enable HTTP/2 support ===== | ||
+ | |||
+ | Enable HTTP/2 modules: | ||
+ | |||
+ | < | ||
+ | a2enmod http2 | ||
+ | |||
+ | </ | ||
+ | |||
+ | Create file / | ||
+ | |||
+ | < | ||
< | < | ||
+ | #The preference order of protocols. | ||
+ | # h2c is http/2 without encryption. | ||
Protocols h2 h2c http/1.1 | Protocols h2 h2c http/1.1 | ||
+ | #maybe can make initiazion of http/2 connection faster. Not a necessary parameter | ||
H2Direct on | H2Direct on | ||
</ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Activate .htaccess files ===== | ||
+ | |||
+ | The default setup of the apache package will not use the .htaccess files (they are not very efficient). Most probably your php applications will use them, so to activate them, edit / | ||
+ | |||
+ | < | ||
+ | < | ||
+ | Options Indexes FollowSymLinks | ||
+ | AllowOverride All | ||
+ | Require all granted | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
linux_server_manuals/apache_http_2_php-fpm.1515828830.txt.gz · Last modified: 2018/01/13 07:33 by ronney