We regularly receive "bug" reports and support requests which are the variation of the following:
I just restored my site. Even though my hosts uses PHP 7.3 my site complains that it's running on PHP 5.4.45. This must be a bug.
Sometimes they might manifest themselves as a variation of this:
I just restored my site and all I can see is a blank page / PHP error.
In both cases the root cause is the same: your host has multiple PHP versions installed on the server and the default PHP version is too old for your site.
Quick fix: go to your hosting control panel and select a newer PHP version for your site.
Keep reading to understand why this happens and what you can do about it.
It's not a bug
The messages about the PHP version do not do anything fancy to detect the PHP version. They simply ask PHP to report its PHP version by reading the PHP_VERSION constant. This constant is defined by PHP itself and it takes its value when PHP was compiled by your host. That is to say, it can never report the "wrong" PHP version. It always reports the exact PHP version your site is running under.
The real problem is that your host has multiple PHP versions installed but the default PHP version used to run your site is very old and not the same as the much newer one reported by your hosting control panel. We understand it's counter-intuitive. It's how your host works which is outside our control. All we can do is explain how things work under the hood and what you can do to fix your sites.
The default PHP version is not necessarily what is reported by the hosting control panel
Most modern hosts have multiple versions of PHP installed in parallel on the server. In our example above a host has both PHP 5.4 and 7.3 installed in parallel.
The hosting control panel (e.g. cPanel or Plesk) will only ever run under the specific PHP version it was designed to run with. In fact, the hosting control panel doesn't run under your hosting account. It's a parallel system to the web server serving your site. When you visit the hosting control panel you see the PHP version the panel runs under in its own isolated web server. It is NOT the PHP version your site runs under.
Without doing anything further, your site runs under the default PHP version your host has selected for your web server. Typically hosts choose an older, obsolete PHP version. It makes business sense for them. Most of their clients will be maintaining old sites which have not been updated in years. By using a veritably antediluvian PHP version as the default they avoid having to provide support to these clients. The web hosting business bases its profitability on marginal cost cuts, after all.
This is, of course, a big problem when you want to run a modern, up-to-date site with modern, up-to-date software that requires a newer PHP version. All of these hosts allow you to select which PHP version your site will run under through their hosting control panel.
How multiple PHP versions are implemented
Most servers supporting multiple PHP versions run under Apache. When you go to your hosting control panel and change the PHP version what really happens is that your site's .htaccess file is edited. Typically, you will see a line starting with AddHandler or SetHandler added to the bottom of the file. Here's an example line from a typical cPanel installation enabling PHP 7.3:
AddHandler application/x-httpd-php73 .php .php5 .php4 .php3
PHP versions per folder (only some hosts)
In many cases you can select a different PHP version for each folder of your site. For example, you can set one version for the root of your site (typically called public_html, htdocs or www) and a different one for Joomla's administrator or WordPress' wp-admin folder. This is implemented by creating / modifying the .htaccess files inside each folder. Please keep that in mind if your public site seems to be running under a different version that your site's administrator backend.
Also note that .htaccess files, therefore the selection of a PHP version applied through a .htaccess file, cascades. This is a fancy way to say that whatever you select in your site's root will be applied to all subdirectories and their subdirectories and so on and so forth. You can override the cascade if you select a different PHP version for a specific folder. For example, if you apply a different PHP version in your administrator directory the setting inherited from the site's root is ignored and overridden by the PHP version selected for the administrator folder. All subdirectories of the administrator folder will use the PHP version specified for the administrator folder itself.
If you find yourself in a situation where you can't understand why different PHP versions are reported in different parts of your site try editing your .htaccess files and remove all AddHandler and SetHandler lines. Then go to your hosting control panel and apply the required PHP version to your site's root.
How PHP versions are handled during restoration
If you are using Akeeba Backup / Solo 7.3.0 or later and Akeeba Kickstart 7.0.1 or later any custom PHP versions will be honoured and applied to your restored site by default.
If you are restoring to a new server you need to go to your hosting control panel and apply the newer PHP version to your site's root right after uploading kickstart.php and your backup archive but before starting the restoration. If you are using the Site Transfer Wizard you need to do that after the wizard tells you it has finished uploading the files and before clicking the button to start the restoration on the new server.
Kickstart and the restoration script inside your backup archive will take note of the AddHandler and SetHandler lines and use them throughout restoration. Moreover, they will apply them to your .htaccess file when you click on the Clean Up button. This way your newer PHP version will be effective even after the restoration is complete.
If you are using an older version of Akeeba Backup and / or Kickstart you will have to apply the newer PHP version after you click the Clean Up button at the end of the restoration process.
PHP versions and third party extensions / plugins such as Admin Tools
There's a number of third party Joomla! extensions and WordPress plugins which can modify the .htaccess file of your site. As a result of these changes the AddHandler / SetHandler lines which set up a newer PHP version on your site may be removed.
On WordPress the .htaccess file is modified, not replaced, one section at a time specific to each plugin. Since the PHP version lines (AddHandler or SetHandler) are placed at the end of the .htaccess file they are not supposed to be touched by any third party plugins. Therefore nothing special is required there.
Joomla doesn't come with a default .htaccess file. Third party extensions can generate a new .htaccess from scratch. One such extension is our Admin Tools for Joomla. If you are using it you need to make a manual change to its configuration if and only if you are using its .htaccess Maker feature.
- First, set the newer PHP version to your site using your hosting control panel.
- Open the .htaccess file in a text editor e.g. using your hosting control panel's file manager.
- Copy the AddHandler line at the bottom of the file.
- Go to Components, Admin Tools and find the “Custom .htaccess rules at the bottom of the file” area.
- Paste the AddHandler line you copied previously into a new line in this area.
- Click on Save & Create .htaccess in the toolbar to apply the change.
This ensures that regenerating your .htaccess file through the .htaccess Maker won't accidentally bump your site back to the server's older, default PHP version.
When restoring the site to a new server you have to follow this procedure again. The custom PHP version AddHandler line may be different on every host or even every server used by the same host.