Apache is downloading php files instead of displaying them
The correct AddType for php is application/x-httpd-php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Also make sure your php module is loaded
LoadModule php5_module modules/mod_php55.so
When you're configuring apache then try to view the page from another browser - I've had days when chrome stubbornly caches the result and it keeps downloading the source code while in another browser it's just fine.
Please take a look at your addtype directives.
It looks to me like Apache is telling the browser that it's sending a document type of application/php for scripts with extensions like .php5. In fact Apache is supposed to tell the browser that the script is outputting text/html.
Please try this:
AddType text/html .php
Regarding the suggestion above that you should tell the browser that you are outputting a PHP script: It seemed like an unusual idea to me. I googled it and found that there is quite a bit of discussion about it on the web. Apparently there are cases where you might want to say that you are sending a PHP script (even though Apache is supposed to execute the script and emit text/html,) and there are also cases where the browser simply doesn't recognize that specific Mime Type.
Clearing your browser cache is always a good idea.
In case it's helpful here's a copy of my /etc/httpd/conf.d/php.conf file from a server running CentOS 5.9:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps
After struggling a lot I finally solved the problem.
If you are prompted to download a .php
file instead of executing it, then here is the perfect solution: I assume that you have installed PHP5 already and still getting this error.
$ sudo su
$ a2enmod php5
This is it.
But If you are still getting the error :
Config file php5.conf not properly enabled: /etc/apache2/mods-enabled/php5.conf is a real file, not touching it
then do the following:
Turns out files shouldn't be stored in mods-enabled
, but should rather be stored in mods-available
. A symlink should then be created in mods-enabled pointing to the file stored in mods-available.
First remove the original:
$ mv /etc/apache2/mods-enabled/php5.conf /etc/apache2/mods-available/
Then create the symbolic link:
$ ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf
I hope your problem is solved.
I came across this issue today and none of the solutions described worked for me. So here is another possible cause:
If you have something like
AddHandler x-mapp-php6 .php3 .php4 .php .phtml
in a .htaccess
file of your web content folder, it can cause your PHP scripts to stop working. In my case the server did not know the x-mapp-php6
type, since that .htaccess
file was something I imported from a different web host when I transferred the website content.
Just removing the AddHandler
line from the .htaccess
file solved it for me.