Apache2 on Ubuntu - PHP Files Downloading

apache2 on ubuntu - php files downloading

If Firefox downloads your PHP files it means that your server doesn't have PHP or the Apache PHP module installed.

Have you installed the Apache PHP module?
If not then install it by typing this into a terminal:

sudo apt-get install libapache2-mod-php5

And if yes, do you have your index.php located in /var/www/?

Make sure to enable PHP with the command

sudo a2enmod php5

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

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.

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

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



Related Topics



Leave a reply



Submit