Skip to content

Instantly share code, notes, and snippets.

@mthabsheer
Created May 22, 2018 00:24
Show Gist options
  • Save mthabsheer/2811a146fa35336402116793740b879d to your computer and use it in GitHub Desktop.
Save mthabsheer/2811a146fa35336402116793740b879d to your computer and use it in GitHub Desktop.
--------------PHP versions----------------
sudo apt show php
OR
sudo apt show php -a
//install default PHP version
sudo apt install php
First start by adding Ondřej Surý PPA to install different versions of PHP – PHP 5.6, PHP 7.0 and PHP 7.1 on Ubuntu system.
sudo apt install python-software-properties
sudo add-apt-repository ppa:ondrej/php
Next, update the system as follows.
sudo apt-get update
Now install different supported versions of PHP as follows.
For Apache Web Server
sudo apt install php5.6
sudo apt install php7.0
sudo apt install php7.1
For Nginx Web Server
sudo apt install php5.6-fpm
sudo apt install php7.0-fpm
sudo apt install php7.1-fpm
To install any PHP modules, simply specify the PHP version and use the auto-completion functionality to view all modules as follows.
sudo apt install php5.6
------------ press Tab key for auto-completion ------------
$ sudo apt install php5.6
$ sudo apt install php7.0
$ sudo apt install php7.1
Now you can install most required PHP modules from the list.
------------ Install PHP Modules ------------
$ sudo apt install php5.6-cli php5.6-xml php5.6-mysql
$ sudo apt install php7.0-cli php7.0-xml php7.0-mysql
$ sudo apt install php7.1-cli php7.1-xml php7.1-mysql
Set Default PHP Version in Ubuntu
7. You can set the default PHP version to be used on the system with the update-alternatives command, after setting it, check the PHP version to confirm as follows.
------------ Set Default PHP Version 5.6 ------------
$ sudo update-alternatives --set php /usr/bin/php5.6
To set the PHP version that will work with Apache web server, use the commands below. First disable the current version with the a2dismod command and then enable the one you want with the a2enmod command.
$ sudo a2dismod php7.0
$ sudo a2enmod php7.1
$ sudo systemctl restart apache2
After switching from one version to another, you can find your PHP configuration file, by running the command below.
------------ For PHP 5.6 ------------
$ sudo update-alternatives --set php /usr/bin/php5.6
$ php -i | grep "Loaded Configuration File"
------------ For PHP 7.0 ------------
$ sudo update-alternatives --set php /usr/bin/php7.0
$ php -i | grep "Loaded Configuration File"
------------ For PHP 7,1 ------------
$ sudo update-alternatives --set php /usr/bin/php7.1
$ php -i | grep "Loaded Configuration File"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment