How to Install PHP 5.3, 5.4, and 5.5 on Modern Debian and Ubuntu Systems

PHP5 support on Debian 12 and Ubuntu 22.04

Although PHP 5.3, 5.4, and 5.5 have long since reached their end-of-life, some legacy applications may still depend on them. Installing these outdated versions on modern systems like Debian 10/11/12 or Ubuntu 20.04/22.04 requires manually building the software and resolving dependencies. This guide provides a step-by-step approach, including dependency management (such as curl, OpenSSL, and the intl extension).

Why Use Legacy PHP Versions?

While using legacy PHP versions isn’t recommended, some scenarios may necessitate their use:

  • Legacy Applications: Applications developed years ago may not yet be updated to support modern PHP versions.
  • Specialized Requirements: Some environments or software integrations may temporarily rely on outdated PHP versions.

Before You Begin

Keep in mind:

  • Security Risks: Legacy PHP versions are no longer supported and lack security updates, making them highly vulnerable.
  • Isolation: Always run these versions in isolated environments, such as a container or a virtual machine, to minimize potential risks.

Prerequisites

Ensure your system meets the following requirements:

  • A machine running Debian 10/11/12 or Ubuntu 20.04/22.04.
  • Administrative privileges.
  • Essential build tools installed.

Step 1: Install Required Dependencies

Before starting the build process, ensure that all necessary build tools and libraries are installed. Use the following commands to update your system and install dependencies:

sudo apt update

sudo apt install build-essential libxml2-dev libjpeg-dev libpng-dev \
libfreetype6-dev libmcrypt-dev libxslt1-dev libkrb5-dev libltdl-dev \ 
default-libmysqlclient-dev

These libraries are essential for compiling PHP and ensuring compatibility with various extensions.

Step 2: Compile and Install OpenSSL 1.0.2u

For compatibility reason we will compile and install OpenSSL 1.0.2u manually:

1. Download OpenSSL Source Code:

wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
tar -xzf openssl-1.0.2u.tar.gz
cd openssl-1.0.2u

2. Build and Install OpenSSL

./config shared --openssldir=/opt/openssl-1.0.2/ enable-ec_nistp_64_gcc_128
make depend
make
make install
ln -s /opt/openssl-1.0.2/lib /opt/openssl-1.0.2/lib/x86_64-linux-gnu

3. Add OpenSSL libraries path to system runtime

Create file /etc/ld.so.conf.d/openssl.conf and add line:

/opt/openssl-1.0.2/lib

Update shared library cache:

ldconfig

4. Verify Installation

/opt/openssl-1.0.2/bin/openssl version
OpenSSL 1.0.2u 20 Dec 2019

Step 3: Compile c-client library for php-imap

To enable IMAP functionality in PHP, you need to build the c-client library, which PHP relies on for email handling. Follow these steps to build and install it:

1. Download and unpack the source code:

cd /opt
wget --no-check-certificate https://wiki.olvy.net/download/c-client.tar.gz
tar xzf c-client.tar.gz
cd /opt/imap-2007f

2. Set OpenSSL directory:

nano /opt/imap-2007f/src/osdep/unix/Makefile

[...]
SSLDIR=/opt/openssl-1.0.2

[...]

3. Set EXTRACFLAGS to disable kerberos :

nano /opt/imap-2007f/Makefile

Find EXTRACFLAGS= and change it to EXTRACFLAGS=-fPIC

4. Compile c-client:

make slx IP6=4

Step 4: Compile Curl bundled with OpenSSL 1.0.2u

Older PHP versions may require a specific version of curl. Compile and install it as follows:

1. Download and unpack the source code:

wget https://curl.se/download/curl-7.88.1.tar.gz
tar xzf curl-7.88.1.tar.gz
cd curl-7.88.1

2. Configure Curl:

./configure --prefix=/opt/curl --with-ssl=/opt/openssl-1.0.2 --with-ca-path=/etc/ssl/certs

3. Compile and install Curl:

make
...
make install

Step 5: Compile PHP 5.x

1. Download the PHP Source Code

Download the source code for the specific PHP version you need from the PHP archives:

Download and extract PHP 5.3:

wget https://www.php.net/distributions/php-5.3.29.tar.gz
tar xzf php-5.3.29.tar.gz
cd php-5.3.29

Download and extract PHP 5.4

wget https://www.php.net/distributions/php-5.4.45.tar.gz
tar xzf php-5.4.45.tar.gz
cd php-5.4.45

Download and extract PHP 5.5

wget https://www.php.net/distributions/php-5.5.38.tar.gz
tar xzf php-5.5.38.tar.gz
cd php-5.5.38

Notes regarding Freetype:

We will install PHP 5.x into directory /opt/php5/

If you need Freetype support enabled for PHP, using --with-freetype-dir option, please note:

freetype-config is deprecated and no longer included in libfreetype6-dev package, we will take freetype-config from Debian 9 libfreetype6-dev package:

wget http://archive.debian.org/debian-security/pool/updates/main/f/freetype/libfreetype6-dev_2.6.3-3.2+deb9u2_amd64.deb -O - | dpkg --fsys-tarfile - | tar xOf - ./usr/bin/freetype-config > /usr/bin/freetype-config && chmod +x /usr/bin/freetype-config

2. Configure PHP 5.x:

./configure --prefix=/opt/php5 --with-config-file-path=/opt/php5/etc --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --enable-bcmath --enable-opcache --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-mbstring --enable-soap --enable-sockets --enable-zip --with-curl=/opt/curl --with-freetype-dir=/usr --with-gd --with-gettext --with-mcrypt --enable-mysqlnd --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-openssl=/opt/openssl-1.0.2 --with-openssl-dir=/opt/openssl-1.0.2 --with-zlib --with-xsl --with-zlib-dir=/usr --enable-calendar --enable-gd-native-ttf --with-jpeg-dir=/usr --with-png-dir=/usr --with-imap=/opt/imap-2007f --with-imap-ssl

On Arm64 platforms also add:

--host=aarch64-linux-gnu --build=unknown-unknown-linux

3. If PHP configured successfully, make and install it:

make
...
make install

Step 6: Install PHP 5.x

1. Copy php.ini

Copy file /usr/src/php-5.x.x/php.ini-production to default php.ini location:

cp /usr/src/php-5.x.x/php.ini-production /opt/php5/etc/php.ini

2. Create systemd unit

Next, we’ll create the system unit file which is used to start and stop the PHP-FPM daemon.

nano /lib/systemd/system/php5-fpm.service

With the following content:

[Unit]
Description=The PHP 5.x FastCGI Process Manager
After=network.target

[Service]
Type=simple
PIDFile=/opt/php5/var/run/php-fpm.pid
ExecStart=/opt/php5/sbin/php-fpm --nodaemonize --fpm-config /opt/php5/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

Enable the service and reload systemd:

systemctl enable php5-fpm.service
systemctl daemon-reload

3. Add PHP-FPM configuration

Create PHP-FPM default configuration file:

nano /opt/php5/etc/php-fpm.conf

With content:

[global]
error_log = log/php-fpm.log
include=/opt/php5/etc/pool.d/*.conf

Create PHP-FPM pool folder:

mkdir /opt/php5/etc/pool.d

Create PHP-FPM pool configuration file:

nano /opt/php5/etc/pool.d/yourwebsite.tld.conf

With the content:

[yourwebsite.tld]

user = yourusername
group = yourusername

listen = /opt/php5/var/run/php5-fpm.yourusername.sock

listen.owner = yourusername
listen.group = yourusername

pm = dynamic
pm.max_children = 20
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

*yourusername is a system user you are going to use to run PHP.

Add HTTP default user www-data to PHP user’s group:

usermod -a -G yourusername www-data

4. Start/Stop/Restart PHP-FPM

Start PHP-FPM:

systemctl start php5-fpm.service

Stop PHP-FPM:

systemctl stop php5-fpm.service

Restart PHP-FPM:

systemctl restart php5-fpm.service

PHP-FPM status:

systemctl status php5-fpm.service

Step 7: Install ”intl” extension for PHP 5.x (optional)

 Internationalization library (“intl”) is a PHP extension that acts as a wrapper for ICU (International Components for Unicode) library. It allows PHP developers to execute a wide range of operations that are sensitive to locale settings, such as formatting dates, numbers, and currencies, as well as working with text in multiple languages.

1. Download icu 57.1 sources, as dependency for intl extension:

wget https://archive.debian.org/debian/pool/main/i/icu/icu_57.1.orig.tar.gz

2. Build and install icu:

tar xzf icu_57.1.orig.tar.gz
cd icu/source
./configure --prefix=/opt/icu_57.1
make
make install

3. Compile and install intl extension:

wget https://pecl.php.net/get/intl-3.0.0.tgz
tar xzf intl-3.0.0.tgz
cd intl-3.0.0
/opt/php5/bin/phpize

./
configure --with-icu-dir=/opt/icu_57.1 --enable-intl --with-php-config=/opt/php5/bin/php-config
make make install

4. Add intl extension to php.ini :

nano /opt/php5/etc/php.ini
extension=intl.so

5. Create symlink for icu library:

ln -s /opt/icu_57.1/lib/libicudata.so.57.1 /usr/lib/x86_64-linux-gnu/libicudata.so.57

6. Restart PHP-FPM:

systemctl restart php5-fpm.service

Security Considerations

Using legacy PHP versions comes with significant security risks. Protect your environment by:

  • Isolating: Use containers or VMs to limit exposure.
  • Restricting Access: Implement strict firewall rules.
  • Planning an Upgrade: Work towards migrating applications to a supported PHP version.

Conclusion

This guide demonstrates the full process for installing PHP 5.3, 5.4, and 5.5 on modern Debian and Ubuntu systems, such as Debian 10/11/12 or Ubuntu 20.04/22.04. While these steps enable legacy applications to run, upgrading to a supported PHP version is strongly advised to ensure security and performance.


About Olvy ( www.olvy.net / www.olvy.eu ) : Olvy is a private and independent Limited Liability Company based in Bratislava, Slovakia, in the heart of Europe. We combined our invaluable 20+ years experience to develop innovative and reliable, lightning-fast and affordable Managed Cloud Hosting services for Everyone. From a small blog to a growing eCommerce –Olvy takes care of your website 24/7.

Leave a Reply