動作環境:
Ubuntuの:16.04
PHP:5.6.36
のApache:2.4.18
表示される/var/www/html
PHPファイルを実行することができますフォルダの下に
バーチャルホストの設定ファイルのDocumentRoot
パス形式があり/home/USERNAME/public_html
、アクセス、出力PHPのソースファイルまたはダウンロードPHP
ソリューション:
- 使用しないでください
/home/USERNAME/public_html
、このような読み取りとして、このフォーマットを:/home/USERNAME/www
このフォーマットを - 変更し
/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_html
さpublic_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に