Are you looking to update the version of PHP for a website you have hosted on your Plesk server? Then, follow along!
What is PHP and what are different versions?
The PHP application’s job is to read .php files stored on the server, and then interpret and execute the code within them in order to ouput webpage to the visitor. PHP files themselves are hidden to the end-user, unlike .html files, because they may contain sensitive information. For example: WordPress’ wp-config.php contains the database username and password.
PHP is one of the most popular website scripting languages, and as such–hackers are constantly looking for exploits and vulnerabilities. The developers of PHP push updates each major version (for example PHP 8.2) up to certain date (Dec 31, 2024), in which that PHP version is considered retired, or has reached it’s “end of life”.
Each new version of PHP contains new scripting functions, features, and improvements. Often this means that older functions are deprecated for newer, better ones. If you update the PHP interpreter version of a website without updating the code to match, the website will display errors or fail to load.
What steps should I take?
- The first step in preparing for any change is making a backup, or checking the integrity of the last backup.
- Next, creating a staging website, as a clone/copy.
- Then, installing the newer version of PHP on the server.
- Followed by updating the staging site scripts, themes, plugins.
- Trying out the newer PHP interpreter on the staging site.
- If all is well, copying over the updating staging site to the live site.
Making a Backup
There are many different ways to make a backup. I advisable to use at least two or more methods:
Backup Method | Documentation | Pros | Cons |
Plesk Backup | https://support.plesk.com/hc/en-us/articles/12377967480855–How-to-create-a-backup-in-Plesk | Very easy and quick to create and restore website backups. | Backups are stored locally so if the server is compromised, file system corrupted, or hard drive dies, your backup is lost. However, there are built-in options for remote storage as well. |
Cloud Backup | Purchasing Installing Creating a Protection Plan Triggering a manual backup | Stores backups off of the server in case of server compromise, file system corruption, or hard disk crash. | Has extra steps to install and configure the backups. There is an associated price. |
Plugin Backup | https://wordpress.org/plugins/updraftplus/ | Easy to use with WordPress. | Only works with WordPress sites. Requires an additional paid service to backup to (Dropbox, Google Drive, etc.). |
Manual Backup | https://developer.wordpress.org/advanced-administration/security/backup/ | Can backup to local PC or thumb drive. No additional costs. | The most tedious option. Requires the most steps. |
Creating a Staging Site
Since WordPress is so popular, Plesk comes pre-installed with the WP Toolkit. If your website is a WordPress site, using the WP Toolkit to create a staging site is your friendlier option.
If your website is anything other than WordPress, things can get a bit trickier. For basic PHP-only websites, it’s simple! For anything other-script related (React), or for websites containing Databases (Joomla), there are some additional steps involved.
Cloning The Website
If your website is not listed, click on the Scan button to add it.
Next, under your website on the WordPress page, click Clone.
![](https://help.unlimitedweb.space/share/2024/06/wptk.png)
Choose the target, either creating a new staging subdomain (if this is your first time), or over-writing an existing staging subdomain. Click Start.
The newly cloned website will be listed. Be sure that DNS entries exist for the subdomain so that you can visit it. For example, adding an A record for staging.example.com at your name server. DNS updates often take an hour to fully propagate.
Next, navigate to Domains > your domain > Website Copying.
![](https://help.unlimitedweb.space/share/2024/06/wsc.png)
Note: Website Copying is not available in Dynamic View. Click on the wrench in the top right corner, and select Active List under View Mode.
Choose your staging subdomain. Choosing to delete existing files may be the more secure option.
![](https://help.unlimitedweb.space/share/2024/06/cd.png)
Next you will need to copy the database if one exists. Navigate to Domains > your domain > Databases. Click Copy under the database.
![](https://help.unlimitedweb.space/share/2024/06/copydb.png)
Now, you will need to change the database name within your staging website's configuration file. Where this is located depends on your website.
Example locations for database config file:
Joomla: /configuration.php
Drupal: /sites/default/settings.php
Magento: /app/etc/env.php
TYPO3: /config/system/settings.php
PrestaShop: /app/config/parameters.php
Installing New PHP Version
At the time of this writing, PHP 8.1 is the lowest supported version by the PHP team, however, Plesk support installing as low as PHP 7.4 using the Plesk Installer. This is prone to change for any version or operating system at any time.
Installing >=PHP 7.4
To install a new version of PHP available in the installer, login to your Plesk server and navigate to Tools & Settings → Updates. A new window/tab will pop up.
Click on Add/Remove Components.
Linux Server: On this page, navigate to Web hosting → PHP interpreter versions
Windows Server: On this page, navigate to the Plesk hosting feature section
Choose the PHP version for installation and click Continue.
Installing < PHP 7.4
Anything lower than PHP 7.4 is not supported by the Plesk installer on Linux. On Windows, as low as PHP 5.6 is available from the installer, so add them within Tools & Settings → Updates → Add/Remove Components → Plesk hosting feature.
Installing Outdated PHP Versions
Install the software-properties-common package if it isn’t already:
apt-get install software-properties-common
Add the repository that contains older PHP versions:
add-apt-repository ppa:ondrej/php
In this example, we will install PHP 7.2. Replace with your intended version:
apt -y install php7.2
Install your required PHP modules, for example:
apt install -y php7.2-{bcmath,bz2,cli,common,curl,dev,fpm,gd,gmp,imagick,imap,intl,json,mbstring,mysql,opcache,soap,ssh2,xml,xmlrpc,zip}
Lastly, register PHP handler in Plesk. Again, be sure to replace 72 with your intended PHP version:
plesk bin php_handler --add -displayname php72-fpm-custom -path /usr/sbin/php-fpm7.2 -phpini /etc/php/7.2/fpm/php.ini -type fpm -id php72-fpm-custom -clipath /usr/bin/php -service php7.2-fpm -poold /etc/php/7.2/fpm/pool.d
Install required repository management software:
apt install ca-certificates apt-transport-https -y
Add the required GPG key for the sury.org repository:
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
Add the repository to a new APT sources file:
sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" >> /etc/apt/sources.list.d/php_custom.list'
Refresh the repository list:
apt update
In this example, we will install PHP 7.2. Replace with your intended version:
apt -y install php7.2
Install required PHP modules, for example:
apt install -y php7.2-{bcmath,bz2,cli,common,curl,dev,fpm,gd,gmp,imagick,imap,intl,json,mbstring,mysql,opcache,soap,ssh2,xml,xmlrpc,zip}
Lastly, register PHP handler in Plesk. Again, be sure to replace 72 with your intended PHP version:
plesk bin php_handler --add -displayname php72-fpm-custom -path /usr/sbin/php-fpm7.2 -phpini /etc/php/7.2/fpm/php.ini -type fpm -id php72-fpm-custom -clipath /usr/bin/php7.2 -service php7.2-fpm -poold /etc/php/7.2/fpm/pool.d
Install the C compiler and XML library:
yum install gcc -y && yum install libxml2-devel -y
Download the PHP source you require from the official website (https://www.php.net/releases/) on to the server, unpack it, and navigate into the extracted folder:
wget https://www.php.net/distributions/php-7.2.0.tar.gz
tar -xvzf php-7.2.0.tar.gz
cd php7.2.0
Configure about build PHP:
./configure --prefix=/usr/local/php72 --enable-fpm --with-fpm-group=www-data
make
make install
Edit your PHP.ini file and then copy to it to the proper directory:
nano php.ini-development
cp php.ini-development /usr/local/lib/php.ini
Lastly, register PHP handler in Plesk. Again, be sure to replace 72 with your intended PHP version:
plesk bin php_handler --add -displayname php72-fpm-custom -path /usr/sbin/php-fpm7.2 -phpini /etc/php/7.2/fpm/php.ini -type fpm -id php72-fpm-custom -clipath /usr/bin/php7.2 -service php7.2-fpm -poold /etc/php/7.2/fpm/pool.d
Update the Staging Site Scripts
If your website is running behind a Content Management System (CMS) such as WordPress, Joomla, or Drupal, you will want to update the core CMS, and any plugins and themes. This is where things can get sticky.
If you opt for free themes or plugins, the developers will usually only keep it up to date for a certain period of time, when they move on to new things. When they stop updating the theme/plugin, you can consider any newer PHP versions from then on as possibly incompatible.
If you opt for paid themes or plugins, the developers will often provide updates for a fee or subscription. In this case, you should always consider contacting the theme and plugin developers to request information on PHP compatibility.
Update WordPress: Dashboard → Updates
Joomla: Components → Joomla! Update
Drupal: Instructions
Magento: Instructions
TYPO3: Instructions
PrestaShop: Instructions
If you don’t have a CMS and you paid a developer, then you should contact your developer first to inquire about PHP compatibility. Otherwise, you may continue with trying a newer version of PHP on the staging site.
If you update your site and it is broken now, it could be due to requiring a newer version of PHP. That will be our next step.
Test out the new PHP version on the staging site
In Plesk navigate to Domains → your staging subdomain → PHP Settings.
Select the new PHP version from the drop-down list, and opt to run PHP as a FPM application. Click OK.
The moment of truth: Visit the staging site to see how it looks and operates.
- Clear your cache first, to be sure you’re bringing up a fresh pull.
- Visit as many pages and links of your site as you can.
- Login to the backend of your site and check things out.
- Try everything with a secondary browser.
- View everything logged in and logged out as a user/admin.
Keep in mind that you’ll need an SSL installed on the staging subdomain if one is being used on the live site. SSL errors related to an SSL missing on the staging site shouldn’t affect copying back to the live site, but you’re safer bet is installing an SSL on the staging subdomain to be sure.
If everything looks great and you’re feeling confident, you can move on to the next step of copying the staging site back to the live site.
If things don’t look great, here are some tips to help you troubleshoot:
- Try working backwards:
- Use your web browser’s developer tools to look for errors in Console, and for missing files in the Network tab. Look for specific plugins or directories mentioned for hints.
- Deactivate plugins one by one to find a troublemaker. For example, renaming a plugin directory name in WordPress will disable that plugin but allow for reactivation within the admin dashboard.
- Try using a different theme to see if the website will display properly, hinting at theme compatibility issues.
- Try different versions of PHP.
- If your goal is to update to a newer PHP, and you’re jumping up several versions, try moving one version at a time. For example, go from PHP 5.6 to 7.0, rather than jumping right to 8.3.
- Fun fact: There is no PHP 6, so PHP 7.0 is the next version above PHP 5.6.
- If your goal is to update to a newer PHP, and you’re jumping up several versions, try moving one version at a time. For example, go from PHP 5.6 to 7.0, rather than jumping right to 8.3.
- Look at the staging domain logs for errors to indicate at what’s wrong.
- Compare available and enabled PHP modules/extensions on the live site with the working PHP version versus your staging site and newer PHP modules/extensions.
Copy to Live Site
If you are happy with your updates, the last step is to copy over the staging site updates back to the live site. The steps are basically the same as copying from live to staging.
Copying Staging Site To Live Site
Choose the target, over-writing the existing live size. (Make sure you have a backup first!) Click Start.
During the copying process, the live website enters maintenance mode and becomes temporarily unavailable.
Clear your web browser cache, and visit the website on 2+ browsers on 2+ networks (for example, Wifi on laptop and 5G on smartphone), clicking through all links, menus, logging in and out.
If all is well, congratulations! You've just updated PHP!
Choose your live domain. Choosing to delete existing files may be the more secure option. (Make sure you have a backup first!)
Next you will need to copy the database if one exists. Navigate to Domains > staging subdomain > Databases. Click Copy under the database.
Choose to copy to existing database, and choose the correct live site database. Keep the option checked to create a full copy. Click on OK.
Clear your web browser cache, and visit the website on 2+ browsers on 2+ networks (for example, Wifi on laptop and 5G on smartphone), clicking through all links, menus, logging in and out.
If all is well, congratulations! You've just updated PHP!