Why is my php file downloading instead of running?

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.

CHANGING THE PHP VERSION

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:

  • Log in to cPanel
  • In the SOFTWARE section of the cPanel home screen, click MultiPHP Manager:
Why is my php file downloading instead of running?
Click on the MultiPHP Manager
  • Under System PHP Version, cPanel displays the default PHP version for your server. Any domain that does not have a PHP version explicitly set uses this version.
  • To change the PHP version for a domain, under Set PHP Version per Domain, select the check box next to the domain for which you want to change the PHP version:
  • In the PHP Version list box, select the PHP version you want to use for the domain, and then click Apply:
  • The new PHP version for the domain takes effect immediately.

ADDING APACHE HANDLERS

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:

Why is my php file downloading instead of running?
Apache Handlers Tool under the ‘Advanced’ section

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

  1. Community Forum
  2. Community Support
  3. Server Management
  4. Server Analytics
  5. Questions

PHP files downloading instead of executing.

Why is my php file downloading instead of running?

My account was recently downgraded from a dedicated account to a VPS account. I've just discovered that the primary domain on my account (circa75.co) is having issues with with PHP files. Instead of PHP files executing, they are downloading. I've uploaded a test index.php file for testing purposes.

Duplicates 1

index.php downloading instead of opening in browser

My website is working fine, apart from the fact that when ever I try to open domain/rss instead of the browser opening the feed, it tries to download it.


I tried fixing it by altering .htaccess, but that didn't seem to work.


Has something changed on the server side that would account for this problem?


Chris

Confirm

Why PHP script is not running in browser?

PHP is not intended for execution in a browser. It is for web servers to execute, or other preprocessing on the PHP-installed computer. PHP runs in several incarnations when installed on a computer: from the command line.

How do I fix WordPress download Index PHP instead of opening?

Whenever someone opens his website, a file named “index..
Update Your Server..
Uninstall Cache Plugin from WordPress..
Remove addHandler Code to your .htaccess File..
Replace Complete .htaccess File..
Change Hosting Provider..

How do I run a PHP file?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

Do PHP files need to be executable?

php with a shebang line it will need to be executable. If you specify the interpreter (ie. php) it's the interpreter that needs to be able to execute code, so in this case it only needs to be able to read the code.