Upgrading PHP to a newer version has multiple perks: speed and performance increase, resource usage reduction, support for newer functions, and most importantly, better security of your website. Unfortunately, if some of the currently used functions aren’t supported by the newer PHP version, you run the risk of breaking your website. While that can be scary, the risk can be nearly eliminated with proper precautions and little troubleshooting. And because we believe the benefits outweigh the potential downsides, here’s how to update PHP in WordPress.
1. Check your current WordPress PHP version (Optional)
You can inspect your current PHP version. That way, you know where to fall back to if things don’t go as planned. One way is step 1 in our guide on the “your PHP installation appears to be missing the MySQL extension which is required by WordPress” error. A more user-friendly way is to access a WordPress Admin Section, then go to Tools > Site Health and find the PHP version at the top.
2. Prepare things for the PHP update in WordPress
To ensure a smooth transition and avoid the majority of potential errors, we recommend you do these things before upgrading:
- Update WordPress. We already demonstrated how updating WordPress works.
- Backup your website. Use one of the top backup plugins for WordPress if you aren’t already.
- Update themes and plugins. Visit the Plugins > All Plugins and Themes > All Themes pages in your Admin Section, and upgrade your themes and plugins to the newest versions.
- Check PHP Compatibility. A WordPress plugin named PHP Compatibility Checker by WP Engine is no longer supported. So, you’ll have to resort to an open-source GitHub project, PHP CodeSniffer.
2. Create a staging website (Strongly recommended)
Making a staging website will duplicate your current website. That way, you can simulate the update and test it in a safe environment bore making live changes. Many web hosting providers offer built-in ways to do that, too. One example is Kinsta, which we reviewed, via the Kinsta Dashboard:
- Click on Sites in the left sidebar.
- Click on the Change environment button in the upper right corner.
- Select Staging environment from the drop-down menu.
- Click on the Create a staging environment button, and Kinsta will generate a subdomain.
- You can begin making changes after DNS propagates, in approximately 10 to 15 minutes.
Mine doesn’t. What do I do?
Use a dedicated WordPress plugin to do the same, of course. A popular example is WP STAGING (wordpress.org/plugins/wp-staging/) which will make a copy of your website. You don’t need to create any accounts and the data stays on your server.
3. Update PHP version in WordPress
Updating PHP in WordPress can be done in one of 3 ways:
1. Through cPanel (or alternatives)
Many web hosting services allow you to do it through the site owner Dashboard, which is usually Linux cPanel or their variation of it. Check your hosting’s website for precise instructions, or skip to method 3. Here are a few examples of upgrading PHP version via cPanel:
After accessing the Kinsta Dashboard, do this:
- Open the Sites menu in the left sidebar.
- Select your website if you have multiple, then switch to the Tools tab.
- Find the PHP engine section, and you’ll see the current PHP version.
- Click on the Modify button.
- Select a new PHP version from the drop-down list.
- When a prompt appears, click on the Modify PHP version button to confirm.
Log in to the GoDaddy website with your user account, and then:
- Switch over to the Products page.
- In the Web Hosting section, click on Manage next to your website name.
- Now, under Dashboard, find the Settings section.
- Click on Server, then find PHP version and click on Manage next to it.
- Select a newer version of PHP, then type “update” in the empty text field.
- Click on Save Changes.
A2 Hosting uses a typical Linux cPanel, so if yours does too, follow these steps:
- Find the SOFTWARE section on the home screen.
- Click on the Select PHP Version option.
- Click on Current PHP Version, and select a new PHP version from the drop-down list.
- Optional. Select PHP extensions you want to enable or disable by putting/removing checkmarks in from of their names.
- Changes will take effect immediately.
2. By editing .htaccess
Many web hosting services allow PHP version updates by editing a .htaccess file. To do this, you’ll have to access it via FTP or SSH (Secure Shell). To demonstrate this, we’ll use DreamHost, which allows you to update PHP to PHP 7.4 by adding this code:
AddHandler fcgid-script .PHP
FCGIWrapper "/dh/cgi-system/php74.cgi" .php
Tip. You can replace 74 with the PHP version, for example, 80 for PHP version 8.0.
3. Via hosting Customer Support
The first two methods are typical for shared or VPS types of web hosting. Some web-hosting providers, however, make it necessary to contact their Customer Support to make any changes in the PHP version. Luckily, this service is available 24/7, via webchat, internal ticket, e-mail, or even phone call.
4. Check for errors, conflicts, or instability
Now for the main reason for creating a staging website, which is testing. Spend some time on the frontend: open menus, browse pages, click around, test plugin and theme functionality, and pay attention to any glitches or bugs. In the worst-case scenario, you’ll get a “This site is experiencing technical difficulties“ error or white screen of death. At that point, you should either wait it out or use method 3, sub-method 3 to ask for help. Luckily, in most cases, bugs will be minor or non-existent. The WordPress developers for themes or plugins will fix them when they release a new update.
5. Make the PHP update live (Staging website only)
If you used step 2 in our guide and confirmed everything is in order, repeat these steps on your real website. Or, to save time, simply click on the Push Staging to Live button in the Staging environment window (sub-step 3) or an equivalent button on the installed WordPress staging plugin.