How to change the PHP version in cPanel
John Mwaniki / Updated on 07 Jul 2024PHP is a widely used server-side programming language for web development. According to W3Techs, 78.9% of all websites run on PHP as of the time of writing this article.
PHP was originally created in 1994 by Rasmus Lerdorf, a Danish-Canadian programmer.
The initials originally stood for "Personal Home Page", but later changed to represent recursive initialism for Hypertext Preprocessor.
In 1995, Rasmus made PHP open-source by releasing its source code to the public. This allowed developers to use it on their websites, fix bugs that occurred in the code, and generally improve upon it.
The reference for PHP implementation is now produced and maintained by The PHP Group.
Since its inception to this date, the PHP language has gone through lots of improvements and fixes, with each update making it better and more efficient.
A set of new updates and fixes is referred to as a version.
Each release version is fully supported for two years from its initial stable release. During this period, bugs and security issues that have been reported are fixed and are released in regular point releases.
After the 2 years period of active support, the version is then supported for one more year for critical security issues only. The number of releases depends on the number of issues reported, where they can be multiple or none.
Once the 3 years of support are completed, the version reaches the end of its life and is no longer supported by The PHP Development Team.
Here are the currently supported PHP versions.
Below is a visualization of versions release and support in form of a calendar.
The official PHP website strongly urges the developers to upgrade to a current version, as using older versions may expose websites to security vulnerabilities and bugs that have been fixed in more recent versions of PHP.
Why you should update PHP version
Below are some of the most important reasons why you should update the PHP version for your website to the current version.
1. Security
This is the most important of all the reasons. The older versions are no longer supported for bug fixes and security updates. The websites using those outdated versions run a risk of being compromised by attackers.
2. Performance
New PHP versions are significantly faster than the previous versions and with less memory usage and fast execution times.
3. New features and improvements
Newer versions come with new features and improvements of various aspects, which in turn increases performance and effectiveness.
4. Support
As new versions are released and the older ones becoming deprecated, so do the web developers adapt to the newer ones and stop supporting the older versions.
For instance, if your website is built in WordPress, you rely on themes and plugins built by other developers. Over time, they will stop supporting those built with older PHP versions and upgrade. If you don't update to a newer version, then your website will be vulnerable to bugs and attacks with no support guaranteed.
How to change the PHP version for your site in cPanel
There are three different methods by which you can update your PHP version.
- MultiPHP Manager
- PHP selector
- Using .htaccess file
Method 1: MultiPHP Manager
Step 1: Log in to your cPanel account
Step 2: Click on "MultiPHP Manager" under the Software section
Step 3: Check/tick the checkbox(es) for all the domain names and subdomains for which the version change you would want to affect.
If you have multiple domains or subdomains and you want to apply the change to all of them, check/tick the box at the top of the table on the left column.
The next step is the select your preferred PHP version at the top of the table on the right side, then click on the "Apply" button.
It may take a minute or few seconds for the changes to apply, then you will see a success message as below.
Method 2: PHP selector
Step 1: Log in to cPanel account
Step 2: Click on "Select PHP version" under the software section.
You will be able to see the current PHP version as below:
Step 3: Select from the current PHP version dropdown your preferred version.
Step 4: Click on the "Set as current" button to apply the changes.
The changes will apply and you will be able to see the version you selected set as the current version.
Method 3: Using the .htaccess file
The .htaccess (in full Hypertext Access) file is a directory-level configuration file that is supported by Apache-based web servers for doing various server configurations to the directory where it is placed, and all its subdirectories.
You can update the PHP version of the whole website, or for a specific directory using the .htaccess file.
Just browse through your cPanel file manager and create a file with the name .htaccess. The .htaccess file is a hidden file, so you may not be able to see it by default. You will need to first show hidden files in the file manager in order to see the file when you create it or to see whether there already exists one.
Open/edit the .htaccess file and add the following lines to it:
<IfModule mime_module>
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
The above lines sets the PHP version to 7.4. Note that we have not included a dot(.) between 7 and 4. Also notice we have not included the 4 after the second version.
To set the version to 8.0, we do it as below.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php80 .php .php8 .phtml
</IfModule>
Click on the Save button at the top-right corner for the changes to take effect. The PHP version set in the .htaccess file will apply to all PHP files in the directory it is placed and all its subdirectories.
Conclusion
In this article, we have covered in detail what PHP versions are, why updating to a supported version is very important, and the three different ways in which you can update it by yourself.
If you would want to get notified when we add new incredible and impactful content, feel free to subscribe to our email newsletter to get notified directly into your email. Cheers!