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.

But hold on...what is PHP? The term might sound familiar to you — that’s because your site, and allWordPress websites, run on it. As part of WordPress’ underlying code backbone, PHP works with HTML, CSS, and JavaScript to create the framework of WordPress sites worldwide.

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.

使用HubSpot的WordPress网站来发展业务

What is PHP?

PHP是网络上经常使用的编程语言。PHP于1995年首次作为通用编程语言发行,已成为开发人员中最喜欢的工具,以启用动态网页。动态网页是客户要求时由托管服务器生成的网页,而不是整体存储在服务器上。

phpis a服务器端语言,这意味着它完全运行服务er that hosts the website. This distinguishes it from other languages you might know, includingHTML,CSS和JavaScript。这些是client-sidelanguages — they run on the device of the visitor accessing a website (i.e., the visitor’s web browser).

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.

在您的WordPress网站上,PHP的主要工作是获取存储在WordPress数据库中的页面内容并将其转换为网页。收到页面的请求后,PHP代码将从WordPress数据库中提取相关的页面内容,将其转换为HTML文件(以及随附的CSS文件),并将HTML发送回该请求的访问者。bob全站app

Why assemble pages this way? In a word, flexibility. In conjunction with HTML and CSS, PHP makes it possible for developers to create themes andmust-have WordPress pluginsthat 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和CMS革命

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 themost popular CMS在互联网上,这一事实证明了PHP的鲁棒性和多功能性。

What is PHP 7?

php7 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是前一个版本PHP 5.6的重大升级。(如果您想知道PHP 6发生了什么,该项目由于技术问题和接待不佳而被报废。)PHP 7的显着改善包括:

  • 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和许多WordPress主机可以轻松使用自动化。不过,手动更新可能会很麻烦。升级PHP真的值得您花时间吗?

Absolutely. The benefits of the latest PHP can be boiled down to three factors: speed, security, and compatibility.

Increased Speed

之间的版本中,PHP开发人员更新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提高您在搜索引擎中的排名

为了评估PHP 7的性能,我们在严格控制的环境中在WordPress上测试了PHP 7。该服务器的击中37,378次,零错误和零超时。缓存的平均响应时间为4毫秒:

图表显示了使用php 7在WordPress网站上增加响应时间的图表
a chart showing increased hit rates on a WordPress website using PHP 7

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 ourtips to improve WordPress site performance

Improved Security

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.

仅仅新的PHP就不会阻止入侵者。看我们guide to WordPress securityfor steps on how to harden your WordPress site

Better Compatibility

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.

作为WordPress管理员,您无需了解有关PHP的工作方式的细节。但是,必须知道如何更新PHP。让我们开始吧。

1. Check your current PHP version.

为了确保您的系统需要PHP更新,您可以在WordPress中检查。从管理员仪表板中,选择Tools > Site Health。UnderSite Health Status, WordPress will tell you if your version of PHP should be updated, along with other security and performance improvement recommendations.

the Site Health Status window in WordPress

2. Check compatibility with the latest PHP version.

Before upgrading your WordPress Site to PHP 7, make sure it’s compatible with new PHP. The easiest way to do this is by using the pluginPHP兼容性检查器

The PHP Compatibility Checker plugin for updating PHP in WordPRess

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.备份您的网站。

Most WordPress tutorials will advise you tocreate a backup of your sitebefore 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 underDashboard > Updatesand clickUpdate allif prompted.

任何高质量的插件和主题都将与PHP 7一起使用 - 如果没有,请找到一个更好的选择。

5. Update your PHP version.

现在实际更新部分。的模块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.

与您的托管提供者交谈

PHP升级的更多功能选择是通过聊天,电子邮件或电话直接与主机联​​系,并只是询问。在大多数情况下,您的提供商会为您处理此功能,或在托管控制面板中添加升级选项以及说明。

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移至新的WordPress主机。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 iscPanel

To make the switch, navigate to thebob电竞官方下载软件/服务标签并搜索phpoption. Then, click选择PHP版本。您会看到此屏幕:

CPANEL仪表板PHP版本选择器

突出显示的下拉列表使您可以设置当前的PHP版本。只要您的托管提供商完成了工作,应该可以使用一些PHP 7的变体。从下拉菜单中选择了版本7后,请单击节省或者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.检查您的更新网站。

给您的主机至少30分钟以使PHP完全更新。然后,确保您的WordPress网站仍然可以通过查看所有页面并一对一地测试您的插件来工作。如果有问题,您可能可以在CPanel中恢复到旧的PHP版本,或者再次与主机联系。如果更糟糕的是,您将有一个备份来重置您的更新。

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.

使用WordPress网站上的HubSpot工具,并在不处理代码的情况下连接两个平台。点击这里了解更多。

使用WordPress网站上的HubSpot工具,并在不处理代码的情况下连接两个平台。点击这里了解更多。

Originally published Feb 28, 2020 5:33:03 PM, updated March 17 2021

Topics:

WordPress Website