Install PHP 7.3 & Required PHP Extensions for WordPress on Ubuntu Nginx Server

PHP Logo

With PHP versions 7.1 or older reaching end of life (EOL), f you haven’t already its time that you install and configure PHP 7.3 and any required extensions, this article will walk you through the process of setting up PHP 7.3 on your Ubuntu Nginx server, as well as installing the required and recommended PHP Extensions for WordPress website.

In this article I am working on a system that was already configured and running PHP 7.2.

Before you begin, the steps in this article assume the following

  • You are running either Ubuntu 16.04 or 18.04
  • You have sudo or root access
  • Your server runs Nginx.

 

1. Add PPA repository and update package lists.

Run the following commands to add the ppa:ondrej/php PPA repository to your system and update the available package list.  This PPA contains the latest PHP packages and extensions for Ubuntu systems and is my recommended choice, even though there are a number of possible sources for these packages.

sudo add-apt-repository ppa:ondrej/php

sudo apt update

This should only take a minute to complete, after which you can install and configure the new PHP package and any required extensions.

2. Install PHP 7.3 and any extensions that you need.

The next commands will install php 7.3 to your system and both the required and recommended extensions for running a WordPress website using the latest core branch.

To install php-7.3 and php7.3-fpm;

sudo apt install php7.3 php7.3-fpm

To ensure that you have all of the required & recommended extensions for running WordPress websites (these extensions should also be sufficient for most other PHP based CMS platforms or functions), run the following;

sudo apt install php7.3-common php7.3-mysql php7.3-curl php7.3-json php7.3-mbstring php7.3-xml php7.3-zip php7.3-gd php7.3-soap php7.3-ssh2 php7.3-tokenizer 

A list of the required and recommended PHP extensions for WordPress

WordPress have a list of the required and recommended PHP extensions for running WordPress optimally in the WordPress Server Environment Documentation which is available in full by clicking here, but for your reference, below is the list as of December 18th 2019, with WordPress version 5.3.1 being the latest and PHP 7.3 being the recommended version.  Many of them are included in the php7.3-common package, which is why they havent been explicitly added in the earlier commands.

PHP Extensions for WordPress

Required Extensions;

curlPerforms remote request operations.
domUsed to validate Text Widget content and to automatically configuring IIS7+.
exifWorks with metadata stored in images.
fileinfoUsed to detect mimetype of file uploads.
hashUsed for hashing, including passwords and update packages.
jsonUsed for communications with other servers.
mbstringUsed to properly handle UTF8 text.
mysqliConnects to MySQL for database interactions.
libsodiumValidates Signatures and provides securely random bytes.
opensslPermits SSL-based connections to other hosts.
pcreIncreases performance of pattern matching in code searches.
imagickProvides better image quality for media uploads. See WP_Image_Editor is incoming! for details. Smarter image resizing (for smaller images) and PDF thumbnail support, when Ghost Script is also available.
xmlUsed for XML parsing, such as from a third-party site.
zipUsed for decompressing Plugins, Themes, and WordPress update packages.

Recommended Extensions;

filterUsed for securely filtering user input.
gd If Imagick isn’t installed, the GD Graphics Library is used as a functionally limited fallback for image manipulation.
iconvUsed to convert between character sets.
mcryptGenerates random bytes when libsodium and /dev/urandom aren’t available.
simplexmlUsed for XML parsing.
xmlreaderUsed for XML parsing.
zlibGzip compression and decompression.

3. Configure PHP 7.3 in your Nginx configuration.

Next, you will need to update your sites Nginx configuration to accomodate the recently installed PHP 7.3, if you already had an older php version installed and configured, this will just involve updating a little bit of code within your Nginx configuration.

If you are using the default site block and only running a single site on the service, which would put your sites document root at  /var/www/html/ then you will need to edit the default configuration at /etc/nginx/sites-available/default which you can do by issuing the following command.

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

If you have multiple sites and configurations, and want to apply PHP 7.3 to them individually instead of adding it as the default, then edit the appropriate configuration file within the same directory as the “default” file, or if you are using a custom built site block, wherever your sites configuration may be set up.

Install PHP 7.3 - PHP Extensions for WordPress

Once you have the file open in nano (or your choice of editor), then add or amend the following code within the server configuration section to configure it for use with PHP 7.3.

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

 

Dont forget afterwards to restart the php7.3-fpm service, as well as check the Nginx configuration for problems before restarting or reloading Nginx.  The changes will not take affect until this is done.

To restart php7.3-fpm – sudo systemctl restart php7.3-fpm

To check that the Nginx configuration changes have been made correctly – sudo nginx -t

Nginx Config OK

If the Nginx configuration test comes back as OK, then you can restart or reload Nginx using the following commands;

sudo systemctl restart nginx

sudo systemctl reload nginx

You can check the status of these service also by running the following command to make sure they successfully restarted on your server.  After doing this, PHP 7.3 will be running any sites it was configured for;

sudo systemctl status php7.3-fpm nginx

Install PHP 7.3 - PHP Extensions for WordPress
Get paid to Google search

3 Comments

    • Thanks for the reply! I’ve updated the install command to include this extension, although it is not listed by the official WordPress documentation that it is required and sites seem to run fine without it so I’m not quite sure that it is required with an up to date WP version.

Leave a Reply

Your email address will not be published.


*