It is sometimes necessary to run a legacy application against an older version of PHP in order to start a migration process. The problem is that it’s very difficult to find a platform that still allows for an easy installation of an older version of PHP. This is where specialized stacks, like Linux for PHP (LfPHP), step in. These Docker-based containers allow us to compile almost any version of PHP. In this short article, we’ll be compiling PHP 5.2.17 on Linux for PHP.
Running Linux for PHP
First of all, you need to have Docker on your computer. If you don't, please go to the following URL for instructions: https://docs.docker.com/install/overview/.
Next, you'll need to start a generic Linux for PHP image on your computer from the command line:
This line will instruct Docker to start the ‘src’ image of LfPHP, and make its port 80 available on your computer’s port 8181. Docker will also automatically download all of the LfPHP images that are needed to run the ‘src’ image.
Configuring and Installing PHP 5.2
From the container’s CLI, we can now start downloading, and unpacking PHP 5.2.17:
Once the archive is unpacked, it will be necessary to apply two patches to the PHP package in order to get SimpleXML and the APXS interface to compile smoothly:
Then, we are ready to configure the package. We'll be omitting the MySQL/MySQLi compile options, as these would require that we download old MySQL headers in order to avoid some backward compatibility breaks that were introduced over the years by MySQL/MariaDB. Although we are not covering this aspect of compilation in this article, we might cover it in an upcoming article. For now, let’s proceed to configure PHP with PDO, but without MySQL/MySQLi:
Once configured, we need to compile and install the package:
After installation is complete, you can make sure that PHP 5.2 is properly installed by entering the following command:
The PHP CLI should indicate that it is version 5.2.17.
From here, we must enable mod_php on Apache, and thus make PHP available to run the Web server’s scripts by modifying Apache’s httpd.conf file, as follows:
Now, the only commands left to enter are the ones to create a ‘phpinfo()’ file and start the Apache Web server itself:
If everything went well, you should now see the ‘phpinfo’ page by requesting the http://localhost:8181/index.php URL in your browser:
Enjoy!