- How to Switch between Multiple PHP Version on Ubuntu
- Switch From PHP 5.6 => PHP 7.4
- Switch From PHP 7.4 => PHP 5.6
- Conclusion
- How to Install Different PHP (5.6, 7.x and 8.0) Versions in Ubuntu
- Install PHP (5.6, 7.x, 8.0) on Ubuntu Using PPA
- For Apache Web Server
- For Nginx Web Server
- Set Default PHP Version in Ubuntu
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- Жонглируем версиями PHP в системе
- How to Switch between Multiple PHP Version on Debian 9
- Enable PHP 7.2 as Default
- Enable PHP 5.6 as Default
- How To Switch Between Multiple PHP Versions In Ubuntu
- Introduction
- 1. Switch Between Multiple PHP Versions
- 1.1. Switch from PHP 7.x to PHP 5.x
- 2. Switch from PHP 5.x to PHP 7.x
How to Switch between Multiple PHP Version on Ubuntu
On your system, if you have installed multiple versions of PHP (eg PHP 7.4 and PHP 5.6 both). PHP 7.4 is running as default PHP for Apache and CLI. For any requirement, you need to use PHP 5.6. Then you don’t need to remove PHP 7.4. You can simply switch your PHP version to default used for Apache and command line.
For example, your server has PHP 7.4 and PHP 5.6 both version’s installed. Now following example will help you to switch between both versions. The PHP 5.6 is configured as default PHP version for Apache and CLI. Let’s make PHP 7.4 as default PHP for Apache server and CLI.
Switch From PHP 5.6 => PHP 7.4
The PHP 5.6 is set as default version in your system, and you need to switch to PHP 7.4. Run the following commands to switch for Apache and command line.
Apache:-
Command Line:-
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 From PHP 7.4 => PHP 5.6
Default PHP 7.4 is set on your system and you need to switch to PHP 5.6. Now run the following commands to switch for Apache and command line.
Apache:-
Command Line:-
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 switch between multiple PHP versions on Ubuntu system. This helps you to change default PHP version on your Apache server and command line interface.
Источник
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.
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.
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
For Nginx Web Server
4. To install any PHP modules, simply specify the PHP version and use the auto-completion functionality to view all modules as follows.
Search PHP Modules
5. Now you can install most required PHP modules from the list.
6. Finally, verify your default PHP version used on your system like this.
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 PHP 5.6 Version in Ubuntu
Set PHP 7.0 Version in Ubuntu
Set PHP 7.1 Version in Ubuntu
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.
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.
Find PHP Configuration File
You may also like:
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.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
Жонглируем версиями PHP в системе
Проблема “ хочу новую версию %software% на моем стареньк … стабильном Debian/CentOS…” так же стара, как *nix-мир. Способов добиться желаемого хватает. Есть масса решений как притащить в систему несколько версий одного и того же софта. Но дальше хочется не просто иметь ещё одну версию, но и управлять тем, какая из версий доступна в системе по умолчанию, для конкретных приложений или пользователей.
Что делать, если хочется сменить системную версию PHP на одну из кастомных сборок? Давайте отталкиваться от того, что у вас на сервере уже установлено несколько версий PHP и вы хотите, чтобы в консоли команда php была конкретной версии, отличающаяся от той, что шла с системой. В этой статье я расскажу, как правильно это настроить, чтобы не было проблем с будущими пакетными обновлениями.
В качестве примера возьмём сервер на CentOS 7, где установлен родной PHP:
Также на сервере установлен наш Plesk с парой своих сборок PHP:
Допустим, мы хотим переключить систему на использование PHP 5.6 по умолчанию (переключать глобально PHP с версии 5.4 на 7 как-то сс… страшно — чему-то в системе может поплохеть от такого). Бинарь PHP 5.6 лежит у нас тут:
Как же сделать так, чтобы система использовала эту, нужную нам, версию PHP?
Сначала посмотрим на системную переменную PATH
В ней перечислен список директорий, в которых ищутся программы по имени. Главный нюанс — поиск в директориях происходит последовательно и используется первый найденный результат. Текущий путь до текущего бинарника PHP мы можем увидеть с помощью команды:
Как видно из PATH , /usr/local/bin находится в списке раньше, чем /usr/bin . Значит, если мы поместим ссылку на альтернативную версию PHP “пораньше”, в /usr/local/bin , то именно она и будет использоваться при вызове команды php вместо /usr/bin/php . Мы можем создать эту ссылку руками (и всё даже будет работать), но правильнее использовать специально созданную для этих целей утилиту update-alternatives (в CentOS это просто alternatives , но есть симлинка update-alternatives , поэтому дальше будем оперировать именно этой командой, как универсальной для Debian/Ubuntu/CentOS/и т.д.).
Теперь, давайте зарегистрируем все доступные версии PHP с помощью этой команды:
Цифры 10, 20 и 30 — это приоритет. Он работает для автоматического выбора, если администратор сам не выбрал конкретную версию. Самое большое число определяет выбор «по умолчанию».
Проверим, что php теперь указывает на созданную командой симлинку:
Давайте разберемся, что же update-alternatives сделала для нас:
Как видно, она создала цепочку симлинок и теперь по требованию просто меняет промежуточную симлинку на нужный нам бинарь.
То есть, мы успешно настроили группу PHP в update-alternatives , где по умолчанию в автоматическом режиме выбран системный PHP. Сейчас у нас есть возможность переключить команду PHP на любую другую версию..
Давайте переключимся на PHP версии 5.6, которая идет в поставке с Plesk’ом:
Проверяем, что переключение произошло:
Все отлично работает. Теперь в системе используется нужная нам версия PHP и я не опасаюсь, что эта настройка слетит при следующих пакетных обновлениях.
С помощью update-alternatives можно выбирать не только версию PHP, но и многие другие вещи, например разные версии phpunit или редактор по умолчанию в системе. Подход этот универсален для различных систем. Не изобретая своего велосипеда, используя существующие инструменты, вы можете быть уверенным, что не устроили для ваших коллег квеста “Ну почему оно так работает?!”. Настраивайте свою систему правильно.
Источник
How to Switch between Multiple PHP Version on Debian 9
On your system, if you have installed multiple versions of PHP (eg PHP 7.2, 7.1 and 5.6). PHP 7.2 is running as default PHP for Apache and CLI. For any requirement, you need to use PHP 5.6. Then you don’t need to remove PHP 7.2. You can simply switch your PHP version to default used for Apache and command line.
We assume you have installed multiple PHP version on your Debian system. Now you need to switch the active PHP version for CLI and Apache2. This tutorial will help you to switch between multiple PHP versions for Apache server and CLI on Debian.
Here are two examples for PHP 7.2 and PHP 5.6. You can use the same for other PHP versions by changes commands accordingly.
Enable PHP 7.2 as Default
You need to set PHP 7.2 as your active PHP version for CLI and Apache2 both. You can do this by disabling Apache2 modules for all other installed PHP versions and configure CLI using the update-alternatives command. Run the following commands to make changes.
Apache:-
Command Line:-
Note – The phpize7.2 and php-config7.2 command is available in php7.2-dev package. This is more useful for compiling PHP modules using pecl.
Enable PHP 5.6 as Default
You need to set PHP 5.6 as your default version for CLI and Apache2 both. Run the following commands to disable other PHP versions like (php7.2, php7.1, or php7.0 etc) for Apache and command line.
Apache:-
Command Line:-
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.
Источник
How To Switch Between Multiple PHP Versions In Ubuntu
This brief tutorial walks you through the steps to switch between multiple PHP versions in Ubuntu Linux and its derivatives. This guide is officially tested on Ubuntu 18.04 LTS server edition. It may work on other older or newer Ubuntu versions as well.
Introduction
Sometimes, the most recent version of an installed package might not work as you expected. Your application may not compatible with the updated package and support only a specific old version of package.
In such cases, you can simply downgrade the problematic package to its earlier working version in no time. Refer our old guides on how to downgrade a package in Ubuntu and its variants here and how to downgrade a package in Arch Linux and its derivatives here.
In some situations, you need not to downgrade the problematic packages. In Linux, we can use multiple versions of the same package at the same time, side by side.
For instance, let us say you are testing a PHP application in LAMP stack deployed in Ubuntu 18.04 LTS. After a while you find out that the application worked fine in PHP 5.6, but not in PHP 7.2 (Ubuntu 18.04 LTS installs PHP 7.x by default).
Are you going to reinstall PHP or the whole LAMP stack again? Not necessary.
You don’t even have to downgrade the PHP to its earlier version. You can simply switch to the previous working PHP version in couple minutes.
1. Switch Between Multiple PHP Versions
Let us check the default installed version of PHP using command:
Sample output:
As you can see, the installed version of PHP is 7.2.7.
After testing your application for couple days, you find out that your application doesn’t support PHP 7.2. In that case, it is a good idea to have both PHP 5.x version and PHP 7.x version, so that you can easily switch between any supported version at any time.
You don’t need to remove PHP 7.x or reinstall LAMP stack. You can use both PHP 5.x and 7.x versions together.
I assume you didn’t uninstall php 5.6 in your system yet. Just in case, you removed it already, you can install it again using a PPA like below.
You can install PHP 5.6 from a PPA:
1.1. Switch from PHP 7.x to PHP 5.x
1.1.1 First disable PHP 7.2 module using command:
Sample output:
1.1.2. Next, enable PHP 5.6 module:
1.1.3 Set PHP 5.6 as default version using command:
1.1.4. Alternatively, you can run the following command to set which system wide version of PHP you want to use by default.
1.1.5. Enter the selection number to set it as default version or simply press ENTER to keep the current choice.
1.1.6. If you have installed other PHP extensions, set them as default as well.
1.1.7. Finally, restart your Apache web server:
Now, check if PHP 5.6 is the default version or not:
Sample output:
2. Switch from PHP 5.x to PHP 7.x
Likewise, you can switch from PHP 5.x to PHP 7.x version by running the following commands one after another.
A word of caution:
The final stable PHP 5.6 version has reached the end of active support as of 19 Jan 2017. However, PHP 5.6 will continue to receive support for critical security issues until 31 Dec 2018. So, It is recommended to upgrade all your PHP applications to be compatible with PHP 7 .x as soon as possible.
If you want prevent PHP to be automatically upgraded in future, refer the following guide.
Источник