Upgrade WordPress to PHP 7.4 on Apache running on Ubuntu


WordPress now displays a “PHP update required” warning on the dashboard if the PHP installation is not up to date. I saw the same warning in the WordPress dashboard for one of my sites.

The site has been running PHP 7.2 for more than a year and it was only recently i saw the warning for the first time. Coincidentally, the site had also been down in performance for a few months. So I had to upgrade PHP to the latest version in hope of boosting the performance of the server.

I will advise you to not take this warning lightly. As WordPress moves ahead, they will drop support for older version of PHP for the greater good of the community. So if you are not updating to the latest version of PHP supported by WordPress, your site will become vulnerable to malicious attacks and the performance of the Apache server will decrease, thus leading to slow loading of web pages. This eventually will result in decrease in SEO.

My server was running Ubuntu 18.04 with Apache as the web server. In order to upgrade WordPress to the latest PHP version, all I had to do was to install the latest version of PHP and make Apache use it instead of the older version. The good thing is, WordPress makes use of the same PHP version which is in use by the Apache web server. Updating PHP to the latest version for Apache will automatically result in WordPress using the same PHP version.

As of writing this, the latest PHP version is PHP 7.4, which was released on October 1st. I can imagine there will be thousands of WordPress sites running versions much lower than this. If your site is one of them, here’s how you can upgrade PHP to the latest version on WordPress running on Apache web server.

Check the latest PHP version.

Step 1: SSH as the root user into your Ubuntu server.

Step 2: Make sure your Ubuntu is up to date.

sudo apt update && sudo apt upgrade

Step 3: Run the following commands to add the correct repositories.

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

Step 4: Run the following command to install the latest version of PHP, i.e. PHP 7.4 as of writing this post.

sudo apt install php7.4

Step 5: Apart from installing the latest version of PHP, you will also have to install some of the commonly used PHP extensions. Run the following command to install the required PHP extensions.

sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

Step 6: Once the extensions are installed, run the following command to check the latest PHP version.

php -v

While the latest version of PHP has been installed on the server, it has not yet been set as the default php version for Apache.

Step 7: Run the following command to disable the older PHP version which Apache is making use of. Replace the x by the php version.

sudo a2dismod php7.x

Step 8: Enable Apache to use PHP 7.4 by running the following command.

sudo a2enmod php7.4

Step 9: Restart the Apache web server to bring the changes into effect.

sudo service apache2 restart

Thats it, Apache is now using PHP 7.4. This means WordPress will automatically use PHP 7.4 by default.

About the author


1 Comment

By lovejeet


Get in touch

Quickly communicate covalent niche markets for maintainable sources. Collaboratively harness resource sucking experiences whereas cost effective meta-services.