UPDATE, INSTALL, AND SWITCH BETWEEN DIFFERENT PHP VERSIONS
If you want to update your PHP version, or just get a different one, you can proceed with the corresponding PHP steps in the following link: http://www.offset101.com/2017/04/18/setup-lamp-server-scratch/
If you want to remove a previous installed or a useless PHP you should do the following:
1 |
sudo apt-get remove --auto-remove php7.0 php5.6 php7.1 php5.5 php5 |
Once you have updated your PHP, you should be aware that you will have a php.ini per cli and apache2 (just in case you needed to add remove or change an extension):
apache2: The fastest way to get it, is adding a phpinfo();die(); withing your code, and find the “Loaded Configuration File” row (this should be under /etc/php/7.0/apache2/php.ini)
cli: The fastest way to get it, is doing a php –ini, and before all the installed packages, you will see the “Loaded Configuration File” row for cli (which should be under /etc/php/7.0/cli/php.ini)
Switch version from PHP 5.6 to PHP 7.0:
- Apache:
1sudo a2dismod php5.6 && sudo a2enmod php7.0 && sudo service apache2 restart - CLI:
1sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php
Switch version from PHP 7.0 to PHP 5.6:
- Apache:
1sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart - CLI:
1sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php
If you don’t want to change between versions, you can create an alias inside your /home/user/.bashrc file to use (for example) the php7, to do so, you can add the following line:
1 |
alias php7="/usr/bin/php7.0" |
and you will be able to do “php7 <file>” using php7.