Apache Is Downloading PHP Files Instead of Displaying Them

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.

Apache is downloading php files instead of execute them

You should not set the Content-Type to application/x-httpd-php.

Instead, remove that header.

And use this:

AddHandler application/x-httpd-php .php

If you use PHP-FPM. then let me know, because the above won't work for PHP-FPM.

Edit:

Remove:

AddType application/x-httpd-php .php

Or change it to:

AddType text/html .php

The problem is:

  • application/x-httpd-php is not a MIME type, but rather a handler. That means your directive must be AddHandler instead of AddType

LAMP: PHP not working (keeps downloading source file instead of displaying the page)

It turned out LAMP was using nginx instead of Apache... problem solved here

Apache2 server not displaying php file, only downloading it

I've got a few Ubuntu 16.04 servers. They mostly work with little effort. I'm going to post my install commands, just so you can compare with what you did:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2 apache2-utils
sudo apt-get install mariadb-server mariadb-client
sudo apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl libapache2-mod-php7.0
sudo systemctl restart apache2

# modify dir.conf so index.php is the preferred file
sudo nano /etc/apache2/mods-enabled/dir.conf


Related Topics



Leave a reply



Submit