Set default php version linux

How to Install Different PHP (5.6, 7.x and 8.0) Versions in Ubuntu

PHP (recursive acronym for PHP: Hypertext Preprocessor) is an open-source, popular general-purpose scripting language that is widely used and best suited for developing websites and web-based applications. It is a server-side scripting language that can be embedded in HTML.

Currently, there are three supported versions of PHP, i.e PHP 5.6, 7.0, and 8.0. Meaning PHP 5.3, 5.4, and 5.5 have all reached the end of life; they are no longer supported with security updates.

In this article, we will explain how to install all the supported versions of PHP in Ubuntu and its derivatives with the most requested PHP extensions for both Apache and Nginx web servers using an Ondřej Surý PPA. We will also explain how to set the default version of PHP to be used on the Ubuntu system.

Note that PHP 7.x is the supported stable version in the Ubuntu software repositories, you can confirm this by running the apt command below.

$ sudo apt show php OR $ sudo apt show php -a
Package: php Version: 1:7.0+35ubuntu6 Priority: optional Section: php Source: php-defaults (35ubuntu6) Origin: Ubuntu Maintainer: Ubuntu Developers [email protected]> Original-Maintainer: Debian PHP Maintainers [email protected]> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 11.3 kB Depends: php7.0 Supported: 5y Download-Size: 2,832 B APT-Sources: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages Description: server-side, HTML-embedded scripting language (default) PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. . This package is a dependency package, which depends on Debian's default PHP version (currently 7.0).

To install the default PHP version from the Ubuntu software repositories, use the command below.

Install PHP (5.6, 7.x, 8.0) on Ubuntu Using PPA

1. First start by adding Ondřej Surý PPA to install different versions of PHP – PHP 5.6, PHP 7.x, and PHP 8.0 on the Ubuntu system.

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

Add PPA in Ubuntu

2. Next, update the system as follows.

3. Now install different supported versions of PHP as follows.

For Apache Web Server

$ sudo apt install php5.6 [PHP 5.6] $ sudo apt install php7.0 [PHP 7.0] $ sudo apt install php7.1 [PHP 7.1] $ sudo apt install php7.2 [PHP 7.2] $ sudo apt install php7.3 [PHP 7.3] $ sudo apt install php7.4 [PHP 7.4] $ sudo apt install php8.0 [PHP 8.0]

For Nginx Web Server

$ sudo apt install php5.6-fpm [PHP 5.6] $ sudo apt install php7.0-fpm [PHP 7.0] $ sudo apt install php7.1-fpm [PHP 7.1] $ sudo apt install php7.2-fpm [PHP 7.2] $ sudo apt install php7.3-fpm [PHP 7.3] $ sudo apt install php7.4-fpm [PHP 7.4] $ sudo apt install php8.0-fpm [PHP 8.0]

4. To install any PHP modules, simply specify the PHP version and use the auto-completion functionality to view all modules as follows.

------------ press Tab key for auto-completion ------------ $ sudo apt install php5.6 $ sudo apt install php7.0 $ sudo apt install php7.1 $ sudo apt install php7.2 $ sudo apt install php7.3 $ sudo apt install php7.4 $ sudo apt install php8.0

Search PHP Modules

5. Now you can install the 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 $ sudo apt install php7.2-cli php7.2-xml php7.2-mysql $ sudo apt install php7.3-cli php7.3-xml php7.3-mysql $ sudo apt install php7.3-cli php7.4-xml php7.4-mysql $ sudo apt install php7.3-cli php8.0-xml php8.0-mysql

6. Finally, verify your default PHP version used on your system like this.

Читайте также:  Cv2 python install linux

Check Default PHP Version in Ubuntu

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

Set PHP 5.6 Version in Ubuntu

------------ Set Default PHP Version 7.0 ------------ $ sudo update-alternatives --set php /usr/bin/php7.0

Set PHP 7.0 Version in Ubuntu

------------ Set Default PHP Version 7.1 ------------ $ sudo update-alternatives --set php /usr/bin/php7.1

Set PHP 7.1 Version in Ubuntu

------------ Set Default PHP Version 8.0 ------------ $ sudo update-alternatives --set php /usr/bin/php8.0

Set PHP 8 Version

8. To set the PHP version that will work with the 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.

----------- Disable PHP Version ----------- $ sudo a2dismod php5.6 $ sudo a2dismod php7.0 $ sudo a2dismod php7.1 $ sudo a2dismod php7.2 $ sudo a2dismod php7.3 $ sudo a2dismod php7.4 $ sudo a2dismod php8.0 ----------- Enable PHP Version ----------- $ sudo a2enmod php5.6 $ sudo a2enmod php7.1 $ sudo a2enmod php7.2 $ sudo a2enmod php7.3 $ sudo a2enmod php7.4 $ sudo a2enmod php8.0 ----------- Restart Apache Server ----------- $ sudo systemctl restart apache2

Enable Disable PHP Modules for Apache

9. 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" ------------ For PHP 7.2 ------------ $ sudo update-alternatives --set php /usr/bin/php7.2 $ php -i | grep "Loaded Configuration File" ------------ For PHP 7.3 ------------ $ sudo update-alternatives --set php /usr/bin/php7.3 $ php -i | grep "Loaded Configuration File" ------------ For PHP 7.4 ------------ $ sudo update-alternatives --set php /usr/bin/php7.4 $ php -i | grep "Loaded Configuration File" ------------ For PHP 8.0 ------------ $ sudo update-alternatives --set php /usr/bin/php8.0 $ php -i | grep "Loaded Configuration File"

Find PHP Configuration File

In this article, we showed how to install all the supported versions of PHP in Ubuntu and its derivatives. If you have any queries or thoughts to share, do so via the feedback form below.

Читайте также:  Dns server linux centos

Источник

Linux – How to set default version of PHP in Ubuntu 16.04

It might be possible you have installed multiple version of PHP in you server or system. First you should list all the php version and check which version is set to default. After that set the preferred PHP version.

How to list number of Php version in the system?

To list PHP version use sudo update-alternatives —display php

surya@x:$ sudo update-alternatives --display php php - manual mode link best version is /usr/bin/php7.1 link currently points to /usr/bin/php5.5 link php is /usr/bin/php slave php.1.gz is /usr/share/man/man1/php.1.gz /usr/bin/php5.5 - priority 55 slave php.1.gz: /usr/share/man/man1/php5.5.1.gz /usr/bin/php5.6 - priority 56 slave php.1.gz: /usr/share/man/man1/php5.6.1.gz /usr/bin/php7.0 - priority 70 slave php.1.gz: /usr/share/man/man1/php7.0.1.gz /usr/bin/php7.1 - priority 71 slave php.1.gz: /usr/share/man/man1/php7.1.1.gz

How to check current default Php version in server?

To check current default version use command php -v

surya@x:$ php -v PHP 5.5.38-4+deb.sury.org~xenial+1 (cli) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

How to set default Php version in server?

To set default version of PHP use sudo update-alternatives —config php

surya@x:$ sudo update-alternatives --config php There are 4 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/php7.1 71 auto mode * 1 /usr/bin/php5.5 55 manual mode 2 /usr/bin/php5.6 56 manual mode 3 /usr/bin/php7.0 70 manual mode 4 /usr/bin/php7.1 71 manual mode Press to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/bin/php5.6 to provide /usr/bin/php (php) in manual mode surya@OMDELPDNEOUBU:/etc/nginx/sites-available$ php -v PHP 5.6.31-4+ubuntu16.04.1+deb.sury.org+4 (cli) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

This is how, you can set your preferred version of Php to the system.

Surya

Living in permanent beta mode: Learning, Improving & evolving. SPECIALTIES: Web Application Development, Digital Media, E-Commerce Solutions, SEO, CRM Solutions, Open Source Technologies, System Administration ( Linux ), VOIP Solutions, Cloud Computing, Web Security.

Источник

How to Change Default PHP Version on Ubuntu

On your system, if you have installed multiple versions of PHP like PHP 8.2, PHP 7.4 and PHP 5.6. Currently, PHP 7.4 is the default version set for Apache and the command line interface (CLI). Maybe you have any other PHP versions installed on your system. Only one PHP version can be set as default at any time.

Читайте также:  Linux утилита жесткие диски

This tutorial will help you to change the default PHP version for CLI and Apache webserver. This can be achieved with a few sets of commands.

Switch to PHP 8.2

Before switching to PHP 8.2, you have to deactivate the previously activated Apache module. The following commands will deactivate the already activated Apache module and then activate PHP 8.2 Apache module. Then the next commands will set PHP 8.2 as the default version for the command line interface (CLI).

sudo a2dismod php* sudo a2enmod php8.2 sudo systemctl restart apache2 
sudo update-alternatives --set php /usr/bin/php8.2 sudo update-alternatives --set phar /usr/bin/phar8.2 sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.2 sudo update-alternatives --set phpize /usr/bin/phpize8.2 sudo update-alternatives --set php-config /usr/bin/php-config8.2 

Note: The phpize8.2 and php-config8.2 command is available in php8.2-dev package. This is more useful for compiling PHP modules using pecl.

If you want a different version (eg: PHP 8.1 or PHP 8.0) to be configured as default, just replace 8.2 with the required version.

Switch to PHP 7.4

Similarly, if you need to configure PHP 7.4 as the default version in your system. The following set of commands will change the default PHP to 7.4 for the Apache web server and command line interface.

sudo a2dismod php* sudo a2enmod php7.4 sudo systemctl restart apache2 
sudo update-alternatives --set php /usr/bin/php7.4 sudo update-alternatives --set phar /usr/bin/phar7.4 sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4 sudo update-alternatives --set phpize /usr/bin/phpize7.4 sudo update-alternatives --set php-config /usr/bin/php-config7.4 

Note – The phpize7.4 and php-config7.4 command is available in php7.4-dev package. This is more useful for compiling PHP modules using pecl.

Switch to PHP 5.6

PHP 5.6 is an outdated version. So if you have an application that required PHP 5.6, consider them to upgrade to last PHP version. The following set of commands will change the default PHP to 5.6 for the Apache web server and command line interface.

sudo a2dismod php* sudo a2enmod php5.6 sudo systemctl restart apache2 
sudo update-alternatives --set php /usr/bin/php5.6 sudo update-alternatives --set phar /usr/bin/phar5.6 sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6 sudo update-alternatives --set phpize /usr/bin/phpize5.6 sudo update-alternatives --set php-config /usr/bin/php-config5.6 

Note: The phpize5.6 and php-config5.6 command is available in php5.6-dev package. This is more useful for compiling PHP modules using pecl.

Conclusion

This tutorial helps you to change the default PHP versions on an Ubuntu system. This helps you to change the default PHP version for the Apache web server and the command line interface.

Источник

Оцените статью
Adblock
detector