By Rogers Mukalele / Jun, 23
Have you ever opened a web page on your website, and the page either attempts to download a .php file or it displays the PHP code in the browser? This is bad on multiple levels. First off, your website isn’t functioning properly; even worse is the idea that someone could get a first-hand glimpse of your code, which is not only a frustration, but a possible security issue. This issue can be solved by upgrading your PHP version and adding Apache Handers to serve your PHP files as needed.
This issue has recently been common on many websites running a deprecated version of PHP. Recently, PHP version 7.1 got obsolete and now it is advisable to upgrade to atleast PHP version 7.2 for better performance and security.
MultiPHP tool in your cPanel enables you to switch between multiple versions of PHP on your server at the same time. To do this, follow these steps:
Apache is the service that processes and serves the files for your website to its visitors. The Apache handlers control what action should Apache take when it processes a particular file type. This means that you could use a handler to instruct the service to process files with certain extensions as a specific file type. For example, you can create a handler to instruct Apache to process files with .php extensions as php scripts. See more examples of Apache Handlers here. This is useful when you are using extensions for the files of your website that are not defined how to be handled by Apache, or when you want to use custom file extensions and need to ensure they are processed correctly.
In cPanel, you can use the Apache Handlers tool to add Apache Handlers:
Add the following handlers by typing in the type and the extension:
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
Watch Video below for an idea how to do it:
Alternatively, to create a custom Apache handler you can add the following line in a file named .htaccess located where the files for your website are located (under public_html). In cPanel, be sure to enable display of hidden files to see it.
AddHandler handler .extension