How To Switch Between Php Versions On An Ubuntu 18

a2engian lận php5.6 #to lớn enable php5a2engian lận php7.1 #khổng lồ enable php7When I disable php7.1 in Apabít modules và enable php 5.6, Apache recognizes the change và uses php 5.6 interpreter as expected.

Bạn đang xem: How to switch between php versions on an ubuntu 18

But when I run internal php website server from the commandline:

php -S localhost:8888php handles requests using php 7. So how bởi vì I switch between php 5.6 and php 7.1 in the command line ?


*

*

Interactive switching mode

subởi vì update-alternatives --config phpsuvị update-alternatives --config pharsuvị update-alternatives --config phar.phar

Manual Switching

From PHP 5.6 => PHPhường 7.1

Default PHP 5.6 is mix on your system và you need lớn switch khổng lồ PHPhường 7.1.

Apache:

$ suvì chưng a2dismod php5.6$ subởi a2engian lận php7.1$ suvì chưng service apache2 restartCommand Line:

$ subởi update-alternatives --phối php /usr/bin/php7.1$ subởi vì update-alternatives --mix phar /usr/bin/phar7.1$ sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1

From PHPhường 7.1 => PHP.. 5.6

Default PHPhường 7.1 is set on your system & you need lớn switch lớn PHPhường. 5.6.

Apache:

$ subởi vì a2dishack php7.1$ suvì a2enthủ thuật php5.6$ suvì service apache2 restartCommand Line:

$ subởi vì update-alternatives --mix php /usr/bin/php5.6Source


Share
Improve sầu this answer
Follow
edited Jan 21 at 12:49
*

PiTheNumber
20k1313 gold badges9696 silver badges165165 bronze badges
answered Mar 6 "17 at 7:03
*

Stevie GStevie G
3,30811 gold badge88 silver badges1515 bronze badges
7
| Show 2 more comments
154
type this in your commvà line, should work for all ubuntu between 16.04, 18.04 and đôi mươi.04.

Xem thêm: php oop nang cao

$ sudo update-alternatives --config phpand this is what you will get

There are 4 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status------------------------------------------------------------* 0 /usr/bin/php7.2 72 tự động mode 1 /usr/bin/php5.6 56 manual mode 2 /usr/bin/php7.0 70 manual mode 3 /usr/bin/php7.1 71 manual mode 4 /usr/bin/php7.2 72 manual modePress to lớn keep the current choice<*>, or type selection number:Choose the appropriate version


Share
Improve sầu this answer
Follow
edited Jul 13 "20 at 6:19
answered Jan 19 "18 at 8:28
*

GiorgosKGiorgosK
4,16922 gold badges2222 silver badges2121 bronze badges
5
Add a bình luận |
16
To các mục all available versions & choose from them :

suvị update-alternatives --config phpOr bởi vì manually

sudo a2disgian lận php7.1 // disablesuvì a2enthủ thuật php5.6 // enable
Share
Improve sầu this answer
Follow
answered May 30 "18 at 11:25
Kamal KumarKamal Kumar
2,41511 gold badge1616 silver badges1515 bronze badges
0
Add a bình luận |
15
I actually wouldn"t recommkết thúc using a2engian lận for php 5 or 7. I would use update-alternatives. You can do suvì chưng update-alternatives --config php to lớn set which system wide version of PHP you want lớn use. This makes your command line & apache versions work the same. You can read more about update-alternatives on the man page.


Share
Improve sầu this answer
Follow
answered Mar 6 "17 at 7:02
FatBoyXPCFatBoyXPC
72344 silver badges1414 bronze badges
1
Add a phản hồi |
13
I think you should try this

From php5.6 lớn php7.1

suvì chưng a2dismod php5.6sudo a2enthủ thuật php7.1suvì service apache2 restartsuvị update-alternatives --mix php /usr/bin/php7.1subởi update-alternatives --phối phar /usr/bin/phar7.1subởi update-alternatives --mix phar.phar /usr/bin/phar.phar7.1From php7.1 khổng lồ php5.6

suvì chưng a2dismod php7.1subởi a2engian lận php5.6suvì chưng service apache2 restartsuvày update-alternatives --phối php /usr/bin/php5.6suvị update-alternatives --mix phar /usr/bin/phar5.6suvày update-alternatives --mix phar.phar /usr/bin/phar.phar5.6
Share
Improve this answer
Follow
edited Sep 26 "17 at 5:14
answered Sep 19 "17 at 9:38
Rupinder SohalRupinder Sohal
13111 silver badge33 bronze badges
1
Add a comment |
10
You can create a script lớn switch from versions: subởi nano switch_phpthen type this:

#!/bin/sh#!/bin/bashemang đến "Switching lớn PHP$1..."case $1 in "7") subởi a2dismod php5.6 subởi vì a2enthủ thuật php7.0 sudo service apache2 restart suvì ln -sfn /usr/bin/php7.0 /etc/alternatives/php;; "5.6") suvị a2disgian lận php7.0 suvày a2enthủ thuật php5.6 subởi vì service apache2 restart suvì chưng ln -sfn /usr/bin/php5.6 /etc/alternatives/php;;esacemang đến "Current version: $( php -v | head -n 1 | cut -c-7 )"exit and savemake it executable: suvì chưng chgian lận +x switch_php

To exedễ thương the script just type ./switch_php where the parameter is 7 or 5.6

That"s it you can now easily switch form PHP7 to PHP 5.6!


Share
Improve sầu this answer
Follow
edited Aug 26 "18 at 0:58
chepe263
2,5261919 silver badges3737 bronze badges
answered Jul 22 "17 at 18:38
ihakozihakoz
10111 silver badge33 bronze badges
2
Add a comment |
8
You can use below command lines to lớn switch between two PHP. version.

E.g.

I want khổng lồ switch PHP. Version from 7.1 to 7.2 we can use below command

subởi a2dismod php7.1 && suvì chưng update-alternatives --set php /usr/bin/php7.2 &và suvày a2enhack php7.2 &và sudo service apache2 restarta2disgian lận is use to lớn disable the current php version and a2engian lận is use lớn enable the version


Share
Improve this answer
Follow
edited Mar 4 "19 at 6:49
answered Feb 14 "19 at 5:12
Ashish ViradiyaAshish Viradiya
36966 silver badges1515 bronze badges
Add a comment |
8
May be you might have sầu an old PHPhường version lượt thích PHPhường 5.6 in your system and you installed PHPhường 7.2 too so thats multiple PHP. in your machine. There are some applications which were developed when older PHP 5.6 was latest version, they are still live sầu & you working on those applications, You might be working on Laravel simultaneously but Laravel requires PHPhường 7+ to lớn get started. Getting the picture ?

In that case you can switch between the PHP.. versions lớn suit your requirements.

Switch From PHPhường 5.6 => PHPhường 7.2

Apache:-

suvì chưng a2dismod php5.6subởi vì a2enmod php7.2subởi vì service apache2 restartCommand Line:-

suvị update-alternatives --set php /usr/bin/php7.2subởi update-alternatives --phối phar /usr/bin/phar7.2subởi vì update-alternatives --mix phar.phar /usr/bin/phar.phar7.2subởi vì update-alternatives --mix phpize /usr/bin/phpize7.2suvị update-alternatives --phối php-config /usr/bin/php-config7.2And vice-versa, Switch From PHPhường 7.2 => PHPhường 5.6

Apache:-

sudo a2disgian lận php7.2sudo a2engian lận php5.6suvì service apache2 restartComm& Line:-

subởi vì update-alternatives --mix php /usr/bin/php5.6subởi vì update-alternatives --mix phar /usr/bin/phar5.6suvì chưng update-alternatives --phối phar.phar /usr/bin/phar.phar5.6suvày update-alternatives --set phpize /usr/bin/phpize5.6subởi vì update-alternatives --phối php-config /usr/bin/php-config5.6