Introduction

This guide explains how to install Apache 2.4 and PHP 5.6 on Ubuntu 16.04. Since Ubuntu 16.04 does not provide PHP 5.6 as the default PHP version, an additional PHP repository is required. This setup is useful for applications that depend on PHP 5.6 for compatibility.

Prerequisites

Before starting the installation, ensure you have:

  • An Ubuntu 16.04 server.
  • Root or sudo access to the server.
  • A stable internet connection to download the required packages.
  • Basic knowledge of Linux commands and package management.
  • An application that requires PHP 5.6 for compatibility.

IMPLEMENTATION

Add a PPA repo(Personal Package Archive) to the server.

add-apt-repository ppa:ondrej/php

Since this post deals with PHP 5.6, we haven’t included any steps to install a previous version of PHP, such as PHP 5.5 or PHP 5.4. Moreover, PHP 5.5 and PHP 5.4 are no longer supported with security updates.

Now, install the PHP 5.6 application using apt-get.

apt-get install php5.6 php5.6-dev php5.6-curl php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml php5.6-zip

You will be prompted to press Enter to continue. To continue, press Enter continue

The above command will install most of the dependencies, including apache2 and all other dependency packages.

Start the apache2 service and enable the service on systemctl.

systemctl start apache2

systemctl enable apache2

Let’s check the PHP version.

php -v
PHP 5.6.29-1+deb.sury.org~xenial+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

 

Create a phpinfo page on the domain document root or server document root. By default, the location will be /var/www/html

vi /var/www/html/info.php

<?php

phpinfo();

?>

Access the page in the browser at http://IPADDRESS/info.php. You will see the PHP info page with PHP 5.6 version.

Conclusion

In this guide, we installed Apache 2.4 and PHP 5.6 on Ubuntu 16.04 and verified the PHP installation using the php -v command and a phpinfo() page. This setup can be used to support legacy PHP applications that require PHP 5.6. For new deployments, using a currently supported PHP version is recommended.

Leave a Reply