Upgrade php to v 7.2 version on ubuntu 16.04 - php

I want to upgrade my apache php version on ubuntu 16.04. Right now phpinfo() shows 7.0.26. How can I upgrade?
I want to upgrade to phpversion 7.2. sudo apt install php7.2, doesn't update the apache php version. How can I update the apache php version.

I'm assuming that you already have apache and php 7.0 installed, and that you're using the Ondřej Surý PPA something like this:
LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.2
At this point, you would need to remove the old libapache2-mod-php package, install the new one, and restart apache:
sudo apt remove libapache2-mod-php*
sudo apt update
sudo apt install libapache2-mod-php7.2
sudo service apache2 restart
Now, phpinfo() from within a web page should show PHP Version 7.2.0-2+ubuntu16.04.1+deb.sury.org+2
If the add-apt-repository command is missing, you can install it with:
sudo apt install software-properties-common

Please run below commands to upgrade your PHP version to 7.2
sudo apt-get update
sudo apt-get install python-software-properties
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get install php7.2
sudo a2dismod php7.0
sudo a2enmod php7.2
sudo update-alternatives --set php /usr/bin/php7.2
sudo service apache2 restart
sudo apt-get install libapache2-mod-php7.2 php7.2-cgi php7.2-cli php7.2-common php7.2-curl php7.2-gd php7.2-imap php7.2-intl php7.2-json php7.2-ldap php7.2-mbstring php7.2-mysql php7.2-opcache php7.2-pspell php7.2-readline php7.2-soap php7.2-xml
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.2-fpm
sudo service apache2 restart
Hope this helps !!!

In this way, simply run following order for update php rendition.
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt install php7.3

Related

Apache Downloading Laravel index.php After PHP7 to PHP7.4 Update

I installed php7.4 (previously running 7.0.33) on my server and now every time I try to visit my website, it just downloads the laravel index.php file instead of displaying it.
I understand that this means something is not configured correctly with apache (I don't have Nginx), but I can't figure out what! I've been looking for hours!
This is what I did to install (based on this guide https://www.cloudbooklet.com/upgrade-php-version-to-php-7-4-on-ubuntu/)...
sudo apt-get update && apt-get upgrade
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.4
sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y
sudo apt install php7.4-fpm //(I don't think this was needed)
sudo a2dismod php7.0
sudo a2enmod php7.4
sudo service apache2 restart
I am able to make my website work again by doing this... (but the PHP version reverts back to 7.0 of course)
sudo a2dismod php7.4
sudo a2enmod php7.0
sudo service apache2 restart

How can I downgrade or use PHP 7.2 without uninstalling PHP 7.4? Is it possible to use PHP 7.2 as default instead of the latest version?

I am using linux Ubuntu 18.04
And I wanna revert back to the previous version of PHP.
I've seen tutorials that requires me to uninstall the latest version, now I am asking if there is a workaround in this problem such that I can easily switch from using 7.2 or 7.4.
I have faced the same problem and Here is the solution:
sudo update-alternatives --config php
Now select which version U want on right now, thanks
Yes, you can.
1- To stop running PHP 7.4, run the commands below to disable it for Apache2:
sudo a2dismod php7.4
2- Then run the commands below to enable PHP 7.2 for Apache2 to use:
sudo a2enmod php7.2
3- Restart Apache2 for the changes to apply by running the commands below:
sudo systemctl restart apache2.service
Downgrade from 7.4 to 7.2
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2
sudo apt-get install php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-mysql php7.2-mbstring php7.2-zip php7.2-fpm php7.2-intl php7.2-simplexml
sudo a2dismod php7.4
sudo a2enmod php7.2
sudo service apache2 restart
sudo update-alternatives --set php /usr/bin/php7.2
sudo update-alternatives --set phar /usr/bin/phar7.2
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2
sudo update-alternatives --set phpize /usr/bin/phpize7.2
sudo update-alternatives --set php-config /usr/bin/php-config7.2
You can install multiple php version in ubuntu and can disable the version you don't need e.g:
sudo a2dismod php7.4
sudo a2enmod php7.2
If you nginx user. first install php 7.4 all necessary item.
sudo apt-get update
sudo apt -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.4-cli php7.4-json php7.4-common php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath php7.4-fpm -y
systemctl status php7.2-fpm.service #get previous version id
kill -9 873 #id will be replace with your php.7.2-fpm
service php7.4-fpm restart
systemctl status php7.4-fpm.service #check php status
Done, All okay
We downgrade or upgrade the PHP version using the following steps.
Let me show how to downgrade (from 7.2 >> 7.0 )
step1: sudo a2dismod php7.2
step2: sudo a2enmod php7.0
step3: sudo systemctl restart apache2
step4: sudo update-alternatives --set php /usr/bin/php7.0
That's it, version changed to 7.2 as you can see below.

Can't reinstall php7.3 on debian

For some reason, my php cli switched to 5.6.40 instead of the 7.2 version that I had before. Then I was unable to restart apache2, so I tried to apt purge php7 & php5 to reinstall them.
But now, I only have this error:
(sorry for the French, it says packages have unsatisfied dependencies). How can I clean it ?
I have already tried the following commands :
apt-get -f install
apt-get clean
apt-get update
apt-get upgrade
You have to purge comlete php7.3:
sudo apt-get remove -y --purge php7.3*
add repository (if not exist):
sudo add-apt-repository ppa:ondrej/php
install dependents
sudo apt install php libapache2-mod-php
if you have apache:
sudo systemctl restart apache2
if you have nginx:
sudo service nginx restart
install php:
sudo apt install php-fpm
check php:
sudo service php7.3-fpm status

How to update Apache's PHP?

I installed Laravel 5.6, but it's not working because it requires PHP 7.2.
I use Ubuntu 17, and installed Apache 2 and PHP 7.2 (7.1, 7.0) but when I use phpinfo() it shows php7.0.
So how can I config Apache and set php7.2 instead of php7.0?
At first you have to install php7.2 with the following commands
sudo apt install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install -y php7.2
sudo apt install libapache2-mod-php7.2 php7.2-cli php7.2-curl php7.2-intl php7.2-mysql php7.2-opcache php7.2-json php7.2-bz2 php7.2-mcrypt php7.2-xmlrpc php7.2-mbstring php7.2-soap php7.2-xml php7.2-zip
After installing php you have to run the following commands:
sudo update-alternatives --set php "/usr/bin/php7.2";
sudo update-alternatives --set "php-config" "/usr/bin/php-config7.2";
sudo a2dismod "php7.0"
sudo a2dismod "php5.6"
sudo a2enmod "php7.2"
sudo service apache2 restart
If you installed php7.2-dev then you should run the following command too:
sudo update-alternatives --set "phpize" "/usr/bin/phpize7.2";
Run the following commands to have PHP 7.2 installed
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2-cli
After that, you can run the command below to see the installed version of PHP:
php -v

how to install php 5.4 with ubuntu 16??

I have install LAMP stack on ubuntu 16, I got php 7.
I want to downgrade it to php 5.4 . what command should I use to remove php 7 and install php 5.4 in my ubuntu 16?
try this
sudo apt-get purge php*
then
sudo apt-get install php5.4 php5.4-gettext php5.4-common
First, remove LAMP from your Ubuntu.
Then, use the following:
sudo apt-get update
sudo apt-get install apache2 php5 mysql-server mysql-client php5-mysql //install php 5.3
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get remove php5 //remove php 5.3
sudo apt-get update
sudo apt-get install php5 //install php 5.4
First you must install PHP 5.4 (if you have not already done so):
sudo apt-get install php5-fpm php5-mysql
And then:
Apache:
sudo a2dismod php7.0 ; sudo a2enmod php5.4 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php5.4

Categories