My website is downloading php files instead of loading them

Sometimes with plugins or changes in hosting there can be oddball commands that break the standard functionality of your hosting and how the php files are handled.

Usually this is an issue with the .htaccess files in that or the directory above the website folder. We will be going into the file manager and looking at the .htaccess file.

PHP can be fickle and with conflicting commands you can get unexpected results.

The example I have is from the Media Temple transition from GRID to cPanel shared hosting. The website was downloading the pages instead of actually running the files and showing the content.

First we need to look at the structure of the files. Generally the domain folders are nested in the public_html folder of cPanel. However when Media Temple moved the files over they stashed everything in the “domains” folder in the root.

So I start in the “domains” folder and we have our individual website directories. From there we pick a site folder.

I have created this “samplesite.com” for you as a mock-up. Then we open the website folder.

In the domain directory we have some infrastructure stuff. I leave the “cgi-bin” alone. That’s fine. However when we check out the .htaccess file… you see some extra stuff in there…

This probably isn’t needed if you site is WordPress or updated regularly. The old coding references have long been replaced so this is just adding confusion for the system. We will disable the .htaccess within the domain folder.

There… no more complication about the domain level .htaccess file.

Next we inspect the .htaccess file within the site files of the html folder.

Yes, I know my html folder is blank but this is a mock-up and I’m not going to show you how my actual hosting is structured (mitigate exposure.)

After we edit the .htaccess file we get this.

AddHandler php-stable .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# BEGIN (mt) controlled settings
AddHandler php-latest .php
# END (mt) controlled settings

You can see that there are some additional “addhandler” commands that look like they are modifying how the system manages the PHP functions. Both line 1 and line 15 have “addhandler” script that is modifying how the PHP handles your files.

So let’s just remove these extra overrides as well. Just add “#” in front of the lines.

#AddHandler php-stable .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# BEGIN (mt) controlled settings
#AddHandler php-latest .php
# END (mt) controlled settings

Now that we’ve gotten rid of any higher level .htaccess commands as well as commented out the active “addhandler” lines your PHP files should behave as you expect.

Make sure you clear your site cache, firewall cache, DNS cache and refresh your site. The pages should load just fine.