How to update Apache's PHP?

ncux picture ncux · Feb 14, 2018 · Viewed 8k times · Source

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?

Answer

Mohammad Zare Moghadam picture Mohammad Zare Moghadam · Feb 14, 2018

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";