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 beAddHandler
instead ofAddType
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
Get the Metadata of an Order Item in Woocommerce 3
Fatal Error: Call to Undefined Function Pg_Connect()
Generate Download File Link in PHP
Sending Data Using Post in Python to PHP
How to Add a Watermark to an Existing PDF File Using PHP
Remove Zero Values from a PHP Array
Allow Cross Domain Ajax Requests
Utf-8 Problems While Reading CSV File with Fgetcsv
Difference Between Require and Install VS Create-Project in Composer
How to Fix Warning from Date() in PHP"
Google API How to Connect to Receive Values from Spreadsheet
Interview Question: in PHP, Is 123==0123
Show Hide Div If, If Statement Is True
How to Return Custom Error Message from Controller Method Validation
Add a Fee to Woocommerce Per Product, Based on Category
[PHP Warning: Mail(): " Sendmail_From" Not Set in PHP.Ini or Custom "From:" Header Missing