简体   繁体   English

Apache 虚拟主机不解析 PHP

[英]Apache Virtual Host not parsing PHP

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.我做的第一件事当然是 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.从 :80 拉取的内容与 :8080 不同。

But PHP isn't working.但是 PHP 不起作用。 The "original site", (port 80) is running PHP just great. “原始站点”(端口 80)运行 PHP 非常好。 The port 8080 site, however, sends the PHP to the browser.但是,端口 8080 站点会将 PHP 发送到浏览器。 I see nothing in the browser, but the source code shows:我在浏览器中什么也没看到,但源代码显示:

<?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. ……但无济于事。

This could also be due to php files using short php tags <?这也可能是由于 php 文件使用了短的 php 标签<? instead of <?php .而不是<?php By default, short tags are not enabled in the php.ini config file.默认情况下,php.ini 配置文件中未启用短标签。

This finally put me on the right path:这终于让我走上了正确的道路:

http://www.linuxquestions.org/questions/linux-server-73/php-not-working-on-one-vhost-but-works-on-all-others-851093/ http://www.linuxquestions.org/questions/linux-server-73/php-not-working-on-one-vhost-but-works-on-all-others-851093/

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>

就我而言,问题是通过运行以下命令解决的:

apt-get install libapache2-mod-php

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来源: https : //help.ubuntu.com/community/ApacheMySQLPHP

In my case it was a default setting in php.conf.就我而言,它是 php.conf 中的默认设置。 It says:它说:

# 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>

对于我的配置,我必须将此行添加到虚拟主机(在<Directory> ):

AddType application/x-httpd-php .php

确保加载 php 模块的以下行没有被注释掉 -

LoadModule php5_module libexec/apache2/libphp5.so

the only thing that helped me after all tried add apache2.conf毕竟尝试添加 apache2.conf 的唯一帮助我的东西

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

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>

这对我的a2enmod php5帮助,如果模块不存在,则通过键入apt-get install lamp-server^

此命令在 GNU/Linux 4.4.0-105-generic x86_64 上运行良好

apt-get install libapache2-mod-php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM