Why yum install php56 Fails on Amazon Linux and How to Actually Get PHP 5.6 Running
If you attempt to run yum install php56 on a standard Amazon Linux instance, you will encounter an immediate error: No package php56 available. This isn't a broken command syntax or a missing repository flag; it is a result of Amazon Linux's strict packaging policy regarding legacy PHP versions.
Amazon Linux 1 (the generation that predates the switch to Amazon Linux 2) shipped with PHP 5.4 by default and included PHP 5.6 support, but only as part of specific, non-standard repositories or via third-party builds like Remi. The official amazon-linux-extras repository often omits older PHP versions once newer versions (like 7.x or 8.x) become the stable baseline. Consequently, the base package manager does not know about a binary named php56.
To get PHP 5.6 running on Amazon Linux, you have two primary paths: enabling the legacy extras repository if it still exists for your specific AMI version, or installing from a third-party EPEL-style repository. However, before proceeding with installation, you must address the critical compatibility question regarding Apache.
Apache Version Compatibility
PHP 5.6 requires an Apache HTTP Server that supports the mod_php module and understands the syntax changes introduced in PHP 5.4 and 5.6. Specifically, you need to ensure your Apache version is at least 2.4.6 or 2.4.7.
If you are running the default Amazon Linux packages, your system likely has Apache 2.4.6 installed, which works seamlessly with PHP 5.6. However, if you have upgraded your web server to a newer version (e.g., via yum update), you may encounter issues because the package names for modules often changed between major versions.
For example, in older setups, the module was named php56-php-mbstring. In later Amazon Linux updates or when using third-party repos, it might be php56-php-cli, php56-php-fpm, etc., or simply integrated into a generic php package if the versioning scheme shifts. The most common pitfall is enabling PHP 5.6 but forgetting that the Apache module (mod_php) needs to be reloaded or restarted after installation, and potentially conflicting with other PHP versions installed on the same system (e.g., PHP 7.x). If you have multiple PHP versions active, ensure your .htaccess files or httpd.conf are pointing to the correct libphp path for version 5.6, not the newer one.
Installing PHP 5.6 via Third-Party Repositories
Since the official Amazon Linux repositories generally do not provide php56 binaries in recent iterations, the most reliable method is to use a third-party repository like Remi or IUS, which maintain backports for older versions.
First, you must ensure your system has a package manager that can handle these external repos. If you are on Amazon Linux 1, you might find packages via yum if the repo key is imported correctly. Here is a typical workflow using the Remi repository structure:
# Import the GPG key for verification
rpm --import https://rpms.remirepo.net/RPM-GPG-KEY-remi
# Add the remi repo configuration for PHP 5.6
curl -s https://rpms.remirepo.net/enterprise/remi-release-eol.repo > /etc/yum.repos.d/remi-php56-eol.repo
# Enable the specific PHP 5.6 module (if available in the repo structure)
yum-config-manager --enable remi-php56
# Install Apache, PHP CLI, and the specific modules needed
yum install httpd php56-php php56-php-cli php56-php-common \
php56-php-mysqlnd php56-php-pear php56-php-mbstring php56-php-curl
Note: The exact repository name or package structure may vary depending on the specific Amazon Linux minor version. Always verify that the packages resolve correctly before attempting to restart services.
Once the packages are installed, you must configure Apache to use the correct PHP binary. If your system has multiple PHP versions (e.g., default PHP 5.4 and newly installed PHP 5.6), you need to explicitly point the Apache module to the 5.6 installation directory. You can do this by creating a symbolic link or updating the Alias directive in your virtual host configuration.
Potential Pitfalls and Best Practices
The primary risk when installing PHP 5.6 is security. PHP 5.6 reached End of Life (EOL) in December 2018, meaning it no longer receives security patches. If you are deploying a new application, relying on PHP 5.6 is generally discouraged unless you have strict legacy compatibility requirements that cannot be met by PHP 7 or 8.
Another common mistake is assuming that installing php56 automatically updates your Apache configuration. You must manually verify the LoadModule directives in /etc/httpd/conf.modules.d/. If multiple PHP modules are loaded (e.g., both PHP 5.4 and PHP 5.6), Apache will throw a fatal error upon startup because it cannot determine which SAPI to use.
Finally, if you are migrating from an older setup where php56 was the default, ensure that your application's php.ini is loaded from the correct path (usually /etc/php/5.6/fpm/php.ini or similar). A mismatched configuration file can lead to silent failures where the app thinks it's running on one version while actually executing another, causing deprecation warnings or feature breakages.