I have PHP 7.0 and 7.2 installed.

For now, I use PHP 7.0.

How can I switch to PHP 7.2?


Please use to below command

sudo update-alternatives --config php

After run above command select the PHP version that you need to use.

Press to keep the current choice[*], or type selection number: For example 2

After switching below command used to restart the PHP and Nginx server.

sudo service nginx restart
sudo service php7.1-fpm or php7.2-fpm  restart

Please try above code. If you have any help let me know.

  • If it is helpful then accept answer. – Kamlesh Solanki Apr 29 '19 at 13:52

For Nginx, we simply need to update the PHP-FPM socket in its configuration file. But before that make sure that the PHP-FPM is installed for your version and is running as a service.

Take a backup of the default configuration file and then open it up in your favourite text editor.

$ cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
$ sudo vim /etc/nginx/sites-available/default

Change the FastCGI backend to use the new PHP-FPM socket, save and exit the file

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;

Run the configuration test

$ nginx -t

Restart the web server

$ sudo service nginx restart

For more information visit here

sudo a2dismod php7.0
sudo a2enmod php7.2
sudo systemctl restart apache2

Reference: Link

Not the answer you're looking for? Browse other questions tagged or ask your own question.