Upgrade PHP-FPM for WordPress on Ubuntu

This article outlines the process for upgrading PHP-FPM on Ubuntu to ensure compatibility with WordPress 5.0 and later. Users must check theme and plugin compatibility, follow installation commands for PHP 7.2 or 7.3, update PHP configuration, adjust Nginx settings, and remove older PHP versions for optimal performance and security.

This article provides instructions on how to upgrade PHP-FPM to ensure compatibility with WordPress on Ubuntu Linux.

WordPress version 5.0 and later includes support for PHP 7.3-FPM. If you are using an older version of PHP-FPM, follow the steps below to upgrade to PHP 7.3-FPM while running the WordPress CMS with an Nginx HTTP server.

WordPress 5.0.1 is compatible with PHP 7.3-FPM; however, some themes and plugins may not be. It’s advisable to verify that your themes and installed plugins support the latest PHP version to avoid potential issues.

If you have confirmed that all your plugins and themes are compatible with PHP 7.3-FPM, proceed below to learn how to upgrade your PHP-FPM versions to support the latest WordPress version.

If you haven’t installed WordPress, search our website to learn how to install it on Ubuntu.

Upgrade PHP 7.1-FPM to PHP 7.2-FPM with Nginx on Ubuntu

If you are running PHP 7.1-FPM with Nginx on Ubuntu for WordPress, follow the steps below to upgrade to PHP 7.2-FPM.

First, run the commands below to install PHP 7.2-FPM packages

On some Ubuntu systems, PHP 7.2-FPM may not be found in the default repositories. To run PHP 7.2-FPM on Ubuntu 16.04 and earlier versions, you might need to execute the following commands:

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

Then update and upgrade to PHP 7.2-FPM

sudo apt update

Next, run the commands below to install PHP 7.2-FPM and related modules.

sudo apt install php7.2-fpm php7.2-common php7.2-mysql php7.2-gmp php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-gd php7.2-xml php7.2-cli php7.2-zip

After installing PHP 7.2-FPM, execute the commands below to access the default PHP configuration file for Nginx.

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

The following lines are suitable for most PHP-based CMS. Update the configuration file with these changes and save it.

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Whenever you change the PHP configuration file, you should restart the Nginx web server and PHP script… To do so, run the commands below:

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

Next, execute the commands below to enable PHP 7.2 support for Nginx. Then, open the Nginx site configuration file and set the PHP block to use PHP 7.2-FPM.

The Ubuntu default site configuration file can be found at

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

Then edit the PHP block session:

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

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

sudo systemctl restart nginx.service

Finally, run the commands below to remove all PHP 7.1-FPM packages.

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

To proceed, you must accept the changes to your system. Then, type Y to continue. After this, PHP 7.2-FPM will be enabled, and PHP 7.1-FPM will be completely removed from Ubuntu.

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

Skip the previous steps if you are using PHP 7.2-FPM and wish to upgrade to PHP 7.3-FPM. First, execute the commands below to install the PHP 7.3-FPM packages.

On some Ubuntu systems, PHP 7.3-FPM may not be available in Ubuntu default repositories… To run PHP 7.3-FPM on Ubuntu, you may need to run the commands below:

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

Then update and upgrade to PHP 7.3-FPM

sudo apt update

Next, run the commands below to install PHP 7.2-FPM and related modules.

sudo apt install php7.3-fpm php7.3-common php7.3-mysql php7.3-gmp php7.3-curl php7.3-intl php7.3-mbstring php7.3-xmlrpc php7.3-gd php7.3-xml php7.3-cli php7.3-zip

After installing PHP 7.3-FPM, run the commands below to open the PHP default configuration file for Nginx…

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

The lines below are a good setting for most PHP-based CMS… Update the configuration file with these and save….

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Whenever you change the PHP configuration file, you should restart the Nginx web server… To do so, run the commands below:

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

Next, execute the commands below to enable PHP 7.3-FPM support for Nginx. After that, open the Nginx site configuration and set up the PHP block to use PHP 7.3-FPM.

The Ubuntu default site configuration file can be found at

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

Then edit the PHP block session:

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 the Nginx HTTP server to use PHP 7.2-FPM.

sudo systemctl restart nginx.service

Finally, run the commands below to remove all PHP 7.2 packages.

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

Doing that will prompt you to accept the changes to your system. Then, type Y to continue. When you’re done, PHP 7.3-FPM should be enabled, and PHP 7.2-FPM should be removed entirely from Ubuntu.

That’s it!

Conclusion:

Upgrading PHP-FPM on Ubuntu to ensure compatibility with the latest WordPress versions is crucial for performance and security. Here are the key takeaways:

  • Compatibility Check: Always verify that your themes and plugins support the new PHP version before upgrading.
  • Installation Steps: Follow the appropriate commands to install the desired PHP-FPM version and required modules.
  • Configuration Updates: Modify the PHP configuration settings to optimize performance for your WordPress site.
  • Nginx Configuration: Ensure Nginx is properly configured to use the new PHP version by editing the site configuration file.
  • Package Removal: Clean up old PHP versions to free up system resources.
  • Regular Updates: Regularly check for and apply updates to maintain optimal performance and security.

By following these steps, you can successfully upgrade your PHP-FPM and maintain a robust WordPress environment.

Richard Avatar

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *