J.3. Approaches to running multiple PHP versions

There are two fundamental ways of running multiple versions of PHP on the same server.

  1. Running multiple instances of the HTTPD demon where each instance listens on separate addresses and/or ports.

    Advantage: This is the only way to run multiple versions of PHP as (SAPI) modules in Apache2. In addition this has some better security since potential crashes will be isolated and not effect the other HTTPD demons.

    Drawback: Running multiple HTTPD instances will need more system resources in terms of memory and file handlers.

  2. Running one instance of the HTTPD demon which is configured to serve multiple virtual hosts. This is the approach we have chosen.

    Advantage: Minimum system overhead and relatively easy to setup.

    Drawback: Only one PHP version can be run as a (SAPI) Apache module the other PHP versions must be configured/installed as CGI modules. This has a slight performance impact and might not be suitable for heavily loaded production sites. (Note: that could be overcome with the use of fast-cgi which works by pre-loading an instance of PHP in memory which will then be used by the Apache process. See Apache2 documentation regarding fast-cgi for more details).


    There are actually two versions of virtual hosts with apache. By name pr by IP-address. In this example we have chosen to match the virtual hosts by IP address since for a development server we want to be able to use plain IP addresses and not have the added complexity of setting up a full DNS server. For more details about other differences please see the excellent Apache2 documentation.