Trang chủTác giảLiên hệ

Install Multiple PHP Version with Apache on Ubuntu 18.04 & 16.04

By Nguyễn Văn Khánh
Published in PHP
June 09, 2021
2 min read

Apache Installation

Install Apache web server from the official repository. Launch terminal on your system or login with ssh for remote systems. Execute the following commands to install the latest available version of Apache web server.

PHP Installation

For the installation of PHP versions, we use the PPA maintained here. Use the below couple of commands to add the PPA to your system.

  For this tutorial, we are using the PHP 5.6 and PHP 7.2 to configure with Apache web server. To use the multiple PHP versions, we will use PHP FPM and FastCGI. Let’s install the following packages on your system.

  After installation, php-fpm services will be started automatically. Use the following commands to make sure both services are running.

Apache Configuration

Now enable few modules required for the configuration of multiple PHP versions with Apache. These modules are necessary to integrate PHP FPM and FastCGI with Apache server.

  Get ready for the configuration of websites on your Apache server. For the testing purpose, I am configuring two websites to work with two different-2 PHP versions. First, create two directories on your server.

  Now, create and index.php containing the phpinfo() function.

  Let’s start the creation of VirtualHost. Apache keeps all the VirtualHost configuration files under /etc/apache2/sites-available with the extension .conf. Create a file for the first virtual host and edit in your favorite text editor.

  Add the following content. Make sure to use correct ServerName and directory path according to your setup. This website is configured to work with PHP 5.6.

  Similarly, create a second VirtualHost configuration file to work with PHP 7.2. Edit configuration file in text editor:

  Add the following content to file with proper ServerName and DocumentRoot.

  You both of the websites are configured now. But they are still not active. Apache keeps active sites under /etc/apache2/sites-enabled directory. You can simply create a symbolic link of config files to this directory or use below command to do the same.

After making all the changes restart Apache to reload new settings changes.

  Your setup has been completed now. Go to the next step to test your setup.

Test Setup

Edit /etc/hosts file on your local system and make an entry like below. This will resolve temprory names to localhost IP address.

  Add following entry to end of file

  Open a web browser and visit both of the sites. You will see that shows the version PHP 5.6 and is showing the PHP 7.2 as the configuration.

Multiple PHP Version with Apache 1 alt text Multiple PHP Version with Apache 2 alt text

Nguyễn Văn Khánh

Related Posts

PHP - Một số thứ lặt vặt cho người mới
June 09, 2021
1 min
© 2021, All Rights Reserved.

Quick Links

Liên hệ quảng cáoThông tinLiên hệ

Social Media