Gilberto Albino Gilberto Albino - 1 month ago 20
Apache Configuration Question

How to configure Apache for Multiple PHP version from htaccess

I have installed a collection of PHP versions from Remi Repositories, which may be ignored, for the question itself, but kept for the sake of understanding the processed I tried.

They work fine from command line, but I'd like to use them with Apache 2 (httpd on Fedora 24), running multiple virtual hosts as in:

php54.test
php55.test
php56.test
php70.test
php71.test


I have created the VirtualHost conf files and each one is working fine.

I want to run each corresponding php version (accordingly to the suggestive ServerName), but I can't find how to load PHP from each Virtual Host.
I couldn't find the corresponding Remi libphpX.so for loading them as modules:

<VirtualHost *:80>
ServerName php54.test
DocumentRoot /var/www/php54

#SOMETHING LIKE THIS...
LoadModule php??_module modules/libphp??.so

</VirtualHost>


I have, and this is not news, a shared hosting that allows me to change PHP version from .htaccess and I can do something like this:

AddHandler application/x-httpd-php54 .php
AddHandler application/x-httpd-php55 .php
AddHandler application/x-httpd-php56 .php
AddHandler application/x-httpd-php7 .php
AddHandler application/x-httpd-php71 .php


I may look like a dummy now, but how can I do the same .htaccess switching for having multiple PHP versions available?

I probably am not knowing what and how to search on Google to find the best matched answer.

Answer

You cannot use multiple versions of mod_php.

Better solution is to use php-fpm (the Fastcgi Process Manager), using in each vhost a SetHandler to fcgi server:

    SetHandler "proxy:fcgi://127.0.0.1:9070"

Or (using unix domain socket)

    SetHandler "proxy:unix:/var/opt/remi/php70/run/php-fpm/www.sock|fcgi://localhost"

This is described in this article : My PHP workstation.

Comments