How to check if there are multiple versions of PHP installed on Ubuntu 12.04 LTS?

How to check if there are multiple versions of PHP installed on Ubuntu 12.04 LTS?

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

Stefan Bogdanescu

Founder & Senior Architect

Identifying and Managing Multiple PHP Versions on Ubuntu 12.04 LTS

On Ubuntu 12.04 LTS, managing mixed PHP environments often stems from upgrading packages while retaining legacy dependencies or manually compiling specific versions for compatibility. If you are unsure whether both php5.3 and php5.5 coexist on your system, the first step is to inspect the package manager's state. Ubuntu handles these versions as distinct packages, so simply checking /usr/bin/php -v might only show the default binary linked by Apache or CLI.

Run the following command to list installed PHP packages:

dpkg -l | grep '^ii' | grep php5

This filters for packages currently installed (^ii) and identifies those starting with php5. You will likely see entries like php5, php5-cli, php5-curl, or specifically php5.3 if it was added via a third-party repository (like Ondřej Surý's PPA) alongside the official Ubuntu 12.04 packages. If you see both version strings in the output, both sets of binaries are present on your disk, even if Apache is only pointing to one.

To definitively check which binary Apache is using, examine the libphp5.so symlink or the specific module file. Navigate to the Apache modules directory:

ls -l /etc/apache2/mods-available/php5.conf

Open this file to inspect the directive LoadModule. It might reference php5_module.so (generic) or a versioned path depending on how the package was installed. Additionally, check the CLI binary location:

which php
readlink -f $(which php)

If these paths point to different binaries than expected, you have a multi-version setup. A common pitfall is assuming that installing php5.5 automatically removes php5.3. On Debian/Ubuntu systems, package managers do not perform automatic dependency purging unless explicitly told to remove conflicting packages. If both are installed, you risk runtime errors if your application relies on extensions compiled against the older version while Apache loads the newer one.

Removing Legacy PHP Versions

If your goal is to delete php5.3 in favor of php5.5, use apt-get or aptitude. First, ensure you have updated your package lists:

sudo apt-get update

Then, attempt to remove the specific versioned packages while keeping core dependencies intact if possible:

sudo apt-get remove --purge php5.3-*

The --purge flag removes configuration files associated with those packages. Be cautious here; if php5.3 is listed as a dependency for another critical library (rare in modern setups, but possible in old LTS releases), the removal might fail or require you to reinstall dependent packages manually. After removal, verify that no orphaned binaries remain:

dpkg -l | grep php5.3

If the list is empty, the package manager has successfully cleaned up the versioned files. However, if php5.3 was installed outside of standard repositories (e.g., via .deb download), apt-get won't know about it, and you must manually delete the binaries from /usr/bin/php5.3*, /lib/php5.3/, and /etc/php5.3/.

Configuring Apache2 for PHP 5.5

Once only php5.5 remains, you must ensure Apache loads the correct modules. Open the main PHP configuration file:

sudo nano /etc/apache2/mods-available/php5.conf

Ensure the line LoadModule php5_module lib/php5/libphp5.so (or similar) points to the library directory associated with PHP 5.5, typically /usr/lib/php5/. If your distribution places libraries in /usr/lib64 or a versioned subdirectory like /usr/lib/php5.5/, update the path accordingly.

Restart Apache to apply changes:

sudo service apache2 restart

Finally, verify that PHP is processing requests by creating a simple test file at /var/www/html/info.php:

<?php phpinfo(); ?>

Visit http://your-server/info.php in a browser. The output should reflect the version 5.5 headers. If you see a plain text "403 Forbidden" or a missing PHP block, check file permissions and ensure no conflicting .htaccess rules are blocking execution.

If you ever need to switch back between versions without deleting them, consider using PHP-FPM with separate user directories rather than relying solely on Apache's mod_php. This approach isolates the SAPI (Server API) configuration per version, preventing the "which php binary is running" ambiguity entirely.

Our network