“Revamp your WordPress skills with this foolproof guide to updating PHP in your localhost!”
If You’re a WordPress Developer, You May Need to Upgrade PHP in Your Localhost
As a WordPress developer, it’s essential to keep your site running at its peak performance. This often means upgrading your PHP version to match that of your live WordPress site. Since PHP is the programming language WordPress runs on, it’s crucial to ensure you have the same PHP version installed locally as the one running on the server hosting your WordPress site. In this article, we’ll explore how to update PHP in WordPress localhost, step-by-step.
Step 1: Identify Your Current PHP Version
The first step is to check which PHP version you have running on your localhost. You can determine your PHP version through your WordPress dashboard, or by creating a PHP script. To check your PHP version via your WordPress dashboard, go to “Tools,” then select “Site Health,” and you’ll find your PHP version in the “Info” tab on top. Alternatively, create a PHP script following these steps:
- Create a new file named
phpinfo.php
in the root directory of your WordPress site. - Add the following line of code to the file:
<?php phpinfo(); ?>
- Access the file through your web browser by visiting
http://localhost/phpinfo.php
.
Your browser will display your current PHP version on the resulting page.
Step 2: Backup Your WordPress Site Locally
Before upgrading PHP, it’s crucial to take a full backup of your local WordPress site. With a complete backup, you can easily restore your site to its previous state if anything goes wrong during the upgrade. In case you want to think beyond traditional methods, you can look into Archive Document Storage services for a safe and more secure backup.
There are multiple plugins available on WordPress to help you backup your site, like UpdraftPlus, All-in-One WP Migration, etc. Choose the plugin that best suits your requirements to create a complete backup of your website.
Step 3: Upgrade Your PHP Version
Once completed with the backup process, you can upgrade your PHP version knowing your site is now safe. The process for upgrading PHP varies based on your operating system. Below is a step-by-step guide for three of the most commonly used operating systems:
Upgrading PHP in Windows:
- Download the new version of PHP from the official PHP website.
- Extract the downloaded ZIP file and move the contents to a new folder named “php” in your C drive.
- Open the “Run” dialog box by pressing the “Windows” and “R” key simultaneously.
- Type “sysdm.cpl” and press the “Enter” key.
- Click on the “Advanced” tab, then “Environment Variables”.
- Under “System variables”, scroll to “Path,” click “Edit.”
- In the “Edit environment variable” dialog box, click “New.” Then, enter “C:\php” (without quotes), and click “OK.”
- Launch a command prompt and type “php-v” (without quotes).
- If your PHP version is still the old one, restart your computer.
Upgrading PHP in Linux:
- Open your terminal and run the following command:
sudo apt-get install python-software-properties
- Run the following command to add the PPA:
sudo add-apt-repository ppa:ondrej/php
- Update your package list:
sudo apt-get update
- Run the command to install PHP:
sudo apt-get install php7.4
- Note: replace “php7.4” with the version of PHP you want to install.
- After installation, restart your Apache server by running the following command:
sudo service apache2 restart
Upgrading PHP in macOS:
- Install Homebrew if you haven’t already.
- Open your terminal and run the following command:
brew install php
- Open your Apache configuration file located at
/etc/apache2/httpd.conf
and search for the following line:#LoadModule php7_module libexec/apache2/libphp7.so
. - Remove the “#” symbol from the line, save and close the file.
- Run the following command:
sudo apachectl restart
Step 4: Test Your WordPress Site
Once you have upgraded your PHP version, it’s essential to test your WordPress site to ensure everything’s working properly. Check your site for errors or warning messages by navigating to it in your web browser.
If there are no errors or warning messages, your PHP update was successful!
Conclusion
Overall, upgrading your PHP version in WordPress localhost is a simple process. Identify your current PHP version, backup your WordPress site, upgrade PHP, and test your site to ensure it’s working correctly. With these straightforward steps, you can have the same PHP version running locally as on your live WordPress site.