Is there way to use two PHP versions in XAMPP?

Is there way to use two PHP versions in XAMPP?

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

Stefan Bogdanescu

Founder & Senior Architect

Is there way to use two PHP versions in XAMPP?

You are currently running XAMPP with PHP 7.0 because your new products require it, but you have old projects relying on functions like mysql_connect that were removed in PHP 7. The short answer is yes, you can run multiple PHP versions side-by-side on a single XAMPP installation without needing to upgrade those legacy projects immediately. This approach solves the immediate constraint where you cannot decide to update the code due to organizational decisions beyond your control.

XAMPP is not a monolithic block of software; it relies heavily on portability and modular components. The core Apache server does not care which version of PHP runs, provided the paths are configured correctly. The separation between PHP versions is handled entirely by the php.ini configuration file and the location of the binaries themselves.

To achieve this, you must treat each PHP version as an independent environment within your XAMPP directory structure. When you install a new version of PHP (for example, downloading php-7.4 or php-8.0 from the official archives), do not replace the existing files in the xampp\php folder. Instead, create a dedicated subdirectory, such as xampp\php_7_4.

The critical step is configuring Apache to load the correct binary and configuration file for each virtual host. In XAMPP, this is managed via the .htaccess file or the main httpd.conf using the LoadModule directive. However, a simpler method that avoids complex module reloading is to use PHP's built-in ability to switch SAPI (Server API) contexts if you are running multiple versions on different ports.

A more practical approach for XAMPP specifically involves modifying the Extra tab in the Apache configuration or creating separate httpd-vhosts.conf entries. You would need to ensure that each project points to a specific PHP executable. For instance, your new product might point to C:\xampp\php\php.exe, while your legacy project points to C:\xampp\php_7_4\php.exe.

You must also manage the database connection strings carefully. The mysql_* functions are deprecated and removed in PHP 5.5 and later, replaced by mysqli_*. Your old projects likely link against an older MySQL client library bundled with XAMPP. If you run a newer PHP version that expects different extensions, you might encounter missing function errors if the extensions aren't loaded. Conversely, running an older PHP binary (like 5.6) alongside PHP 7 requires ensuring that the php.ini file for that specific version explicitly disables the new MySQLi drivers or loads the old mysql.dll if it still exists in that bundled package.

One common pitfall is mixing configuration files. Ensure that your legacy project's .htaccess file does not accidentally override the PHP settings intended for the newer version. If you use a single .htaccess to switch versions, you must explicitly define which php.ini file belongs to which virtual host.

<VirtualHost *:8080>
    ServerName legacy.local
    # Point this to the older PHP binary and config if XAMPP supports it
    DocumentRoot "C:/xampp/htdocs/legacy"
    PHPIniDir "C:/xampp/php_5_6" 
</VirtualHost>

<VirtualHost *:8090>
    ServerName newproduct.local
    DocumentRoot "C:/xampp/htdocs/newproduct"
    PHPIniDir "C:/xampp/php"
</VirtualHost>

Note: The exact syntax for PHPIniDir or binary pathing depends on the specific version of Apache and XAMPP you are using. Some configurations require adding a custom .ini file to the Extra folder in XAMPP.

Another consideration is the database driver compatibility. If your legacy project uses raw MySQL functions, it may strictly depend on the MySQL client library included with that specific PHP build. Switching the PHP binary without matching the underlying MySQL extension can lead to runtime errors where functions simply do not exist.

While running multiple versions is technically feasible, it adds operational complexity. You will need to maintain separate update cycles for each version and ensure security patches are applied to both. If your organization eventually decides to upgrade, having two distinct environments makes the migration path clearer: you can test the new code against PHP 7 while keeping the old code on the legacy stack until the decision is made.

For a more robust long-term solution, consider using a dedicated PHP server like php-fpm with Nginx or Apache configured to proxy requests to specific ports based on domain, rather than relying solely on XAMPP's bundled binaries. This decouples the application logic from the web server configuration entirely. If you are building new applications in Laravel, for example, the framework handles multi-version environments very well by defaulting to modern PHP standards, which aligns with best practices outlined by LaravelCompany.

Our network