Ubuntu 20.04 | Apache 2.4 | PHP 5.5.x

I was faced with a non trivial situation where I need to run Ubuntu 20.04 and Apache 2.4 with old PHP 5.5.9. My first try was to find an APT Repo that could have this version to install. This could solve my problem. I checked at ondrej/php PPA repository but, of course, the oldest version there is 5.6.

The second option was to find a Docker Image to use this version. Of course that I will find some options but:

https://www.trendmicro.com/vinfo/hk-en/security/news/virtualization-and-cloud/malicious-docker-hub-container-images-cryptocurrency-mining

I´m not telling that I´ve found one malicious container image. The fact is that there are some. You need to be sure that the image you´re using is clean and safe. Another thing that make me think a little bit about using a Docker image is that this server was not ready to use Docker and would become an island.

Then, I decided to use old school approach: Build PHP from scratch compiling the source code. Well, let´s do it:

I started with Ubuntu 20.04 and Apache 2.4 already installed:

# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"

root@render-webserver-01:~# apt list --installed 'apache*'
Listing... Done
apache2-bin/focal-security,now 2.4.41-4ubuntu3.3 amd64 [installed,upgradable to: 2.4.41-4ubuntu3.4]
apache2-data/focal-security,now 2.4.41-4ubuntu3.3 all [installed,upgradable to: 2.4.41-4ubuntu3.4]
apache2-utils/focal-security,now 2.4.41-4ubuntu3.3 amd64 [installed,upgradable to: 2.4.41-4ubuntu3.4]
apache2/focal-security,now 2.4.41-4ubuntu3.3 amd64 [installed,upgradable to: 2.4.41-4ubuntu3.4]

Then, we can start stopping Apache service, installing one pre-req to enable PHP and Apache integration, apache2-dev package, download desired PHP Version (5.5.9 in my case) and extract it:

# systemctl stop apache2
# apt install apache2-dev
# wget https://www.php.net/distributions/php-5.5.9.tar.gz && tar xzvf ./php-5.5.9.tar.gz && cd php-5.5.9

Next, configure with desired options and compile it:

# ./configure --with-mysql --with-apxs2=/usr/bin/apxs2
# make && make install

Note: The option --with-apxs2 needs to be filled by full path to apxs2 at your environment
Note: You can find more configuration options running ./configure --help 

Almost finished. Now it´s time to configure Apache to load PHP5 modules by editing configuration file:

# vi /etc/apache2/apache2.conf

Be sure that you find these lines inside your configuration file. If no, add it:

.
.
.
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
.
.
.
<FilesMatch \.php$>
        SetHandler application/x-httpd-php
</FilesMatch>
.
.
.

Note: Dots (.) is only to let you know that maybe there are some spaces or other lines before / after the blocks.

If you would like to see a full sample apache2.conf file, get it here.

To enable php module at Apache and start Apache Service run:

# a2enmod php5
Enabling module php5.
To activate the new configuration, you need to run:
  systemctl restart apache2

# systemctl restart apache2

Check if Apache is running:

# systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-07-29 00:18:32 UTC; 25s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 385564 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 385582 (apache2)
      Tasks: 6 (limit: 4682)
     Memory: 6.7M
     CGroup: /system.slice/apache2.service
             ├─385582 /usr/sbin/apache2 -k start
             ├─385583 /usr/sbin/apache2 -k start
             ├─385584 /usr/sbin/apache2 -k start
             ├─385585 /usr/sbin/apache2 -k start
             ├─385586 /usr/sbin/apache2 -k start
             └─385587 /usr/sbin/apache2 -k start

Jul 29 00:18:32 render-webserver-01 systemd[1]: Starting The Apache HTTP Server...
Jul 29 00:18:32 render-webserver-01 apachectl[385577]: AH00558: apache2: Could not reliably determine the server's fully qualified domai>
Jul 29 00:18:32 render-webserver-01 systemd[1]: Started The Apache HTTP Server.

You can check php version by running at shell:

# php -v
PHP 5.5.9 (cli) (built: Jul 28 2021 19:40:30)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

And to check the Apache integration, create a file called phpinfo.php at your DocumentRoot dir (/var/www/html in my case), with the following content:

<?php
phpinfo();
?>

Save the file and access using a browser:

http://ip_of_your_web_server/phpinfo.php

You can see the result:

phpinfo result

That´s the end. Hope that this can help someone.

About the Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these