首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ubuntu16.04下的虚拟主机上为apache2启用php7.0?

问如何在ubuntu16.04下的虚拟主机上为apache2启用php7.0?
EN

Server Fault用户
提问于 2019-07-18 13:01:40
回答 1查看 1K关注 0票数 0

首先,我的虚拟主机示例在不将嵌入index.html的情况下工作。

Apache在我使用的同一台机器上。PHP在这台机器上是可用的两倍。

代码语言:javascript
复制
$ which php
/usr/bin/php
$ which php7.0 
/usr/bin/php7.0

此外:libapache2-mod-php7.0已经安装好了。

我到现在为止所做的事:

代码语言:javascript
复制
$ 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文件后,看起来如下所示:

代码语言:javascript
复制
    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:

代码语言:javascript
复制
$ sudo a2ensite virtualhost.com.conf
$ sudo apache2ctl restart

我的/etc/hosts中的新条目是:

代码语言:javascript
复制
127.0.0.1       www.testhost.com    
127.0.0.1       www.virtualhost.com

启动了以下模块:

代码语言:javascript
复制
$ 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就不是回显了。

我需要像这样的

代码语言:javascript
复制
LoadModule php7_module modules/libphp7.so

在我的/etc/apache2/apache2.conf里?

任何解决这个问题的暗示都是受欢迎的。

EN

回答 1

Server Fault用户

发布于 2019-08-02 01:21:57

为了执行文件中嵌入的PHP代码,实际需要通过PHP解释器运行该文件。默认情况下,只有以.php结尾的文件(以及其他几个文件扩展名)才会通过PHP解释器发送,因为默认情况下通过PHP解释器发送所有文件会降低性能,并且在某些情况下可能会导致安全性或功能问题。

为了让您的add服务器通过PHP解释器发送以.html结尾的所有文件,您应该在vhost配置中添加以下行:

代码语言:javascript
复制
AddHandler application/x-httpd-php70 .html
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/975748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档