In this tutorial, you will learn how to update PHP for WordPress. This tutorial assumes that you have SSH root access to your server and that you’re using either Apache or Nginx on an Ubuntu/Debian system to serve your web pages.
While the steps are very similar, the first part of this tutorial is specifically for Apache and the second part is for Nginx, but first let’s check the version of PHP that WordPress is using.
How to Check WordPress PHP Version
You can check the version of PHP that your WordPress website uses by going to Tools > Site Health > Info > Server.
Update WordPress PHP in Apache
To update PHP in Apache, first let’s add the PHP repository to the system.
apt update apt install software-properties-common add-apt-repository ppa:ondrej/php
In addition to installing a specific version of PHP (version 8.0 in this case), let’s install some PHP modules that WordPress may or may not need depending on what plugins you have installed.
apt install php8.0 apt install php8.0-bz2 php8.0-cli php8.0-common php8.0-curl php8.0-gd php8.0-gmp php8.0-intl php8.0-mbstring php8.0-mysql php8.0-opcache php8.0-pspell php8.0-readline php8.0-soap php8.0-tidy php8.0-xml php8.0-xmlrpc php8.0-zip
Finally let’s tell the Apache web server to use the new version of PHP instead of the old one.
a2dismod php7.4 a2enmod php8.0 systemctl restart apache2
At this point, you can verify that WordPress is now using a new version of PHP.
Update WordPress PHP in Nginx
To update PHP in Nginx, first let’s add the PHP repository to the system.
apt update apt install software-properties-common add-apt-repository ppa:ondrej/php
In addition to installing a specific version of PHP (version 8.0 in this case), let’s install some PHP modules that WordPress may or may not need depending on what plugins you have installed.
apt install php8.0 apt install php8.0-fpm php8.0-bz2 php8.0-curl php8.0-gd php8.0-gmp php8.0-intl php8.0-mbstring php8.0-mysql php8.0-pspell php8.0-soap php8.0-tidy php8.0-xml php8.0-xmlrpc php8.0-zip
Finally let’s tell the Nginx web server to use the new version of PHP instead of the old one. To do this, edit your website’s configuration file which is usually location at /etc/nginx/sites-available/
. Simply update the php-fpm socket reference (assuming you’re using that) to the new version of PHP. The line will look something like this server unix:/var/run/php/php8.0-fpm.sock
.
To apply this change, reload the Nginx web server.
systemctl reload nginx
At this point, you can verify that WordPress is now using a new version of PHP.