How to Change the PHP Version of a Website + Things to Consider Before Updating
Hypertext Preprocessor (PHP) is an open-source server-side scripting language widely used for web development. It is also used in popular content management systems (CMS), such as WordPress and Joomla.
Since PHP updates frequently, the default version installed on your web server may be outdated. Therefore, it is crucial to understand how to switch PHP versions to maintain your site’s functionality.
This article will explain why and how to change your site’s PHP version. We will also list the prerequisites and answer commonly asked questions about changing the PHP version.
Download guide to using Hostinger
Why Change PHP Version of Your Site
As an essential part of your website, PHP defines how your web page functions. Depending on your goal, you may upgrade or downgrade to another version of PHP.
A PHP upgrade can bring many benefits to your site, namely:
- Increased security. Due to its popularity, many cybercriminals often exploit PHP to attack a website. Updating PHP applies the newest security patch, protecting your site.
- Performance boost. The newer PHP version is faster and more efficient. According to WordPress, updating PHP can improve your site’s speed by up to 400%.
- New features. A major PHP update usually adds new features. For instance, PHP version 8’s new features include named arguments, union types, and match expression features.
- Improved functionality. Updating your PHP version fixes bugs that may harm your site’s functionality. It also lets you run your updated site code properly.
Meanwhile, you may want to downgrade PHP to an earlier version to fix an incompatibility issue. Sometimes, newer PHP versions can’t properly run older plugins, themes, or site codes.
What to Consider Before Changing the PHP Version
Before switching to a different PHP version, consider the following prerequisites to ensure your site works normally.
Update CMS to the Newest Version
Update your CMS before switching to a different PHP version. Since most CMS are based on PHP, an outdated version may trigger incompatibility issues. These issues may prevent PHP codes from running correctly, harming your site’s functionality.
The steps to check your CMS version may vary. To check your current WordPress version, log in to your site’s wp-admin page and navigate to the sidebar → Dashboard → Updates.
WordPress will display the currently active version and the newest stable release. If your WordPress is up-to-date, it will say, “You have the latest version of WordPress.”
Otherwise, it says, “An updated version of WordPress is available.” Simply press the Update Now button to download and install the latest WordPress version.
Make Sure the Site Code Is Up-To-Date
Your old site code may not execute properly if you use the latest PHP version. This also applies to PHP-based programs, such as WordPress themes and plugins.
To ensure your site works well, update its code, themes, and plugins before upgrading PHP.
There are different ways to check whether your website is compatible with a specific version of PHP. For instance, you can use Hostinger’s WordPress and PHP compatibility checker. This tool examines your site’s core and current PHP version, advising a switch to a compatible version if necessary.
To use the compatibility checker, access your hPanel dashboard and navigate to WordPress → Overview, and locate the PHP Version section. If you’re using a supported PHP version, you will see the following message:
However, you will receive a warning if your website is not compatible with your current PHP version. Click the Change button to update your PHP version to a supported one.
Alternatively, test your website with the new PHP version manually on a local development server. This option lets you check your site’s compatibility with the new PHP version without affecting the live one.
Resolve PHP Errors and Warnings
You may get PHP error messages or warnings even when your site works fine. Unfortunately, these alerts may indicate that your site code may not work with a different PHP version.
If you host your website on Hostinger, you can disable PHP error messages via hPanel. However, you shouldn’t ignore them, especially if your site encounters issues.
These error messages help determine PHP problems, allowing you to fix them quickly. In case of incompatibility, resolve the error by:
- Disable and enable themes and plugins
- Enable the default theme
- Update the site code, plugins, and themes
- Use the default .htaccess file
How to Change PHP Version in hPanel
The simplest way to change your system-wide version of PHP is via your hosting control panel. Aside from switching to different PHP versions, it lets you configure PHP extensions and options. At Hostinger, we use hPanel.
hPanel supports up to PHP 8.2 and will update its support each time a new PHP version is launched. Although we will use hPanel in this tutorial, the following steps should be similar for other hosting control panels like cPanel:
- Log in to hPanel and click Hosting on top of the homepage.
- Click the Manage button next to your domain name.
- On the sidebar, go to Advanced → PHP configuration.
- Select the PHP version you want to use. By default, it only shows supported versions, but you can check Show no longer supported PHP versions to display older ones.
- Click Update to save the changes.
How to Change PHP Version for a Specific Folder or a Subdomain
You can change the PHP version for a specific folder of a subdomain by editing the .htaccess file. This method allows you to use multiple PHP versions on the same account.
In the following tutorial, we will install PHP 8.1 for a subdomain via hPanel:
- Log in to your hPanel and select Hosting.
- Click Manage next to your desired domain.
- Go to Files → File Manager.
- Access the folder whose PHP version you want to change. To edit a subdomain, go to public_html → yoursubdomain folder.
- Double-click on the .htaccess file. If it doesn’t exist, create a new .htaccess file.
- Copy and paste the following command to the beginning of the .htaccess file to install PHP 8.1. To install a different PHP version, change 81 with your desired version number. Read our PHP version change article to view other useful commands.
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp81 </FilesMatch>
- Click the disk icon on the top right corner to save the changes.
Optionally, create a phpinfo.php file to check your PHP settings and version.
To use multiple PHP versions, repeat the steps above for each subdomain or folder.
However, we don’t recommend modifying the .htaccess file to change your PHP version. This method doesn’t include PHP extensions and options, which may affect your site’s functionality.
If you choose this method, consider manually configuring the PHP modules and options by editing the php.ini file.
Conclusion
PHP is a server-side scripting language used for web development. Popular CMSs like WordPress and Joomla are based on PHP.
You may want to switch to a different PHP version for various reasons, such as improving your website’s performance and fixing compatibility issues.
However, changing the PHP version can affect your website’s functionality. Consider the following before switching your PHP version:
- Update your CMS to the newest version
- Renew your site code
- Resolve existing PHP errors or warnings
You can use hPanel or other hosting control panels to change your hosting account’s PHP version. Alternatively, change the PHP version for a specific folder or subdomain by adding a command to your .htaccess file.
Change PHP Version FAQ
This section will answer some of the most commonly asked questions about changing your PHP version. If your question remains unanswered, leave it in the comments section below.
How to Check My PHP Version?
Use your hosting control panel to check the PHP version installed on your site. Since the steps vary across different control panels, always refer to the user manual.
For hPanel users,click the Manage button next to a domain → Advanced → PHP info. If you have a cPanel account, go to Software → Select PHP version.
Which PHP Version Should I Use?
We recommend using the latest PHP stable release that compatible with WordPress to ensure your site runs properly. At the time of writing, it is PHP 8.3.
Since PHP updates frequently, always check the PHP download page before switching.
Can I Downgrade My PHP Version?
Yes, you can downgrade your site’s PHP to any version. But note that downgrading PHP to an older version may cause errors.
The best way to downgrade your PHP version is via your hosting control panel. If you use hPanel, follow our article on downgrading your PHP version.
Comments
January 12 2018
When will you support php 7.2?
January 15 2018
Hey king, Support for PHP 7.2 should be added in near feature. Our devs are already testing it
September 09 2020
I'm just follow these steps, but my wordpress still saying that I use PHP 5.6. Whats wrong ?
November 11 2020
Hey there Gabriel. Make sure to press SAVE on the bottom, and clear your browser cache before checking again. The PHP version should show correctly.
November 19 2020
I followed the steps and everything seems to be working perfectly but when I ssh into the my hosting and check the php version it still shows the old php i had before. Is there a different method for ssh?
February 09 2021
Hi there! You can also use this method of creating a phpinfo file to check the current version of your PHP as well as other PHP settings ;)
January 01 2021
php 8??
February 09 2021
Hi there! System administrators are currently testing PHP version 8, so it should be ready for shared and cloud servers fairly soon!
April 26 2021
Hi! Which PHP versions are available in cPanel ?
May 06 2021
Hi Fred, The cPanel default profile includes PHP versions 7.3, 7.4, and PHP 8. EasyApache 4 supports PHP versions 5.4 through 5.6, PHP versions 7.0 through 7.4, and PHP 8.0. Note that if your server runs CentOS 8, you cannot use PHP 7.1 or earlier.
July 05 2021
My application in the PHP version 5.1, if I move it to the latest then it does not support. Whereas I believe that it should not have problem from lower to higher versions. Please let me know how I can run my applications.
September 16 2021
Hi there! This will depend entirely on the code on your application - if the code is written in a way, which is not compatible with the newer version (often happens with custom code), after updating the PHP version, the app will break. So before updating the PHP version, you'd need to make sure that every piece of the code is compatible with the new version. You can have a look at this article to help you test your code's compatibility with PHP 8.
December 10 2021
How can i change php version for subdomain only?
December 14 2021
Hi Milan, you can use this solution to change PHP version for subdomains :)
January 24 2022
I created a subdomain. But I wanted it to have a different version of PHP. Can I change it without affecting my main one?
January 25 2022
Hi! Yes, you can change it through .htaccess file - as long as it's inside of your subdomain, it will not affect the main domain. Check out this guide on how to change the PHP version for your subdomain :)
March 31 2022
Hello I have a prestashop service that uses PHP 7.1, do you support it, if so until when ???
April 06 2022
Hi Aldo, you can still enable the 7.1 version, though it doesn't get updates anymore, so it's not recommended. If you specifically need it though, you can do it from your hPanel -> PHP Configuration; then select "Show no longer supported PHP versions"
September 05 2022
Do you force customer to move to a newer PHP version? I have a site that currently runs on PHP 7.4. Can you guarantee this remains available even after it is marked as EOL?
September 09 2022
Hey there! We encourage updating the PHP versions for security and website's performance, however if you wish to use an older PHP version, there's no need to worry, as you will still be able to use them even if it becomes outdated ?
March 29 2023
Hi, My site uses a php open source application which only runs on php 7.1. My current host, Ionos, charge for using unsupported php versions, so I would have to upgrade. Therefore, I am thinking of moving over to Hostinger. Do you charge extra for using unsupported php versions? Thanks.
March 31 2023
Hello there! We do not charge extra fees for older PHP versions and allow you to manage PHP Extensions and PHP Options on the go for any of them. You can also run different websites with different PHP versions. At the time of writing this comment, you can choose from PHP 5.2 to PHP 8.1 at Hostinger. You can find more information about PHP versions in this article.
September 19 2023
hey, do you people have an 8.2 PHP version? I have a laravel project which requires a 8.2 PHP version.
September 26 2023
Hello there! Yes we do offer PHP 8.2. We also offer an ability to install Laravael automatically via our auto installer. More information can be found here.
February 29 2024
Late comment but I will assume each website can have its own php version yes ? Thank you.
March 05 2024
Hi there! Yes, typically, each website hosted on a web server can have its own PHP version ?