WordPress 是围绕PHP脚本语言构建的,因此在您的 Web 服务器上安装它的最新版本非常重要。让 WordPress 保持最新(keep WordPress up-to-date)很容易,但核心技术(如PHP)并不总是与您安装的 WordPress 版本同步。
对于您自己设置的DIY Web 服务器尤其如此。如果托管您网站的服务器没有更新,PHP也不太可能更新,这可能会使您的网站暴露在漏洞利用或功能受损的情况下。这意味着您需要更新PHP以保持运行——这是在WordPress中更新(WordPress)PHP的方法。
检查您当前的 PHP 版本
WordPress支持的最低(WordPress)PHP支持版本会不时发生变化。您可以在WordPress 网站上(WordPress website)查看当前的最低版本,但截至发布时,WordPress目前至少支持PHP 7.3或更高版本。
但是,并非所有 Web 服务器都将运行PHP 7.3或更高版本。较旧的PHP版本仍可与WordPress一起使用,但可能会导致较新的主题、插件和功能中断。
为确保您运行的是正确的PHP版本,您可以使用 WordPress 5.2 及更高版本中的“(PHP)站点健康(Site Health)”菜单检查当前的WordPress安装。
- 为此,请登录您的WordPress管理页面。您需要有一个应用了管理员(Administrator)角色的用户帐户。登录后,从侧面菜单中按Tools > Site Health
- 如果您的WordPress PHP版本已过期,则会在“(WordPress PHP)状态”(Status)选项卡中将其列为建议。
- 要检查当前的PHP版本,请按Info > Server并检查PHP 版本(PHP Version)类别下列出的版本。
您还可以使用第三方插件(例如PHP Compatibility Checker )检查您的(PHP Compatibility Checker)PHP版本。如果您的PHP版本已过时,您需要尽快进行升级。
备份您的网站并准备升级(Backup Your Site & Prepare To Upgrade)
更新像PHP这样的核心组件可能会破坏您的网站。在您急于在WordPress中更新(WordPress)PHP之前,最好的办法是备份您的 WordPress 站点(backup your WordPress site)并准备先升级它。
您应该首先制作MySQL 数据库的副本并制作(copy of your MySQL database)WordPress文件的物理副本。许多WordPress托管服务提供商将提供您可以利用的内置备份服务,因此如果是这种情况,请务必咨询您的网络托管服务商。
对于DIY服务器,它在您身上——您需要手动备份它。如果您害怕点击终端,请使用UpdraftPlus之类的插件自动定期备份您的WordPress安装。UpdraftPlus 可以利用Google(Google)或Microsoft Azure等云存储服务将您的备份存储在您的服务器之外。
如果您的WordPress网站已备份,那么您准备好冒险并开始在WordPress中更新(WordPress)PHP。
使用 cPanel 在 WordPress 中切换 PHP 版本(Switching PHP Versions In WordPress Using cPanel)
许多网络托管服务使用 cPanel 网络托管控制面板系统来允许您控制和更改您的网络托管。对于共享主机,您与其他用户共享您的网站空间,您可能根本无法在WordPress中更新(WordPress)PHP,但如果可用,您可以切换到更新的版本。
如果不是,请直接与您的托管服务提供商讨论将PHP更新到最新版本的问题。如果是这样,cPanel 允许以快速简便的方式切换到新版本的关键服务器软件,例如PHP。
由于 cPanel 是模块化的,因此这些设置可能会有所不同,具体取决于您自己的 cPanel 版本。
- 要将PHP切换到 cPanel 中的较新版本,请登录 cPanel 站点以进行 Web 托管。登录后,查找名为PHP Selector或Select PHP version的 cPanel 选项并按下它。
- PHP 选择器(PHP Selector)工具允许您更改服务器上当前使用的PHP版本。(PHP)从PHP Version(PHP Version)下拉菜单中选择等于或高于WordPress支持的最低版本(当前为PHP 7.3)的版本,然后按Set as current以应用它。
服务器上运行的PHP版本应该立即更改。其他网络主机控制面板确实存在并且可能支持类似的功能——如果它们不支持,并且您可以直接访问您的网络服务器,您可以手动更新PHP 。
从终端或 SSH 连接手动更新 PHP(Updating PHP Manually From a Terminal Or SSH Connection)
此选项只能并且应该仅由已备份其站点并且对使用Linux终端感到舒适的用户使用。大多数 Web 服务器运行Linux,但如果您有Windows IIS服务器,则可以使用Web 平台安装程序(Web Platform Installer)在WordPress中更新PHP。
正如我们所提到的,在开始之前备份您的WordPress网站非常重要。在单独的服务器上测试WordPress(WordPress)的最新PHP版本并进行安装,以确保在更新主服务器之前,您的插件、主题和整体WordPress设置可以正确使用它。
- 如果您已准备好升级,请在本地 Web 服务器上打开终端或使用Windows、Linux或 macOS上的SSH客户端连接到远程服务器。连接后,通过键入php -v并按 Enter键检查您的PHP版本。(PHP)
- 对于基于Ubuntu和 Debian 的服务器,键入sudo apt-get install software-properties-common && sudo add-apt-repository ppa:ondrej/php && sudo apt update && sudo apt install phpx.x以安装 PHP,将xx替换为最新可用的PHP版本(例如php7.4)。
这将使用第三方存储库来安装最新的 PHP 包,但您可能更喜欢自己从PHP 网站(PHP website)下载并安装它。安装后可以再次运行php -v来检查是否安装成功。
- 将安装最新版本的PHP,但您需要更改Web 服务器使用的PHP版本。(PHP)如果您使用的是Apache,请输入sudo a2enmod phpx.x(将xx替换为正确的版本)以更改您的Apache服务器设置,然后通过输入sudo systemctl restart apache2或sudo service apache2 restart 重新启动(sudo service apache2 restart)Apache。
对于非 Apache 安装,请查阅您的 Web 服务器软件的文档以更新用于您的服务器配置的PHP版本,以及为您的 PHP 版本安装额外的PHP模块(PHP)(插件)。
一旦PHP更新,您的 Web 服务器设置已更改为使用新版本,并且您的 Web 服务器已重新启动,您的WordPress站点将开始使用它。
保持您的 WordPress 网站安全(Keeping Your WordPress Site Secure)
WordPress是全球数百万网站的核心,与其他网络管理员一样,您需要确保WordPress网站的安全。现在您知道如何在WordPress中更新(WordPress)PHP,您应该运行一个完整的安全审核 - 如果您的网站有漏洞,您可能需要删除WordPress 恶意软件。(WordPress malware)
如果您是WordPress新手,这里有一些基本的 WordPress 插件可以让您的网站快速启动和运行。在评论部分让我们知道您的WordPress安全提示。
How to Update PHP in WordPress
WordPress is built around the PHP scripting language, so it’ѕ pretty essential to have аn up-to-dаte version of it installed on уour web server. It’s eаsy 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.