I'm setting up a test server on Rocky Linux 9.3 with Apache 2.4.57 and PHP 8.3 from Remi's repository installed in multiple versions mode and having some trouble with configuring a php files handler in Apache.
When I install php83-php package and some of it's additional modules it places it's configuration into /etc/httpd/conf.modules.d/20-php83-php.conf
like this:
<IfModule !mod_php5.c>
<IfModule !mod_php7.c>
<IfModule prefork.c>
LoadModule php_module modules/libphp83.so
</IfModule>
</IfModule>
</IfModule>
This can be verified by starting httpd service and doing a command httpd -M | grep php
which gives the following output:
php_module (shared)
It also defines a handler for php files in /etc/httpd/conf.d/php83-php.conf
:
<IfModule mod_php.c>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
<FilesMatch \.(php|phar)$>
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
This doesn't work though and php scripts don't execute in browser. After some googling I found out a changelog for PHP (https://php.watch/versions/8.0/mod_php-rename) mentioning that starting from version 8.0 the module identifier for Apache handler was changed to php_module
, which is logical given the name of the module that php package automatically places into Apache config.
But if I change the conditional statement defining a handler into <IfModule php_module>
like it is mentioned in php changelog this doesn't work as well and php code doesn't get executed in the browser.
Apache documentation on using <IfModule>
directive (https://httpd.apache.org/docs/2.4/mod/core.html#ifmodule) mentions that either an identifier or a filename can be used but putting libphp83.so there also doesn't have any effect.
And if I completely remove the conditional statement <IfModule ... > ... </IfModule>
around a handler everything works just fine and code gets correctly executed like it's supposed to. However? as far as I understand, this is (supposedly) not secure as it can lead to code leakage if a php module would actually fail to load for some reason.
So, my question is, how do I define an Apache php file handler for PHP 8.3 within <IfModule>
directive for it to work correctly?
As for why I'm not using php-fpm, well that's a good question, which I don't really have a clear answer for. What I'm trying to do here is prepare to migrate a very old and heavily customized Bitrix CRM from CentOS 7 (which is nearing it's and of life) and PHP 7.4 to modern distribution and modern PHP version while following a manual written by a person who left quite some time ago along with most of the IT staff which led to me being transferred from a paperwork position into IT not so long ago and I still have only vague idea what I'm doing, so any help would be much appreciated.
Using mod_php imply you use httpd in prefork mode, which is a terrible idea for security and performance.
Also notice than mod_php only allows a single version.
Starting with EL-8, httpd use event mode, and php-fpm is used by default, mod_php still available.
Starting with EL-9, httpd use event mode, and php-fpm always used
I heartily recommend to use php-fpm
So, the proper handler is (which the proper path)
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
And to run multiple versions, I recommend you read My PHP development Workstation
P.S. The default provided configuration is designed to work out of the box. No changes are needed. Changes are only required when multiple versions are installed simultenaously.