Sunday . 14 Jul. 2024

PHP Version Manager On Ubuntu 18.04 Using Apache & NGINX

PHP Version Manager On Ubuntu 18.04 Using Apache & NGINX

In this tutorial we will learn to set up multiple PHP versions and use on the project basics. Since we don't any PHP version manager like nodes's NVM (Node Version Manager), We will configure manually and use it. 

1. Get the information of PHP

$ sudo apt show php


$ sudo apt show php -a
$ sudo apt install php //this will install default php version ( may be 7.2 )

2. To Install Different Versions Of PHP

$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update

2.1 For Apache

$ sudo apt install php5.6   //[PHP 5.6]
$ sudo apt install php7.2   //[PHP 7.2]

2.2 For Nginx

$ sudo apt install php5.6-fpm   //[PHP 5.6]
$ sudo apt install php7.2-fpm   //[PHP 7.2]

3. To Install Required Modules

$ sudo apt install php5.6-cli php5.6-xml php5.6-mysql ...
$ sudo apt install php7.2-cli php7.2-xml php7.2-mysql ...

4. Set Default PHP Version in Ubuntu (i.e. from 7.2 to 5.6)

$ sudo update-alternatives --set php /usr/bin/php5.6
$ sudo a2dismod php7.2
$ sudo a2enmod php5.6
$ sudo systemctl restart apache2

And so on

Readers Comment