I have installed php 5.6 and and php7.1 on my ubuntu 16.04
I know with apache as my web server, i can do
a2enmod php5.6 to enable php5
a2enmod php7.1 to enable php7
When i disable php7.1 in apache modules and enable php5.6, apache recognizes the change and uses php5.6 interpreter as expected.
But when i run internal php web server from the commandline :-
php -S localhost:8888
php handles requests using php7 , how do i switch between php6.6 and php7.1 in the commandline ?
Switch from PHP 5.6 to PHP 7.2 using:
Switch from PHP 7.2 to PHP 5.6 using:
type this in your shell
and this is what you will get
Choose the appropriate version
I actually wouldn't recommend using
a2enmod
for php 5 or 7. I would useupdate-alternatives
. You can dosudo update-alternatives --config php
to set which system wide version of PHP you want to use. This makes your command line and apache versions work the same. You can read more aboutupdate-alternatives
on the man page.You could use these open source PHP Switch Scripts, which were designed specifically for use in Ubuntu 16.04 LTS.
https://github.com/rapidwebltd/php-switch-scripts
There is a
setup.sh
script which installs all required dependencies for PHP 5.6, 7.0, 7.1 & 7.2. Once this is complete, you can just run one of the following switch scripts to change the PHP CLI and Apache 2 module version.When installing laravel on Ubuntu 18.04, be default PHP 7.3.0RC3 install selected, but laravel and symfony will not install properly complaining about missin php-xml and php-zip, even though they are installed. You need to switch to php 7.1, using the instructions above or,
now, running laravel new blog, will proceed correctly
You can create a script to switch from versions:
sudo nano switch_php
then type this:exit and save make it executable:
sudo chmod +x switch_php
To execute the script just type
./switch_php [VERSION_NUMBER]
where the parameter is 7 or 5.6That's it you can now easily switch form PHP7 to PHP 5.6!