问题
I recently configured php7 on Ubuntu 14.04 by following blog http://www.zimuel.it/install-php-7 and I installed it successfully as per blog. but when try to run the php file (/var/www/test.php) then it is downloaded instead of executing. I have no idea what configuration I missed. and when I entered localhost in browser then it comes with response "it works".
回答1:
(Edit) I had a similar problem that first looked like that Apache randomly showed me correct data and sometimes gave me a download option. It showed up that it was completely different processes that competed about answering to port 80. Killing everything alive fixed that problem and this has actually very little to do with the real problem. So the rows below actually solved the download-problem for me, at last.
LoadModule php7_module modules/libphp7.so
AddHandler php7-script .php
AddType application/x-httpd-php-source .phps
AddHandler application/x-httpd-php .phps
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .php
回答2:
You need to enable PHP under Apache, like so:
sudo a2dismod php5
sudo service apache2 restart
sudo cp /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php7.conf
sudo service apache2 restart
From: http://www.hashbangcode.com/blog/compiling-and-installing-php7-ubuntu
回答3:
I was having the same issue on my Ubuntu 18.04. I fixed the issue by performing the following steps.
Step 1:
Check if php7 module is present in /etc/apache2/mods-available
. If there are files like php7.conf
and php7.load
perform step 3, else go to the next step.
Step 2:
Download the php7 module for apache. I had php7.2 installed so I installed the module by doing sudo apt-get install libapache2-mod-php7.2
. You can replace the php version in your command with the one you have installed.
Step 3:
Enable the apache module. sudo a2enmod php7.2
in my case.
Step 4:
Restart apache server by doing sudo service apache2 restart
.
回答4:
In your apache configuration in /etc/apache2/sites-available try to remove this lines with comments:
#RemoveHandler .php
#RemoveHandler .php7.0
#php_admin_value engine Off
来源:https://stackoverflow.com/questions/34244798/php-7-file-is-downloaded-instead-instead-of-executing