WordPress is built around the PHP scripting language, so it’s pretty essential to have an up-to-date version of it installed on your web server. It’s easy to keep WordPress up-to-date itself, but the core technologies (like PHP) aren’t always in sync with your installed WordPress version.
This is especially true for DIY web servers that you’ve set up yourself. If the server hosting your site isn’t updated, PHP isn’t likely to be either, which could leave your site exposed to exploits or broken features. That means you’ll need to update PHP to keep things running—here’s how to update PHP in WordPress.
Check Your Current PHP Version
From time to time, the minimum supported version of PHP that WordPress supports changes. You can check the current minimum version at the WordPress website, but as of publication, WordPress currently supports a minimum of PHP 7.3 or greater.
Not all web servers will be running PHP 7.3 or greater, however. Older PHP versions will still work with WordPress, but it may cause newer themes, plugins, and features to break.
To make sure you’re running the correct PHP version, you can check your current WordPress installation using the Site Health menu in WordPress 5.2 and later.
To do this, log in to your WordPress admin page. You’ll need to have a user account that has the Administrator role applied. Once you’re signed in, press Tools > Site Health from the side menu.
If your WordPress PHP version is out of date, this will be listed as a recommendation in the Status tab.
To check the current PHP version, press Info > Server and check the version listed under the PHP Version category.
You can also check your PHP version using third-party plugins such as PHP Compatibility Checker. If your PHP version is out-of-date, you’ll need to move to upgrade it as soon as possible.
Backup Your Site & Prepare To Upgrade
Updating a core component like PHP can break your site. Before you rush to update PHP in WordPress, the best thing to do is backup your WordPress site and prepare to upgrade it first.
You should start by making a copy of your MySQL database and make physical copies of your WordPress files. Many WordPress hosting providers will offer built-in backup services that you can take advantage of, so be sure to check with your web host if this is the case.
For DIY servers, it’s on you—you’ll need to back it up manually. If you’re afraid of hitting the terminal, use a plugin like UpdraftPlus to make regular backups of your WordPress installation automatically. UpdraftPlus can store your backups off your server, taking advantage of cloud storage services like Google or Microsoft Azure.
If your WordPress site is backed up, then you’re prepared to take the plunge and begin updating PHP in WordPress.
Switching PHP Versions In WordPress Using cPanel
Many web hosting services use the cPanel web hosting control panel system to allow you to control and make changes to your web hosting. For shared hosting, where you share your webspace with other users, you may not be able to update PHP in WordPress at all, but you may be able to switch to a newer version if it’s available.
If it isn’t, speak with your hosting provider directly about updating PHP to the latest version. If it is, cPanel allows for a quick-and-easy way to switch to newer versions of critical server software like PHP.
Because cPanel is modular, these settings may vary, depending on your own cPanel version.
To switch PHP to a newer version in cPanel, sign in to the cPanel site for your web hosting. Once signed in, look for cPanel options named PHP Selector or Select PHP version and press it.
The PHP Selector tool allows you to change the PHP version currently in use on your server. Choose a version equal or above the minimum WordPress supported version (currently PHP 7.3) from the PHP Version drop-down menu, then press Set as current to apply it.
The PHP version running on your server should change immediately. Other web host control panels do exist and may support similar functionality—if they don’t, and you have access to your web server directly, you can update PHP manually.
Updating PHP Manually From a Terminal Or SSH Connection
This option can and should only be used by users who have backed up their site and who feel comfortable using a Linux terminal. Most web servers run Linux, but if you have a Windows IIS server, you can update PHP in WordPress using the Web Platform Installer instead.
As we’ve mentioned, it’s essential that you have a backup of your WordPress site before you begin. It’s also worth testing the latest PHP version on a test version of WordPress on a separate server and installation to make sure that your plugins, themes, and overall WordPress setup works with it correctly before you update your main server.
If you’re ready to upgrade, open a terminal on a local web server or connect to a remote server using an SSH client on Windows, Linux, or macOS. Once connected, check your PHP version by typing php -v and pressing enter.
For Ubuntu and Debian-based servers, type sudo apt-get install software-properties-common && sudo add-apt-repository ppa:ondrej/php && sudo apt update && sudo apt install phpx.x to install PHP, replacing x.x with the latest available version of PHP (for instance, php7.4). This will use a third-party repository to install the latest PHP package, but you may prefer to download and install this yourself manually from the PHP website. You can run php-v again after installing to check if the installation was successful.
The latest version of PHP will be installed, but you’ll need to change which version of PHP is used by your web server. If you’re using Apache, type sudo a2enmod phpx.x (replacing x.x with the correct version) to change your Apache server settings, then restart Apache by typing sudo systemctl restart apache2 or sudo service apache2 restart.
For non-Apache installations, consult your web server software’s documentation to update the PHP version used for your server configuration, as well as to install additional PHP modules (plugins) for your version of PHP.
Once PHP has been updated, your web server settings have been changed to use the new version, and your web server has been restarted, your WordPress site will begin using it.
Keeping Your WordPress Site Secure
WordPress is the core of millions of sites worldwide, and like other web administrators, you need to keep your WordPress site secure. Now you know how to update PHP in WordPress, you should run a full security audit—if your site has holes, you may have WordPress malware that you’ll need to remove.
If you’re new to WordPress, here are some essential WordPress plugins to get your site up and running quickly. Let us know your WordPress security tips in the comments section.