WordPress is built around the PHP scripting language, so having an up-to-date version of it installed on your web server is quite essential. It’s easy to keep WordPress up to date yourself, but the core technologies (like PHP) aren’t always in sync with your installed WordPress version.
This is especially true for do-it-yourself web servers that you have set up yourself. If the server hosting your site hasn’t been updated, PHP probably isn’t, which could expose your site to exploits or faulty features. That means you need to update PHP to keep everything 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 on the WordPress sitebut as of publication, WordPress currently supports at least PHP 7.3 or higher.
However, not all web servers will use PHP 7.3 or higher. Older PHP versions will still work with WordPress, but it can cause newer themes, plugins, and features to break.
To make sure you are using the correct PHP version, you can check your current WordPress installation using the Site health menu in WordPress 5.2 and above.
- To do this, log in to your WordPress admin page. You need a user account with the Administrator role applied. Once you are logged in, press Resources > Site Health from the side menu.
- If your WordPress PHP version is out of date, it 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 with third-party plugins such as: PHP Compatibility Checker† If your PHP version is out of date, you should transfer it as soon as possible to upgrade it.
Back up your site and prepare to upgrade
Updating a core component like PHP can wreck your site. Before rushing to update PHP in WordPress, it is best to backup your WordPress site and prepare to upgrade it first.
You should start by making a copy of your MySQL database and making physical copies of your WordPress files. Many WordPress hosting providers offer built-in backup services that you can take advantage of, so check with your web host if this is the case.
For DIY servers, it’s up to you – you need to back them up manually. If you’re afraid to hit the terminal, use a plugin like UpdraftPlus to automatically create regular backups of your WordPress installation. UpdraftPlus can store your backups from your server and take advantage of cloud storage services such as Google or Microsoft Azure.
Once your WordPress site has been backed up, you are ready to take the plunge and start updating PHP in WordPress.
Switch PHP Versions in WordPress with cPanel
Many web hosting services use the cPanel web hosting control panel system so that you can manage and change your web hosting. For shared hosting, where you share your web space with other users, you may not be able to update PHP at all in WordPress, but you may be able to switch to a newer version if it’s available.
If not, please contact your hosting provider directly about updating PHP to the latest version. If so, cPanel provides 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, log in to the cPanel site for your web hosting. After logging in, look for the cPanel options named PHP selector or Select PHP version and press it.
- The PHP selector tool allows you to change the PHP version currently used on your server. Choose a version equal to or higher than 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 exist and may support similar functionality. If there are none and you have direct access to your web server, you can update PHP manually.
Update PHP manually from a terminal or SSH connection
This option can and should only be used by users who have their site backed up and who are comfortable using a Linux terminal. Most web servers run on Linux, but if you have a Windows IIS server, you can update PHP in WordPress using the Web Platform Installer instead of.
As we mentioned, it is essential that you have a backup of your WordPress site before you start. It’s also worth testing the latest PHP version on a test version of WordPress on a separate server and installation to make sure your plugins, themes, and overall WordPress installation are working properly before launching. update your main server.
- When 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 press 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 Install, replace PHP xx with the latest available version of PHP (for example php7.4†
This will use a third-party repository to install the latest PHP package, but you may prefer to manually download and install it yourself from the PHP website† you can walk php-v again after installation to verify that the installation was successful.
- The latest version of PHP will be installed, but you will need to change which version of PHP is used by your web server. If you are using Apache, type sudo a2enmod phpx.x (replacing xx with the correct version) to change your Apache server settings, then restart Apache by typing sudo systemctl restart apache2 or sudo service restart apache2†
For non-Apache installations, please refer to your web server software documentation to update the PHP version used for your server configuration, and to install additional PHP modules (plug-ins) for your version of PHP.
After PHP is updated, your web server settings are changed to use the new version, and your web server is rebooted, your WordPress site will start using it.
Keeping Your WordPress Site Secure
WordPress is at the heart of millions of sites around the world, and like other web administrators, you need to keep your WordPress site secure. Now that you know how to update PHP in WordPress, you should do a full security audit. If your site has holes, you may have WordPress malware that you need to remove.
If you are 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.