9

I have PHP 7.0 and 7.2 installed.

For now, I use PHP 7.0.

How can I switch to PHP 7.2?

0

3 Answers 3

23

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.

1
  • If it is helpful then accept answer. Apr 29, 2019 at 13:52
8

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

1
  • 1
    This is a critical step for nginx users. I was facing difficulty after switching version of PHP, restarting the php driver and nginx server, but the site would still not load. It wasn't until I saw this answer that I remembered I have the php version specified in the configuration file. Thanks!
    – Andrew Fox
    Feb 28, 2021 at 0:39
1
sudo a2dismod php7.0
sudo a2enmod php7.2
sudo systemctl restart apache2

Reference: Link

1
  • 1
    Didn't OP ask about Nginx, not Apache?
    – Klesun
    Feb 29, 2020 at 16:23

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