Apache with php-fpm: Difference between revisions
m (→See Also: Changed a link to https) |
mNo edit summary |
||
Line 9: | Line 9: | ||
Install required packages | Install required packages | ||
{{Cmd|# apk add apache2-proxy | {{Cmd|# apk add apache2-proxy php-fpm}} | ||
Run and add services to startup | Run and add services to startup | ||
{{Cmd|# rc-service php- | {{Cmd|# rc-service php-fpm83 start | ||
# rc-update add php- | # rc-update add php-fpm83 | ||
# rc-service apache2 start | # rc-service apache2 start | ||
# rc-update add apache2}} | # rc-update add apache2}} |
Latest revision as of 14:05, 26 February 2025
![]() It should be merged with Apache. Everything in one place seems logical (Discuss) |
PHP-FPM is the Fast Process Manager for PHP which runs as a service that spawns PHP processes as needed when files files are requested through the FastCGI interface. Passing this off to the PHP-FPM results in interpreting the PHP files much faster than having Apache spawn new processes each time a page is requested. You can read more about it here.
Instructions
Installation
Install required packages
# apk add apache2-proxy php-fpm
Run and add services to startup
# rc-service php-fpm83 start # rc-update add php-fpm83 # rc-service apache2 start # rc-update add apache2
Configure
Configure Apache
Uncomment the mpm_event module and comment the mpm_prefork module like so:
LoadModule mpm_event_module modules/mod_mpm_event.so #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
Add the following lines to /etc/apache2/httpd.conf:
<FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9000" </FilesMatch>
Comment out the following lines in /etc/apache2/conf.d/php8-module.conf:
#LoadModule php_module modules/mod_php8.so #DirectoryIndex index.php index.html #<FilesMatch \.php$> # SetHandler application/x-httpd-php #</FilesMatch>
Configure PHP-FPM
Edit the file /etc/php8/php-fpm.conf to suit your needs.
In the configuration you may need to change the default user and group from nobody to another user such as apache
:
user = apache group = apache
Restart apache2 and PHP-FPM after editing the configuration:
# rc-service php-fpm8 reload && rc-service apache2 reload