[英]apache2 on ubuntu - php files downloading
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
If Firefox downloads your PHP files it means that your server doesn't have PHP or the Apache PHP module installed. 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?您是否安装了 Apache PHP 模块? 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/
?如果是,您的 index.php 是否位于
/var/www/
?
Make sure to enable PHP with the command确保使用命令启用 PHP
sudo a2enmod php5
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
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.来了,浏览器没有尝试下载 php 文件。 Didn't have to restart the browser, either.
也不必重新启动浏览器。
You need to enable the PHP extension.您需要启用 PHP 扩展。 Do this with the command
sudo a2enmod php
.使用命令
sudo a2enmod php
执行此操作。
I'll assume you installed PHP already and installed the PHP module for Apache here...我假设您已经安装了 PHP 并在此处为 Apache 安装了 PHP 模块...
Did you restart apache?你重启apache了吗? If not:
sudo service apache2 restart
如果没有:
sudo service apache2 restart
Make sure that your httpd.conf file is also being executed.确保您的 httpd.conf 文件也在执行中。 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.
如果它没有重新启动失败,则它没有运行 .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.
可能只是浏览器缓存了页面响应。
I have installed php 7.0 and getting the dailog box.我已经安装了 php 7.0 并获得了对话框。 I have installed apache php module for 7.0 version and it fix my problem.
我已经为 7.0 版本安装了 apache php 模块,它解决了我的问题。
sudo apt-get install libapache2-mod-php7.0 sudo apt-get install libapache2-mod-php7.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.