Apache 虚拟主机不解析 PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9305680/
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
Apache Virtual Host not parsing PHP
提问by user1075581
I decided to enable virtual hosts on my Apache server, and chose to make it port-based.
我决定在我的 Apache 服务器上启用虚拟主机,并选择使其基于端口。
First thing I did, of course, was RTM. I followed the instructions found here. Well, it worked -- kind of. As far as the virtual host running, it does. The content pulled from :80 is different from :8080.
我做的第一件事当然是 RTM。我按照此处找到的说明进行操作。嗯,它奏效了——有点。就运行的虚拟主机而言,它确实如此。从 :80 拉取的内容与 :8080 不同。
But PHP isn't working. The "original site", (port 80) is running PHP just great. The port 8080 site, however, sends the PHP to the browser. I see nothing in the browser, but the source code shows:
但是 PHP 不起作用。“原始站点”(端口 80)运行 PHP 非常好。但是,端口 8080 站点会将 PHP 发送到浏览器。我在浏览器中什么也没看到,但源代码显示:
<?php
echo "It worked!";
?>
This topic seems to be very loosely documented on a few websites, but either I can't find a solution in them, or the solution listed isn't working for me.
这个主题在一些网站上的记录似乎非常松散,但要么我在其中找不到解决方案,要么列出的解决方案对我不起作用。
Again, the virtual host itself is running fine. PHP, on the other hand, is not.
同样,虚拟主机本身运行良好。另一方面,PHP 不是。
Any ideas on what it could be? What content from my httpd.conf file should I provide so I don't blow up my question by copy/pasting the whole thing?
关于它可能是什么的任何想法?我应该提供我的 httpd.conf 文件中的哪些内容,这样我就不会通过复制/粘贴整个内容来破坏我的问题?
(Sorry I forgot to post that I had these in place, Phil. Adding to avoid further confusion)
(对不起,我忘了发帖说我已经准备好了这些,菲尔。添加以避免进一步混淆)
Listen 80
Listen 8080
NameVirtualHost *:80
NameVirtualHost *:8080
<VirtualHost *:80>
ServerName mysite.com
DocumentRoot /var/www/vhosts/Site1/httpdocs
</VirtualHost>
<VirtualHost *:8080>
ServerName mysite.com
DocumentRoot /var/www/vhosts/Site2/httpdocs
</VirtualHost>
I tried adding this inside the tags:
我尝试在标签中添加这个:
AddHandler php5-script .php
AddType text/html .php
...but to no avail.
……但无济于事。
采纳答案by user1075581
This finally put me on the right path:
这终于让我走上了正确的道路:
Here's the solution:
这是解决方案:
In the <Directory>
section, I included these lines:
在本<Directory>
节中,我包含了以下几行:
<IfModule sapi_apache2.c>
php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
Or, a redacted copy/paste of the solution on my server:
或者,在我的服务器上复制/粘贴解决方案:
<Directory "/var/www/vhosts/A2/httpdocs">
<IfModule sapi_apache2.c>
php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
(Other configuration parameters)
</Directory>
回答by Ricky Theil
This could also be due to php files using short php tags <?
instead of <?php
. By default, short tags are not enabled in the php.ini config file.
这也可能是由于 php 文件使用短 php 标签<?
而不是<?php
. 默认情况下,php.ini 配置文件中未启用短标签。
回答by Lazik
Your answer did not work for me.
你的回答对我不起作用。
For Ubuntu 12.04:
对于 Ubuntu 12.04:
sudo a2enmod php5
sudo service apache2 restart
This did it.
source: https://help.ubuntu.com/community/ApacheMySQLPHP
回答by LostMyGlasses
In my case, the problem was fixed by running apt-get install libapache2-mod-php
.
就我而言,问题是通过运行apt-get install libapache2-mod-php
.
This worked for me Mint 18.3 - php7
这对我有用 Mint 18.3 - php7
回答by Edwin Chaidir
In my case it was a default setting in php.conf. It says:
就我而言,它是 php.conf 中的默认设置。它说:
# Running PHP scripts in user directories is disabled by default
Check your php.conf(for PHP 7.1 it's accordingly /etc/apache2/mods-enabled/php7.1.conf) and comment the mentioned lines:
检查您的php.conf(对于 PHP 7.1,它相应地为/etc/apache2/mods-enabled/php7.1.conf)并注释提到的行:
root@zxxxx:/home/pxxx/public_html# vi /etc/apache2/mods-enabled/php5.conf
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
***php_admin_flag engine On*** -> Turn this option ON
</Directory>
</IfModule>
回答by Jesús Carrera
For my configuration I had to add this line to the virtualhost (inside <Directory>
):
对于我的配置,我必须将此行添加到虚拟主机(内部<Directory>
):
AddType application/x-httpd-php .php
回答by Сергей Ходаковский
the only thing that helped me after all tried add apache2.conf
毕竟尝试添加 apache2.conf 的唯一帮助我的东西
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
回答by agaase
Make sure the following line which loads the php module is not commented out -
确保加载 php 模块的以下行没有被注释掉 -
LoadModule php5_module libexec/apache2/libphp5.so
回答by Erik
I'll have to load up a centos vm to check the apache conf but on ubuntu I have a lot more info in my config under the virtualHost
我必须加载一个 centos vm 来检查 apache conf 但在 ubuntu 上,我在 virtualHost 下的配置中有更多信息
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
回答by Tmute
This helped my out a2enmod php5
, if the module does not exist reinstall lamp-server by typing apt-get install lamp-server^
这对我有帮助a2enmod php5
,如果模块不存在,请输入以下命令重新安装灯服务器apt-get install lamp-server^