As a WordPress administrator, updates are central to your job. For optimal functionality and strong security, you need to ensure that your theme, plugins, and WordPress core are running their latest versions.On top of this, we also recommend updating your PHP.
In this post, I’ll cover what you need to know about the PHP language, how it generates content in WordPress, why it needs to be updated, and how to upgrade your WordPress site to the latest version of PHP.
What is PHP?
PHP is a programming language frequently used on the web. First released in 1995 as a general-purpose programming language, PHP has become a favorite tool among developers for enabling dynamic web pages. Dynamic web pages are those which are generated by the hosting server when requested by a client, rather than stored on the server in their entirety.
So, what exactly does PHP do on the web server? In short, PHP code is what generates the dynamic HTML pages to be sent to the client. When a site visitor requests a web page with a URL, a special PHP module on the server processes the request, then executes PHP code to create an HTML page from scratch. Lastly, the server delivers a complete HTML file back to the visitor’s web browser.
What does PHP do in WordPress?
Rather than store each website page separately as individual HTML files, WordPress contains many PHP files that each control a different part of your page, such as headers and footers, comment sections, etc. If you look at your WordPress file names, you’ll notice these files end with a “.php” extension.
On your WordPress site, the main job of PHP is to fetch page content stored in your WordPress database and turn it into web pages. Upon receiving a request for a page, the PHP code pulls relevant page content from your WordPress database, converts it into an HTML file (and accompanying CSS files), and sends the HTML back to the visitor who made the request.
Why assemble pages this way? In a word, flexibility. In conjunction with HTML and CSS, PHP makes it possible for developers to create themes and must-have WordPress plugins that run on their own PHP files. These themes and plugins can use WordPress database content however they like. If you want to swap plugins and/or themes, this setup also lets you do so without the need to generate a new set of pages every time. Every page on your site is generated in real-time when requested.
Additionally, PHP is a good fit for WordPress because, like WordPress itself, PHP is open-source. Anyone can see how the language works under the hood and customize it for their site if desired.
PHP and the CMS Revolution
While PHP enjoyed some popularity in the web development community for years, the advent of Content Management Systems (CMS) really put this language on the map. WordPress is the most popular CMS on the internet, and this fact is a testament to the robustness and versatility of PHP.
What is PHP 7?
PHP 7 is the latest version of PHP, released in late 2015. WordPress played a key role in shaping this version — during its development, the WordPress community examined and tested every element to ensure compatibility with the CMS.
Today, more than 18% of WordPress sites use PHP 7, with many plugins and themes actively supporting this version. PHP upgrades are ongoing, and PHP 8 will be released in late 2020.
PHP 7 is a major upgrade from the previous version, PHP 5.6. (If you’re wondering what happened to PHP 6, the project was scrapped due to technical issues and poor reception.) Notable improvements in PHP 7 include:
- Increased speed: PHP 7 uses less memory to accomplish the same goal, providing a substantial performance boost.
- Enhanced declarations: The addition of Scalar Type and Return Type declarations makes code easier to read and customize.
- Improved error handling: Previous PHP versions handled fatal errors by halting the entire code script. PHP 7 lets the script continue to run and throws an error instead.
Why You Should Upgrade Your PHP in WordPress
WordPress and many WordPress hosts make updates easy with automation. Still, manual updates can be a hassle. Is upgrading PHP really worth your time?
Absolutely. The benefits of the latest PHP can be boiled down to three factors: speed, security, and compatibility.
Between releases, PHP developers update the language to use resources more efficiently and introduce new features and functions. This means that each new release of PHP will run your WordPress website faster than before. Not only will better performance keep visitors engaged with your site — it can also boost your rankings in search engines.
To evaluate PHP 7 performance, we tested PHP 7 on WordPress in a strictly controlled environment. The server was hit 37,378 times with zero errors and zero timeouts. The average response time was 4 milliseconds with caching:
Comparing these results with the previous version of PHP, we see remarkable improvements in performance and average response time. When we ran the same tests on PHP 5.5, the server was hit 24,731 times with zero errors and zero timeouts. But, the average response time was much slower at 208 milliseconds.
For even more ways to speed up your WordPress website, check out our tips to improve WordPress site performance.
PHP’s popularity makes it a common target for cyberattacks. To counter these attacks, new PHP releases contain patches to vulnerabilities exposed by hackers. If your WordPress site is running an old version of PHP, it won’t have these fixes in place and will be more susceptible to malware, viruses, and unwanted access to your site’s backend.
New PHP alone won’t keep intruders out. See our guide to WordPress security for steps on how to harden your WordPress site
WordPress websites are made up of multiple parts, and when one component upgrades, the rest tend to follow. The best WordPress themes and plugins, as well as WordPress itself, always run on the latest version of PHP. If you’re stuck on a previous version, the lack of compatibility between PHP and your core files, plugins, and theme might break your website.
As a WordPress administrator, you don’t need to know the nitty-gritty details about how PHP works. However, knowing how to update PHP is a must. Let’s get started.
How To Update PHP in WordPress
- Check your current PHP version.
- Check compatibility with the latest PHP version.
- Back up your website.
- Update your WordPress core, plugins, and active theme.
- Update your PHP version.
- Check your updated site.
1. Check your current PHP version.
To make sure your system requires a PHP update, you can check in WordPress. From the administrator dashboard, select Tools > Site Health. Under Site Health Status, WordPress will tell you if your version of PHP should be updated, along with other security and performance improvement recommendations.
2. Check compatibility with the latest PHP version.
Simply install and run the plugin through WordPress to check your existing code. If the plugin finds any problems, you’ll see a list of errors and warnings along with specific code details to help make key changes before upgrading.
3. Back up your website.
Most WordPress tutorials will advise you to create a backup of your site before making significant changes, and updating PHP is no exception. The actual switch to PHP typically won’t bring up any show-stopping issues. But, just in case, it’s always ideal to have a failsafe backup handy.
4. Update your WordPress core, plugins, and active theme.
With a backup on hand, you can begin preparing your website for the update itself. To prevent functionality issues stemming from poor compatibility with PHP, check that all your add-ons and your core files are running their latest versions. Check this under Dashboard > Updates and click Update all if prompted.
Any quality plugin and theme will work with PHP 7 — if not, find a better option that does.
5. Update your PHP version.
Now for the actual updating part. The module that processes PHP code is installed on your site’s web hosting server. When I say, “updating PHP version,” this module is what we’re actually changing. Because the inner-workings of PHP are handled by your server, any PHP updates are done through your host
There are two ways to update PHP on your host, by contacting your hosting provider, or by updating manually if possible. Here I’ll explain how to do both.
Talk to Your Hosting Provider
The more hands-off option for a PHP upgrade is reaching out to your host directly via chat, email, or phone, and simply asking. In most cases, your provider will take care of this for you, or add an upgrade option to your hosting control panel along with instructions.
In some cases, your host might offer an automating upgrading service. If so, make sure you’ve run compatibility tests and fixed any errors, since the hosting provider isn’t responsible if something goes wrong with your site.
Other providers may not support PHP 7 and have no plans to switch. In this case, consider moving to a new WordPress host. The benefits of PHP 7 outweigh the inconvenience of transferring domains.
Update PHP Manually
While hosting control panels differ across providers, one of the most common is cPanel.
To make the switch, navigate to the Software/Service tab and search for a PHP option. Then, click Select PHP Version. You’ll see this screen:
The highlighted drop-down lets you set your current PHP version. So long as your hosting provider has done their job, some variant of PHP 7 should be available. Once you’ve selected version 7 from the drop-down menu, click Save or Set as Current.
This process will vary slightly between hosts. If you get stuck, read over your provider’s documentation or help resources, and reach out to support if you need to.
6. Check your updated site.
Give your host at least 30 minutes for the PHP to fully update. Then, make sure your WordPress site still works by viewing all your pages and testing your plugins one-by-one. If there’s a problem, you may be able to revert to your old PHP version in cPanel or by contacting your host again. If worse comes to worst, you have a backup standing by to reset your update.
And with that, you’re all set. PHP 7 will bring your site many benefits over previous iterations. Sit back and enjoy the increased performance, enhanced functionality, tighter security, and happier visitors.
Originally published Feb 28, 2020 5:33:03 PM, updated March 17 2021