Recently one of my friends encountered the issue with his blog that WordPress download file instead of opening in browser and there was no proper post on google on how to solve this issue.
If you are also having issues such as while opening your website, it’s downloading a file named download or index.php instead of opening your site then these fixes will resolve your issue.
So I am sharing all the possible methods, which are useful in solving this issue.
WordPress Download File Instead of Opening In Browser
There are various reasons which can cause this issue. There are usually 2 main reasons behind this issue. Either you have a cache plugin that caused this issue or else you have some codes in your .htaccess file which may have caused this issue.
To fix this issue, we will follow 4 steps, which will help you to overcome this situation and you will be again able to use your blog without any kind of problem.
Solution for fixing WordPress Download File Instead of Opening Site
Just follow each of the steps carefully and your problem will be fixed in no time.
1. Update Your Server
If you are using a cloud or a VPS (Virtual Private Network), then you first need to update your system properly and then restart your server.
You need to login to your server SSH using any terminal. If you are a Windows user then you can use Putty for login into your SSH. and for MAC users you can easily use your terminal to log in to SSH. Login to SSH as the root user or if you don’t have the root then you need to use sudo root to execute the given commands.
If you are using a Debian-based System such as Ubuntu then run the command given below.
apt-get -y update && apt-get -y upgrade
If you are on any Red Hat Enterprises System such as Centos then run the command given below.
yum -y update && yum -y upgrade
After executing the commands simply reboot your system and check if the problem persists or not.
To reboot your system type the command given below in any of the OS.
reboot
If you are not sure about the operating system of your system, you can run both of the commands to check which one works for you.
2. Uninstalled Any Cache Plugin
If updating your system, doesn’t helps you to solve your issue. Then you might need to check if you have any cache plugins installed in your WordPress.
If you are using any of the cache plugins such as WP Super Cache, WP Rocket, W3 Total Cache, etc then you need to deactivate them and then check if the issue exists or not.
The wordpress admin panel is usually accessible even after this issue, If your admin panel is also causing the same issue, then you need to remove the plugins manually from the file manager or from SSH.
If it solves your issue, then you need to check or ask in the forum of the respected plugin for the solution or you can try any other plugin for the cache.
If this still not solves your issue, then enable your cache plugin again and move to the next method.
3. Remove addHandler Code your .htaccess File
If you are on apache based server then you need to remove any addHandler code from your .htaccess file.
If you are having a panel to access your wordpress files, then edit your .htaccess directly or else you can use your SSH to edit directly.
Eg, of addHandler codes
- AddHandler application/x-httpd-php4 .php
- AddHandler application/x-httpd-php5 .php
- AddHandler application/x-httpd-php51 .php
- AddHandler application/x-httpd-php52 .php
- AddHandler application/x-httpd-php53 .php
- AddHandler application/x-httpd-php54 .php
- AddHandler application/x-httpd-php55 .php
- AddHandler application/x-httpd-php56 .php
- AddHandler application/x-httpd-php7 .php
- AddHandler application/x-httpd-php71 .php
- AddHandler application/x-httpd-php72 .php
- AddHandler application/x-httpd-php73 .php
- AddHandler application/x-httpd-php74 .php
If you have any of these lines in your .htaccess file or any other resembling the above one, then you need to delete them from your .htaccess file and then check if you problem is solved or not.
4. Replace complete .htaccess File
If your problem is not solved, then delete all the given codes in htaccess and replace it with the wordpress default htaccess file.
Copy and paste the WordPress Default htaccess file.
# 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
Save the file with the given code and check if your problem is solved or not.
If the problem is still there, then you might need to install wordpress from the scratch.
5. Reinstalling The WordPress
Reinstalling the wordpress is the last step to solve this problem. This problem usually occurs at the frontend so you might be able to access the wordpress admin panel normally. If so, the case then takes the full backup using a backup plugin such as UpdraftPlus.
After successfully backup just delete everything and reinstall a fresh copy of wordpress and restore your backup from UpdraftPlus.
Conclusion
So if you are also here due to your PHP file is downloading instead of executing, then I hope you have found your solution. This issue is more common with WordPress due to various plugins.
This problem is due to a mismatch of the PHP version of your system with that mention in the .htaccess or due to some missing system updates.
This is easy to solve the issue in no time. If you don’t want to encounter such errors again, then always keep your system up to date and use only the official plugins for WordPress.