ubuntu 上的 apache2 - php 文件下载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6245895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
apache2 on ubuntu - php files downloading
提问by shane
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.
我的available-sites
配置工作正常,因为我能够请求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
回答by Paris Liakos
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
回答by Dale E. Moore
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
回答by Anonymous User
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文件。也不必重新启动浏览器。
回答by Znarkus
You need to enable the PHP extension. Do this with the command sudo a2enmod php
.
您需要启用 PHP 扩展。使用命令执行此操作sudo a2enmod php
。
回答by damianb
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.
如果问题仍然存在,请关闭浏览器,重新打开并清除缓存。可能是浏览器只是缓存了页面响应。
回答by alok
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 框。我已经为 7.0 版本安装了 apache php 模块,它解决了我的问题。
sudo apt-get install libapache2-mod-php7.0
须藤 apt-get 安装 libapache2-mod-php7.0