Install PHP 5.5 On Ubuntu 12.04/16.04: A Step-by-Step Guide
Hey everyone! Running into snags while trying to get PHP 5.5 up and running on your older Ubuntu systems like 12.04 or 16.04 using the Ondrej PPA? You're not alone! It's a common head-scratcher, especially when your projects absolutely need that specific version. This article will dive deep into why this happens and, more importantly, give you a rock-solid, step-by-step guide to get PHP 5.5 installed and working. We'll also touch upon why you might be facing similar issues on other Unix-like systems like Mint, Xubuntu, and Lubuntu. Let's get started and tackle this problem together!
The PHP 5.5 Challenge on Older Ubuntu Systems
So, why is installing PHP 5.5 on Ubuntu 12.04 or 16.04 such a headache? The main culprit is the age of these Ubuntu versions. PHP 5.5 has reached its end-of-life, meaning it no longer receives official updates or support. The Ondrej PPA, a popular source for various PHP versions, might not have readily available packages for these older systems due to compatibility issues with the system's core libraries and dependencies. This is where the fun begins, but don't worry, we'll navigate through it!
Understanding the Dependency Maze: Think of your system as a complex Lego castle. Each piece (library, dependency) needs to fit perfectly for the whole structure (PHP 5.5) to stand. Older Ubuntu versions have different base components than newer ones. When you try to install PHP 5.5 from a PPA that's geared towards newer systems, those Lego pieces might not match up. This results in dependency conflicts, errors, and the frustrating "can't install" message. It's like trying to fit a square peg into a round hole – it just won't work!
Why You Might Still Need PHP 5.5: Now, you might be wondering, "Why bother with such an old version?" Well, some of us are working on legacy projects – those older applications that were built specifically to run on PHP 5.5. Upgrading these projects to newer PHP versions can be a massive undertaking, requiring significant code rewrites and testing. Sometimes, it's just more practical (and cost-effective) to keep the application running on its original environment. This is especially true for projects that are no longer actively developed but still need to be maintained. So, if you're in this boat, you're in the right place! We're going to make sure you can get PHP 5.5 running smoothly.
The broader Unix-like ecosystem: The challenges aren't limited to Ubuntu. Similar issues arise on other Unix-like systems like Mint, Xubuntu, and Lubuntu. These distributions often share the same underlying architecture and package management systems as Ubuntu. Therefore, if a package isn't readily available for Ubuntu 12.04 or 16.04, you'll likely encounter the same problem on their cousins. This underscores the importance of having a solution that's adaptable across different distributions. We’ll focus on Ubuntu, but the general principles we discuss can be applied to other Debian-based systems as well.
Step-by-Step Guide: Installing PHP 5.5 on Ubuntu 12.04 and 16.04
Alright, let's get down to the nitty-gritty and walk through the installation process. This method involves manually downloading and installing the necessary packages, which gives us more control over the process and bypasses the usual PPA limitations. Follow these steps carefully, and you'll be on your way to PHP 5.5 glory!
Step 1: Add the deb.sury.org
repository
Ondřej Surý's repository is a treasure trove for PHP versions, including the elusive PHP 5.5. First, we need to add the repository's signing key to our system to ensure the packages we download are authentic. Open your terminal and run:
sudo apt-get install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
Next, let's add the repository itself to our system's sources list. We need to determine the codename for your Ubuntu version (e.g., precise
for 12.04, xenial
for 16.04). You can find this by running:
lsb_release -cs
Now, let's add the repository to the sources list:
echo "deb https://packages.sury.org/php/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/php.list
Step 2: Update the Package Lists
With the new repository added, it's time to update our system's package lists. This ensures that our system knows about the available packages in the newly added repository. Run the following command:
sudo apt-get update
This command might throw some warnings or errors if the repository doesn't perfectly align with your system's version. Don't panic! We'll address these as we go along. The key is to ensure the update process completes.
Step 3: Install PHP 5.5 and Required Extensions
Now for the main event: installing PHP 5.5. But before we dive in, it's important to install specific packages that are compatible with your Ubuntu version. We'll use apt-get
with version pinning to target the correct packages. Here's how you can install PHP 5.5 along with some common extensions:
sudo apt-get install php5.5 php5.5-cli php5.5-fpm php5.5-curl php5.5-mysql php5.5-gd php5.5-intl php5.5-mcrypt php5.5-mbstring php5.5-xml
Breaking it down:
php5.5
: The core PHP 5.5 package.php5.5-cli
: The command-line interface for PHP.php5.5-fpm
: PHP FastCGI Process Manager, essential for web server integration.php5.5-curl
: For making HTTP requests from PHP.php5.5-mysql
: For interacting with MySQL databases.php5.5-gd
: For image processing.php5.5-intl
: For internationalization support.php5.5-mcrypt
: For encryption (though it's deprecated, it might still be needed for older projects).php5.5-mbstring
: For handling multi-byte strings.php5.5-xml
: For XML processing.
You can customize this list based on your project's specific needs. If you need other extensions, just add them to the command in the format php5.5-[extension-name]
. During this process, you might encounter dependency issues. If this happens, try installing the suggested dependencies manually using apt-get install [dependency-name]
. Sometimes, a little manual intervention is needed to resolve these conflicts.
Step 4: Configure PHP 5.5
With PHP 5.5 installed, it's time to configure it. The main configuration file is usually located at /etc/php5/fpm/php.ini
for the FPM version and /etc/php5/cli/php.ini
for the CLI version. Open these files with your favorite text editor (using sudo
, of course) and adjust the settings as needed.
Key configurations to consider:
memory_limit
: Adjust the memory limit to suit your application's needs. A common setting is128M
or256M
.upload_max_filesize
andpost_max_size
: Configure the maximum file upload size.error_reporting
anddisplay_errors
: Set these according to your environment (development vs. production).date.timezone
: Set your timezone to avoid warnings.
After making changes, restart the PHP FPM service to apply them:
sudo service php5.5-fpm restart
Step 5: Integrate with Your Web Server (e.g., Apache or Nginx)
If you're using PHP 5.5 for web applications, you'll need to integrate it with your web server. The process varies slightly depending on whether you're using Apache or Nginx.
For Apache:
-
Enable the PHP 5.5 FPM proxy module:
sudo a2enmod proxy_fcgi setenvif sudo a2enconf php5.5-fpm
-
Restart Apache:
sudo service apache2 restart
For Nginx:
You'll need to configure your virtual host to pass PHP requests to the PHP 5.5 FPM service. Here's a snippet of a typical Nginx virtual host configuration:
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5.5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Make sure the fastcgi_pass
directive points to the correct socket for PHP 5.5 FPM.
After making changes, restart Nginx:
sudo service nginx restart
Step 6: Verify the Installation
To confirm that PHP 5.5 is installed and working correctly, create a simple PHP file (e.g., info.php
) in your web server's document root with the following content:
<?php
phpinfo();
?>
Then, access this file through your web browser (e.g., http://your-server-ip/info.php
). You should see the PHP information page, confirming that PHP 5.5 is running. If you see the PHP 5.5 information page, congratulations! You've successfully installed PHP 5.5 on your Ubuntu system.
Troubleshooting Common Issues
Even with the best instructions, things can sometimes go sideways. Here are some common issues you might encounter and how to troubleshoot them:
- Dependency Conflicts: If you encounter dependency errors during installation, try installing the missing dependencies manually using
apt-get install [dependency-name]
. You might need to add additional repositories or use version pinning to resolve these conflicts. - PHP Not Processing in Web Server: Double-check your web server configuration (Apache or Nginx) to ensure it's correctly configured to pass PHP requests to the PHP 5.5 FPM service. Verify the socket path and module configurations.
- Missing Extensions: If you need additional PHP extensions, install them using
apt-get install php5.5-[extension-name]
. Ensure that the extensions are enabled in thephp.ini
file. - PHP Version Not Recognized: If the system still defaults to a different PHP version, you might need to use the
update-alternatives
command to set PHP 5.5 as the default. This is less common but can occur in certain situations.
Why This Method Works
This manual installation approach works because it gives you fine-grained control over the process. By adding the deb.sury.org
repository and explicitly installing the PHP 5.5 packages, we bypass the limitations of the default Ubuntu repositories and the standard PPA setup. This allows us to target the specific packages we need for PHP 5.5, even on older systems. Furthermore, by manually addressing dependency issues and configuring the web server integration, we ensure that PHP 5.5 works seamlessly with our environment. It might seem a bit more involved than a simple apt-get install
, but the extra control is worth it when dealing with legacy software requirements.
A Word of Caution: Security Implications
Before we wrap up, it's crucial to address the security implications of running an outdated PHP version. PHP 5.5 is no longer actively maintained, which means it doesn't receive security patches. This can leave your system vulnerable to known exploits. If possible, consider migrating your applications to a supported PHP version (e.g., 7.4 or 8.1). If you must continue using PHP 5.5, take extra precautions to secure your server, such as using a firewall, keeping other software up-to-date, and monitoring for suspicious activity. Running outdated software is like leaving your front door unlocked – it's an invitation for trouble.
Conclusion
Installing PHP 5.5 on Ubuntu 12.04 or 16.04 can be a bit of a journey, but with this guide, you're well-equipped to tackle the challenge. Remember to follow the steps carefully, troubleshoot any issues that arise, and, most importantly, be mindful of the security implications. By understanding the underlying reasons for the installation difficulties and taking a manual approach, you can successfully run your legacy applications on PHP 5.5. Good luck, and happy coding!