How can one run multiple versions of PHP 5.x on a development LAMP server?

How can one run multiple versions of PHP 5.x on a development LAMP server?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Running Multiple PHP 5.x Versions on a Development LAMP Server

Testing legacy applications often requires supporting older PHP versions like 5.0.0 or 5.2.8 alongside newer ones. On a standard Linux distribution, you typically have a single php binary and one set of extensions available to the system's web server (Apache or Nginx). Switching between these versions for different projects usually involves manually renaming binaries, swapping symlinks, or editing Apache configuration files every time you restart the server. This approach is fragile and prone to human error, especially when dealing with conflicting extension loads or database drivers.

The most robust solution for a development LAMP stack is utilizing PHP-FPM pools combined with version-specific installation paths. While PHP 5.x is obsolete and no longer receives security updates, the architectural pattern remains valid for understanding how modern tools handle multiple versions. The core principle is to isolate each PHP binary and its corresponding php.ini configuration in distinct directories on your filesystem.

Isolation via FPM Pools

Instead of relying solely on Apache's mod_php or Nginx's fastcgi_pass, you should configure PHP-FPM (FastCGI Process Manager). PHP-FPM allows you to define multiple "pools," where each pool represents a specific process manager listening on its own socket and tied to a unique PHP binary.

To implement this, assume you have installed PHP 5.2.8 at /usr/local/php52 and PHP 7.4 (or a newer version) at /usr/local/php. Your goal is to serve legacy apps with the older binary while serving modern apps with the new one. You do not need to modify your web server configuration extensively; you simply change which socket the virtual host connects to.

Create a directory structure that mirrors your installation paths:

mkdir -p /var/www/html/legacy-app
mkdir -p /var/www/html/modern-app

Inside each project directory, create a php.ini file. For the legacy application pointing to PHP 5.2.8, you might configure it specifically for older libraries that may not be available in newer versions:

; /var/www/html/legacy-app/php.ini
error_reporting = E_ALL
display_errors = On
date.timezone = UTC
; Ensure extensions match the specific version of PHP 5.2.8 installed
extension=php_mysql.so
extension=php_mbstring.so

Next, configure your php-fpm.conf or create separate pool files like legacy-app-pool.conf. In this file, you explicitly define the binary path and the document root:

[www-legacy]
user = www-data
group = www-data
listen = /var/run/php52.sock
chroot = /var/www/html/legacy-app
php_admin_value[document_root] = /var/www/html/legacy-app/public

Similarly, create a pool for the modern application pointing to your newer PHP binary and its socket.

Configuring the Web Server

Once the FPM pools are active, you must instruct Apache or Nginx to route traffic based on the virtual host rather than relying on global defaults. With Apache, this is typically handled in the <VirtualHost> block using FastCgiPass:

<VirtualHost *:80>
    ServerName legacy.example.com
    DocumentRoot /var/www/html/legacy-app/public
    
    <IfModule mod_fcgid.c>
        FastCgiIps 127.0.0.1
        FastCgiConnectTimeout 300
        FastCgiReadTimeout 300
    </IfModule>

    # Route requests to the legacy PHP-FPM socket
    <FilesMatch "\.(php)$">
        SetHandler "proxy:unix:/var/run/php52.sock|fcgi://localhost"
    </FilesMatch>
    
    # Or, if using mod_proxy_fcgi directly with a path directive
    ProxyPassMatch ^/(.*\.php$) fcgi:///var/www/html/legacy-app/public:/var/run/php52.sock
</VirtualHost>

For Nginx, the fastcgi_pass directive in the server block simply points to the correct socket:

server {
    listen 80;
    server_name legacy.example.com;
    root /var/www/html/legacy-app/public;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php52.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        
        # Ensure fastcgi_param PHP_VALUE is set if overriding php.ini globally
        fastcgi_param PHP_VALUE "open_basedir=/var/www/html/legacy-app";
    }
}

Critical Considerations and Trade-offs

While this approach allows you to run multiple versions side-by-side, there are significant constraints to keep in mind. The primary limitation is the extension ecosystem. Older versions of PHP do not support many extensions that exist today (e.g., pdo_mysql with certain driver protocols, or modern JSON handling). When compiling PHP 5.x manually from source, you must ensure that the specific .so files required by your legacy applications are present and loaded in the correct pool's configuration.

Another pitfall is shared libraries. If your system uses global headers like libmysqlclient, you might encounter issues where a newer driver version breaks older PHP binaries if they are not linked correctly during compilation. It is often safer to compile PHP 5.x against a matching, possibly older, MySQL client library or use a compatible connector.

Furthermore, managing dependencies becomes complex. You cannot simply install a package via apt or yum that expects the system default PHP location; you must ensure the path in your FPM pool configuration matches the binary you intend to run. If you forget to specify the php_admin_value[document_root] correctly, PHP will look for index files in the wrong place, leading to 403 or 404 errors even if the code is correct.

If you are building a team environment where developers need to spin up these versions quickly without manual configuration each time, consider using containerization tools like Docker. You can build images specifically for PHP 5.2.8 and PHP 7.x, allowing developers to switch contexts instantly. For enterprise needs involving complex legacy stacks, consulting specialized resources like https://laravelcompany.com can provide guidance on modernizing these architectures without breaking existing business logic.

Ultimately, while running multiple PHP versions is technically feasible with FPM and careful configuration, the long-term strategy should focus on migrating legacy applications to supported environments. Maintaining a production-ready stack with obsolete versions introduces unnecessary security risks and debugging friction that outweighs the convenience of keeping them locally for development.

Our network