ubuntu上的apache2 - php文件下载

时间:2022-10-05 18:59:02

On my new Ubuntu system, I've managed to get Apache2 up and running for developing my ZendFramework Web Applications...

在我的新Ubuntu系统上,我设法启动并运行Apache2以开发我的ZendFramework Web应用程序......

I've got my available-sites config working correctly because I am able to request localhost and it servers up the correct index.html from my specified directory.

我的可用站点配置正常工作,因为我能够请求localhost并从我指定的目录中提供正确的index.html。

Problem : if I request index.php, firefox attempts to download the file instead of running the script.

问题:如果我请求index.php,firefox会尝试下载文件而不是运行脚本。

Any Ideas why this would happen?

任何想法为什么会这样?

I've added the following to httpd.conf but it hasn't helped.

我已经将以下内容添加到httpd.conf但它没有帮助。

AddHandler application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml

AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml

6 个解决方案

#1


67  

if firefox downloads your php files it means that your server doesnt have php or the apache php module installed.

如果firefox下载你的php文件,这意味着你的服务器没有安装php或apache php模块。

have you install apache php module? if not, then install it, by typing this into a terminal:

你安装apache php模块吗?如果没有,那么通过在终端中键入它来安装它:

sudo apt-get install libapache2-mod-php5

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

如果是的话,你的index.php是否位于/ var / www /?

Make sure to enable php with the command

确保使用该命令启用php

sudo a2enmod php5

#2


12  

If you are using userdir (http://localhost/~user/phpinfo.php) you will want to:

如果您使用userdir(http://localhost/~user/phpinfo.php),您将需要:

vi /etc/apache2/mods-enabled/php5.conf

Change

更改

<IfModule mod_userdir.c>
   <Directory /home/*/public_html>
       php_admin_value engine Off
   </Directory>
</IfModule>

to comment the php_admin_value

评论php_admin_value

<IfModule mod_userdir.c>
   <Directory /home/*/public_html>
       #php_admin_value engine Off
   </Directory>
</IfModule>

then

然后

service apache2 restart

#3


4  

For me, the solution was to create the following 2 symbolic links:

对我来说,解决方案是创建以下2个符号链接:

ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf
ln -s /etc/apache2/mods-available/php5.load /etc/apache2/mods-enabled/php5.load

and to restart Apache:

并重新启动Apache:

/etc/init.d/apache2 restart

Hitting the http://my_server/test.php file, which has contents:

点击http://my_server/test.php文件,其中包含以下内容:

<?php
   phpinfo();
?>

came right up, and the browser didn't try to download the php file. Didn't have to restart the browser, either.

来了,浏览器没有尝试下载php文件。也没有重启浏览器。

#4


3  

You need to enable the PHP extension. Do this with the command sudo a2enmod php.

您需要启用PHP扩展。使用命令sudo a2enmod php执行此操作。

#5


2  

I'll assume you installed PHP already and installed the PHP module for Apache here...

我假设你已经安装了PHP并在这里为Apache安装了PHP模块......

Did you restart apache? If not: sudo service apache2 restart

你重启了apache吗?如果没有:sudo service apache2 restart

Make sure that your httpd.conf file is also being executed. If necessary, restart it after making an edit that would cause an error on load. If it doesn't fail to restart, it's not running the .conf file.

确保您的httpd.conf文件也在执行中。如有必要,在进行可能导致加载错误的编辑后重新启动它。如果它没有重新启动,则它没有运行.conf文件。

If the problem still continues, close your browser, reopen it, and clear your cache. It might be the browser just caching the page response.

如果问题仍然存在,请关闭浏览器,重新打开并清除缓存。它可能是浏览器只是缓存页面响应。

#6


0  

I have installed php 7.0 and getting the dailog box. I have installed apache php module for 7.0 version and it fix my problem.

我已经安装了php 7.0并获得了dailog box。我已经为7.0版本安装了apache php模块,它解决了我的问题。

sudo apt-get install libapache2-mod-php7.0

sudo apt-get install libapache2-mod-php7.0

#1


67  

if firefox downloads your php files it means that your server doesnt have php or the apache php module installed.

如果firefox下载你的php文件,这意味着你的服务器没有安装php或apache php模块。

have you install apache php module? if not, then install it, by typing this into a terminal:

你安装apache php模块吗?如果没有,那么通过在终端中键入它来安装它:

sudo apt-get install libapache2-mod-php5

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

如果是的话,你的index.php是否位于/ var / www /?

Make sure to enable php with the command

确保使用该命令启用php

sudo a2enmod php5

#2


12  

If you are using userdir (http://localhost/~user/phpinfo.php) you will want to:

如果您使用userdir(http://localhost/~user/phpinfo.php),您将需要:

vi /etc/apache2/mods-enabled/php5.conf

Change

更改

<IfModule mod_userdir.c>
   <Directory /home/*/public_html>
       php_admin_value engine Off
   </Directory>
</IfModule>

to comment the php_admin_value

评论php_admin_value

<IfModule mod_userdir.c>
   <Directory /home/*/public_html>
       #php_admin_value engine Off
   </Directory>
</IfModule>

then

然后

service apache2 restart

#3


4  

For me, the solution was to create the following 2 symbolic links:

对我来说,解决方案是创建以下2个符号链接:

ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf
ln -s /etc/apache2/mods-available/php5.load /etc/apache2/mods-enabled/php5.load

and to restart Apache:

并重新启动Apache:

/etc/init.d/apache2 restart

Hitting the http://my_server/test.php file, which has contents:

点击http://my_server/test.php文件,其中包含以下内容:

<?php
   phpinfo();
?>

came right up, and the browser didn't try to download the php file. Didn't have to restart the browser, either.

来了,浏览器没有尝试下载php文件。也没有重启浏览器。

#4


3  

You need to enable the PHP extension. Do this with the command sudo a2enmod php.

您需要启用PHP扩展。使用命令sudo a2enmod php执行此操作。

#5


2  

I'll assume you installed PHP already and installed the PHP module for Apache here...

我假设你已经安装了PHP并在这里为Apache安装了PHP模块......

Did you restart apache? If not: sudo service apache2 restart

你重启了apache吗?如果没有:sudo service apache2 restart

Make sure that your httpd.conf file is also being executed. If necessary, restart it after making an edit that would cause an error on load. If it doesn't fail to restart, it's not running the .conf file.

确保您的httpd.conf文件也在执行中。如有必要,在进行可能导致加载错误的编辑后重新启动它。如果它没有重新启动,则它没有运行.conf文件。

If the problem still continues, close your browser, reopen it, and clear your cache. It might be the browser just caching the page response.

如果问题仍然存在,请关闭浏览器,重新打开并清除缓存。它可能是浏览器只是缓存页面响应。

#6


0  

I have installed php 7.0 and getting the dailog box. I have installed apache php module for 7.0 version and it fix my problem.

我已经安装了php 7.0并获得了dailog box。我已经为7.0版本安装了apache php模块,它解决了我的问题。

sudo apt-get install libapache2-mod-php7.0

sudo apt-get install libapache2-mod-php7.0