우분투 16.04의 가상 호스트에서 apache2에 대해 php7.0을 활성화하는 방법은 무엇입니까?

우분투 16.04의 가상 호스트에서 apache2에 대해 php7.0을 활성화하는 방법은 무엇입니까?

우선, 가상 호스트에 대한 나의 예 <? php echo 'Hello World'; ?>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
<html>
    <body>
        <h1>My virtualhost</h1>
        PHP Test:<br>
        <?php echo "PHP"; ?>
    </body>
</html>
ctrl+d
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-availble/virtualhost.com.conf

virtualhost.com.conf파일을 편집한 후의 모습은 다음과 같습니다.

<VirtualHost *:80>

    ServerName www.virtualhost.com
    ServerAlias virtualhost.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/www.virtualhost.com
    DirectoryIndex index.html index.php

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


    <Directory /var/www/www.virtualhost.com/>
            Options +Indexes -FollowSymlinks
            AllowOverride None
    </Directory>

    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

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

사이트 <?php echo "PHP"; ?>에 줄이 없으면 작동합니다. index.html하지만 이 줄을 삽입하면 PHP의 에코가 에코되지 않습니다.

다음과 같은 것이 필요합니까?

LoadModule php7_module modules/libphp7.so

/etc/apache2/apache2.conf?

이 문제를 해결하기 위한 어떤 힌트라도 환영합니다.

답변1

파일에 내장된 PHP 코드가 실행되기 위해서는 해당 파일이 실제로 PHP 인터프리터를 통해 실행되어야 합니다. 기본적으로 PHP 인터프리터를 통해 모든 파일을 전송하면 성능이 저하되고 경우에 따라 보안 또는 기능 문제가 발생할 수 있으므로 다음으로 끝나는 파일 .php(및 몇 가지 다른 파일 확장자)만 PHP 인터프리터를 통해 전송됩니다.

PHP 인터프리터를 통해 끝나는 모든 파일을 보내도록 웹 서버에 지시하려면 .htmlvhost 구성에 다음 줄을 추가해야 합니다:

AddHandler application/x-httpd-php70 .html

관련 정보