Ubuntu Apache vhost not execute php small note

Operating environment:
Ubuntu: 16.04
PHP: 5.6.36
the Apache: 2.4.18

Appear /var/www/htmlunder the folder can execute php file

vhost configuration file DocumentRootpath format is /home/USERNAME/public_html, the access, the output php source file or download php

Solution :

  1. Do not use /home/USERNAME/public_htmlthis format, such as read: /home/USERNAME/wwwthis format
  2. Modify the /etc/apache2/mods-available/php5.6.conffile, use the #numbers to comment out 从<IfModule ...> 到 </IfModule>several lines

The last restart apache

The reason: /etc/apache2/mods-available/php5.6.conffile some content is:

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

My own translation of the above comments

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

In /etc/apache2/sites-availablefolder added a www.test.com.confvhost on file

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

In /home/test/public_html/case there is a info.phpfile

<?php
phpinfo();

Access http://www.test.com/info.php time, has shown php source code, no execute php

Later the vhost configuration file /home/test/public_htmlis public_htmlchanged to wwwthe corresponding folder rename

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

After the changes, /etc/apache2/sites-available/www.test.com.confthe contents of the file is

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

Then restart apache

sudo service apache2 restart

And then try to access http://www.test.com/info.php on the information output php

Guess you like

Origin www.cnblogs.com/fsong/p/11335191.html