Inside /etc/httpd/conf.modules.d/ I have a conf file called 10-php54-php.conf which I use to specify what PHP version I want to use. I can freely switch between PHP 7.2 and PHP 5.4 by commenting line 2 and uncommenting line 3.

Is there a way to specify that I want to use PHP 5.4 in a specific directory and leave the rest of Apache using 7.2? I saw a few guides on our beloved Google telling me to use php-fpm but I'd like to use these .so files if possible.


<IfModule prefork.c>
     LoadModule php7_module modules/libphp7.so
     #LoadModule php5_module modules/libphp54-php5.so

I already tried some variations inside httpd.conf but apache won't start:

<Directory "var/www/html/directory">
        LoadModule php5_module modules/libphp54-php5.so # tried with LoadModule and Include

Apache 2.4.6, CentOS 7.4.

EDIT: When putting LoadModule inside my virtualhost, it fails to restart when running apachectl graceful.


<VirtualHost *:80>
        DocumentRoot /var/www/html/
        ServerName www.domain1.com

<VirtualHost *:80>
        ServerName domain2.com
        ServerAlias *.domain2.com
        ServerAdmin admin@domain2.com
        DocumentRoot /var/www/html/domain2
        ErrorLog /var/log/httpd/domain2.com-error.log
        CustomLog /var/log/httpd/domain2.com-access.log combined
        php_admin_value default_charset UTF-8


<VirtualHost *:80>
        ServerName service.domain1.com
        ServerAdmin admin@domain2.com
        DocumentRoot /var/www/html/service
        ErrorLog /var/log/httpd/service.domain1.com-error.log
        CustomLog /var/log/httpd/service.domain1.com-access.log combined
       #LoadModule php5_module modules/libphp54-php5.so

journalctl -xe:

Mai 22 11:33:08 host.host polkitd[700]: Registered Authentication Agent for unix-process:14527:379023715 (system bus name :1.15226 [/usr/bin/pkttyagent --notif
Mai 22 11:33:09 host.host httpd[14533]: [Wed May 22 11:33:09.001953 2019] [so:warn] [pid 14533] AH01574: module php5_module is already loaded, skipping
Mai 22 11:33:09 host.host kernel: httpd[14533]: segfault at 0 ip 00007f46635326b7 sp 00007fff2214f1d8 error 4 in libphp7.so[7f4663284000+45a000]
Mai 22 11:33:09 host.host systemd[1]: httpd.service: control process exited, code=killed status=11
Mai 22 11:33:09 host.host systemd[1]: Reload failed for The Apache HTTP Server.

You can't load two different PHP modules at the same time. Full stop. This is why you must use php-fpm to run different PHP versions.

  • I installed php-fpm by running yum install php54-php-fpm, started it by running service php54-php-fpm start and added ProxyPassMatch ^/service(.*\.php(/.*)?)$ fcgi://$1 to my virtualhost. Apachectl graceful didn't return any errors but phpinfo() still shows PHP 7.2. Any idea what I'm missing? – Mateus Scheper May 22 at 19:27
  • @MateusScheper BOTH PHP versions must be installed using php-fpm and you have to remove mod_php. – Michael Hampton May 22 at 21:35
  • Ah, I see. I won't be able to test it again this week, but I'll look into it. Thank you very much for your help. – Mateus Scheper May 23 at 11:24

You can only use LoadModule in the context of a server config (httpd.conf) or virtual host. It does not work in a directory context.

  • I tried using it inside my virtualhost, but when I run apachectl graceful, it fails. I added some info to the post. – Mateus Scheper May 22 at 14:55
  • There seems to be a conflict with the php7 module. Does it work if you comment the line in /etc/httpd/conf.modules.d/10-php54-php.conf? – Freddy May 22 at 15:18
  • It's a production server and I won't be able to change PHP version on the entire Apache, so I'll look into it when I get the chance. Thank you very much for your help. – Mateus Scheper May 23 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.