Upgrade WordPress to PHP 7.4 | PHP 7.4-FPM on Ubuntu 18.04 | 16.04

This brief tutorial shows students and new users how to upgrade WordPress to use PHP 7.4 | PHP 7.4-FPM using Ubuntu..

WordPress 5.3 “Kirk” was recently released with introduction of over 150 new features and usability improvements, including full PHP 7.4 support..

WordPress continues to encourage all users to run the latest and greatest versions of PHP… So if PHP 7.4 is fully supported, you may want to upgrade to it and make use of newest features and enhancements that were released..

Although PHP 7.4 is fully supported with WordPress, some themes and plugins may not… so you probably should make sure your themes and installed plugins support the latest PHP version, or you may run into issues…

If you have validated that all your plugins and themes are PHP 7.4-FPM compatible, continue below to learn how to upgrade your PHP-FPM versions to support the latest version to support WordPress…

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

Upgrade to PHP 7.4-FPM with Nginx on Ubuntu

If you’re running PHP 7.3-FPM or previous with Nginx on Ubuntu to support WordPress, the steps below show you how to upgrade to PHP 7.4-FPM

This post assumes that you’re running PHP 7.3 or previous..

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

Ubuntu may not have PHP 7.4-FPM packages available in its default repositories… In order to install the latest versions of PHP on Ubuntu you may have to add third-party repositories..

One such repository is below.. Simply run the commands below to add the below repository to Ubuntu so you can install PHP 7.4-FPM

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.4-FPM and related modules.

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

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

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

The lines below is a good settings 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

Everytime you make changes to PHP configuration file, you should also restart Nginx web server and PHP script… To do so, run the commands below:

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

After that, run the commands below to enable PHP 7.4 support for Nginx…. Open the current WordPress virtual host site configuration file and enable the php block to use PHP 7.4-FPM….

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.4-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }

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

sudo systemctl restart nginx.service

Finally, run the commands below to remove all PHP 7.3-FPM packages…

sudo apt-get purge `dpkg -l | grep php7.3| 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.4-FPM should be enabled and PHP 7.3-FPM completely removed from Ubuntu…

If you’re running PHP 7.2 of previous, replace 7.3 with your specific PHP version number to remove from Ubuntu…

 

Upgrade to PHP 7.4 with Apache2 on Ubuntu

Skip the above steps if you’re running WordPress on Apache2 HTTP server..

Apache2 runs on PHP 7.4 while Nginx runs on PHP 7.4-FPM.

First, run the commands below to install PHP 7.3 packages

Again, Ubuntu may not have PHP 7.4 packages available in its default repositories.. To run PHP 7.4 on Ubuntu to support WordPress, you may need to run the commands below to add a third-party repository…

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

After adding the repository above, update and install to PHP 7.4

sudo apt update

Next, run the commands below to install PHP 7.4 and related modules.

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

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

sudo nano /etc/php/7.4/apache2/php.ini

The lines below is a good settings 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

For Apache2 and PHP 7.4, you must disable previous versions of PHP and enable Apache2 to use the latest version… First run the commands below to disable PHP 7.3.

sudo a2dismod php7.3

Now that PHP 7.3 is disable, run the commands below to enable PHP 7.4.

sudo a2enmod php7.4

After enabling PHP 7.4, run the commands below to restart Apache2 and PHP 7.4 should be used to support WordPress…

sudo systemctl restart apache2.service

Finally, run the commands below to remove all PHP 7.3 packages…

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

That’s it!

Conclusion:

This post shows you how to upgrade to the latest PHP 7.4 to support WordPress sites on Ubuntu systems.. If you find any error above, please use the comment form below to report it.

You may also like the post below:

How to Install and Configure Redis Server on Ubuntu 18.04 | 16.04

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.