UbuntuのApacheのバーチャルホストは、PHPの小さなノートを実行しません

動作環境:
Ubuntuの:16.04
PHP:5.6.36
のApache:2.4.18

表示される/var/www/htmlPHPファイルを実行することができますフォルダの下に

バーチャルホストの設定ファイルのDocumentRootパス形式があり/home/USERNAME/public_html、アクセス、出力PHPのソースファイルまたはダウンロードPHP

ソリューション

  1. 使用しないでください/home/USERNAME/public_html、このような読み取りとして、このフォーマットを:/home/USERNAME/wwwこのフォーマットを
  2. 変更し/etc/apache2/mods-available/php5.6.conf、ファイルを使用して#コメントアウトする番号を从<IfModule ...> 到 </IfModule>複数行に

最後の再起動 apache

理由:/etc/apache2/mods-available/php5.6.conf一部のコンテンツをファイルには、次のとおりです。

# Running PHP scripts in user directories is disabled by default
# 
# 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 Off
    </Directory>
</IfModule>

上記のコメントの翻訳

# 在用户的目录中运行php脚本是默认禁止的
#
# 为了在用户的目录重新启用php 注释以下行
# (从 <IfModule ...> 到 </IfModule>.) 不要将它设置为 On
# 预防 .htaccess 文件来禁止它
<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
    </Directory>
</IfModule>

/etc/apache2/sites-availableフォルダを追加www.test.com.confファイルの上にバーチャルホストを

<VirtualHost *:80>
    ServerName www.test.com
    ServerAlias www.test.com test.com
    DocumentRoot /home/test/public_html
    <Directory /home/test/public_html>
             Options  FollowSymLinks MultiViews
             AllowOverride All
             Require all granted
             Order allow,deny
             allow from all
    </Directory>


    ErrorLog /var/log/apache2/domain/www.test.com.error.log
    CustomLog /var/log/apache2/domain/www.test.comaccess.log combined
</VirtualHost>

では/home/test/public_html/場合があるinfo.phpファイルは、

<?php
phpinfo();

アクセスhttp://www.test.com/info.php時間は、何PHPを実行し、PHPのソースコードを示していません

その後、バーチャルホストの設定ファイルが/home/test/public_htmlpublic_htmlに変更しwww、対応するフォルダ名の変更

mv /home/test/public_html /home/test/www

変更後は、/etc/apache2/sites-available/www.test.com.confファイルの内容は、

<VirtualHost *:80>
    ServerName www.test.com
    ServerAlias www.test.com test.com
    # only replace public_html to www
    DocumentRoot /home/test/www
    <Directory /home/test/www>
             Options  FollowSymLinks MultiViews
             AllowOverride All
             Require all granted
             Order allow,deny
             allow from all
    </Directory>

    ErrorLog /var/log/apache2/domain/www.test.com.error.log
    CustomLog /var/log/apache2/domain/www.test.comaccess.log combined
</VirtualHost>

その後、Apacheを再起動します

sudo service apache2 restart

そして、アクセスしようとするhttp://www.test.com/info.phpを情報出力PHPに

おすすめ

転載: www.cnblogs.com/fsong/p/11335191.html