0

On my apache server I'd like to run multiple versions of PHP concurrently so that I can easily switch between them depending on the needs of the project. I noticed that some shared hosting providers who offer multiple versions of PHP require you to define the version of PHP you need in your .htaccess:

AddHandler application/x-httpd-php5 .php

I'd like to implement something like this on my server so that I can easily switch PHP versions:

AddHandler application/xhttpd-php53 .php
 # .. or ..
AddHandler application/xhttpd-php54 .php
 # .. or ..
AddHandler application/xhttpd-php55 .php

However all of the versions of PHP that I've compiled have a handler named application/xhttpd-php or php5-script. I've tried to search for a ./configure flag that allows you to change these handler names, but nothing turned up.

I searched the PHP github repo for these two strings and this is what I found:

Would it be safe to replace these strings with the new handler name and version number, or is there a wider used (ora actually documented) way to change the handler name?

1 Answer 1

1

You could use one of the php version as a module and another versions as cgi. If you would need to use specific php version in some specific project (vhost) you can use something like

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /vhosts/php55.example.net/
    ServerName php55.example.net

    ScriptAlias /php-fastcgi/ /usr/local/php-5.5.1/bin/

    AddHandler php-fastcgi .php
    AddType application/x-httpd-php .php
    Action php-fastcgi /php-fastcgi/php-cgi

    <Directory /vhosts/php55.example.net>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /vhosts/php54.example.net/
    ServerName php54.example.net

    ScriptAlias /php-fastcgi/ /usr/local/php-5.4.17/bin/

    AddHandler php-fastcgi .php
    AddType application/x-httpd-php .php
    Action php-fastcgi /php-fastcgi/php-cgi

    <Directory /vhosts/php54.example.net>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
1
  • Solid advice. It's what I ended up using in the end. I tried my hack-y workaround from the question and Apache segfaulted after I added more than one PHP module. Seems that FPM is the way to go! Thanks! Aug 6, 2013 at 14:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .