首先,我的虚拟主机示例在不将嵌入index.html的情况下工作。
Apache在我使用的同一台机器上。PHP在这台机器上是可用的两倍。
$ which php
/usr/bin/php
$ which php7.0
/usr/bin/php7.0此外:libapache2-mod-php7.0已经安装好了。
我到现在为止所做的事:
$ sudo mkdir /var/www/www.virtualhost.com/
$ cd /var/www/www.virtualhost.com/
$ sudo cat > index.html
My virtualhost
PHP Test:
ctrl+d
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-availble/virtualhost.com.conf编辑了我的virtualhost.com.conf文件后,看起来如下所示:
ServerName www.virtualhost.com
ServerAlias virtualhost.com
ServerAdmin webmaster@virtualhost.com
DocumentRoot /var/www/www.virtualhost.com
DirectoryIndex index.html index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Options +Indexes -FollowSymlinks
AllowOverride None
#Include conf-available/serve-cgi-bin.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet然后我启用了我的站点,在我的/etc/hosts文件中输入了一个条目,并使用以下命令重新启动了apache2:
$ sudo a2ensite virtualhost.com.conf
$ sudo apache2ctl restart我的/etc/hosts中的新条目是:
127.0.0.1 www.testhost.com
127.0.0.1 www.virtualhost.com启动了以下模块:
$ a2query -m
authz_host (enabled by maintainer script)
proxy_fcgi (enabled by site administrator)
socache_shmcb (enabled by site administrator)
negotiation (enabled by maintainer script)
filter (enabled by maintainer script)
access_compat (enabled by maintainer script)
authz_core (enabled by maintainer script)
deflate (enabled by maintainer script)
authn_file (enabled by maintainer script)
php7.0 (enabled by maintainer script)
authz_user (enabled by maintainer script)
authnz_fcgi (enabled by site administrator)
mime (enabled by maintainer script)
proxy (enabled by site administrator)
mpm_prefork (enabled by site administrator)
dir (enabled by maintainer script)
alias (enabled by maintainer script)
auth_basic (enabled by maintainer script)
setenvif (enabled by maintainer script)
cgi (enabled by site administrator)
env (enabled by maintainer script)
autoindex (enabled by maintainer script)
authn_core (enabled by maintainer script)
status (enabled by maintainer script)
ssl (enabled by site administrator)如果没有中的行index.html,站点就能正常工作。但是如果我嵌入这一行,php的echo就不是回显了。
我需要像这样的
LoadModule php7_module modules/libphp7.so在我的/etc/apache2/apache2.conf里?
任何解决这个问题的暗示都是受欢迎的。
发布于 2019-08-02 01:21:57
为了执行文件中嵌入的PHP代码,实际需要通过PHP解释器运行该文件。默认情况下,只有以.php结尾的文件(以及其他几个文件扩展名)才会通过PHP解释器发送,因为默认情况下通过PHP解释器发送所有文件会降低性能,并且在某些情况下可能会导致安全性或功能问题。
为了让您的add服务器通过PHP解释器发送以.html结尾的所有文件,您应该在vhost配置中添加以下行:
AddHandler application/x-httpd-php70 .htmlhttps://serverfault.com/questions/975748
复制相似问题