How to Switch WordPress from PHP 7.2-FPM to PHP 7.3-FPM on Ubuntu 19.10 with Nginx

Here is you will learn how to switch WordPress from PHP 7.2-FPM to PHP 7.3-FPM on Ubuntu 19.10. In particular on Vultr‘s instance i.e. Ubuntu 19.10.

WordPress 5.* and up comes with PHP 7.3-FPM support. If you’re running older versions of PHP-FPM, you can use the following steps to switch WordPress from PHP 7.2-FPM to PHP 7.3-FPM on Ubuntu 19.10 with Nginx HTTP server running WordPress.

Some themes and plugins are still not compatible with PHP 7.3-FPM so before to upgrade please make sure that your theme & plugins are compatible with PHP 7.3FPM.

Switch PHP 7.2-FPM to PHP 7.3-FPM with Nginx on Ubuntu

Run the following commands before to install PHP 7.3-FPM packages

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Now install PHP 7.3-FPM on Ubuntu & most commonly used PHP extensions using the following command:

sudo apt install php7.3-fpm php7.3-common php7.3-zip php7.3-curl php7.3-xml php7.3-xmlrpc php7.3-json php7.3-mysql php7.3-pdo php7.3-gd php7.3-imagick php7.3-ldap php7.3-imap php7.3-mbstring php7.3-intl php7.3-cli php7.3-recode php7.3-tidy php7.3-bcmath php7.3-opcache

Check the PHP installation

You can use php -v command to check the PHP version installed on your server and output will be

PHP 7.3.11-1+ubuntu19.10.1+deb.sury.org+6 (cli) (built: Oct 28 2019 21:34:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.11-1+ubuntu19.10.1+deb.sury.org+6, Copyright (c) 1999-2018, by Zend Technologies

You can also confirm installed version of any PHP extension using apt policy command i.e. apt policy php7.3-cli and output will be

php7.3-cli:
  Installed: 7.3.11-1+ubuntu19.10.1+deb.sury.org+6
  Candidate: 7.3.11-1+ubuntu19.10.1+deb.sury.org+6
  Version table:
 *** 7.3.11-1+ubuntu19.10.1+deb.sury.org+6 500
        500 http://ppa.launchpad.net/ondrej/php/ubuntu eoan/main amd64 Packages
        100 /var/lib/dpkg/status
     7.3.11-0ubuntu0.19.10.1 500
        500 http://archive.ubuntu.com/ubuntu eoan-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu eoan-security/main amd64 Packages
     7.3.8-1 500
        500 http://archive.ubuntu.com/ubuntu eoan/main amd64 Packages

Now, PHP 7.3-FPM has been installed on your Ubuntu. The default Nginx PHP-FPM configuration file is at /etc/php/7.3/fpm/php.ini and if we want to modify the default PHP configuration, open file for Nginx using the following command:

sudo nano /etc/php/7.3/fpm/php.ini

Configure PHP 7.3-FPM for Nginx

Make the changes on the following below lines in the file and save. The value below is great settings to apply in your environments.

max_execution_time = 180
max_input_time = 120
max_input_vars = 5000
memory_limit = 256M
cgi.fix_pathinfo = 0
file_uploads = On
upload_max_filesize = 100M
allow_url_fopen = On
date.timezone = Asia/Karachi

After making the change above, save the file and close out.

Restart Nginx And PHP-FPM

After installing PHP and related modules, all you have to do is restart Nginx to reload PHP configurations.

To restart Nginx and PHP-FPM, run the commands below

sudo systemctl restart nginx.service
sudo systemctl restart php7.3-fpm.service

Now you are having PHP-FPM 7.3 Installed and configured.

Open the Nginx site configuration and configure the PHP block to use PHP 7.3-FPM

sudo nano /etc/nginx/sites-available/yourprojectname

Then modify the PHP block session from fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; to fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; i.e.

location ~ \.php$ {
     include snippets/fastcgi-php.conf;
     fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     include fastcgi_params;
}

After that, restart Nginx HTTP server to use PHP 7.3-FPM.

sudo systemctl restart nginx.service

Finally, run the following command to remove all PHP 7.2 packages.

sudo apt-get purge `dpkg -l | grep php7.2| awk '{print $2}' |tr "\n" " "`

Once you will run the above command, It will prompt you to accept the changes to your system. Type ‘Y’ to continue; when you’re done, PHP 7.3-FPM should be enabled and PHP 7.2-FPM completely removed from Ubuntu.

Related Post

How To Set Up Apache2 Virtual Hosts on Ubuntu

Here is how you can set up Apache2 Virtual Hosts on Ubuntu. In particular on Vultr’s instance i.e. Ubuntu 16.04 LTS / 18.04 LTS / 18.10. Apache2 Virtual Hosts can run more than one website…

How to Install WordPress on Ubuntu with Nginx, MariaDB and PHP-FPM

Here is how you can install WordPress on Ubuntu with Nginx, MariaDB and PHP-FPM. In particular on Vultr’s instance i.e. Ubuntu 19.10.

Leave a Reply