0

I set up a Debian 6 VPS to host couple of small sites and it works beautifully for default one.

Next i created new user and copy/paste default vhost file and enabled it with a2ensite and only adjusted paths accordingly for that new user but for some reason PHP files aren't parsed and only their source is displayed.

So, recap: identical vhost settings, PHP module enabled, short tags on (but not used)

To make it clear: I search and found bunch of "solutions" here and on the web elsewhere but none of those seemed to work for me.

Just noticed this string in logs :

PHP Fatal error:  Unknown: Failed opening required '/home/tester/public_html/index.php' (include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0

[Thu Mar 21 20:28:55 2013] [error] [client xxx.xxx.xxx.xxx] PHP Warning:  Unknown: open_basedir restriction in effect. File(/home/tester/public_html/index.php) is not within the allowed path(s): (/home/user/public_html:/tmp) in Unknown on line 0

And this is my default vhost file content:

<VirtualHost *:80>

        ServerAdmin [email protected]
        ServerName domain.com
        ServerAlias www.domain.com
        DocumentRoot /home/user/public_html/
        ErrorLog /home/user/logs/error.log
        CustomLog /home/user/logs/access.log combined

        <Directory "/home/user/public_html">
        AllowOverride All
                php_admin_flag engine on
                php_admin_value open_basedir "/home/user/public_html:/tmp"
        </Directory>

</VirtualHost>

Could PHP's open_basedir be the culprit of this issue?

2 Answers 2

0

Yes, open_basedir can be root of this problem. You must have /home/tester/public_html/ in path and you have /home/user.

Looks like it skip PHP parsing and not block access to page as I tough - I found similar problem solved here: https://bbs.archlinux.org/viewtopic.php?id=57877 .

/First version with asking for clarification deleted as not complying with ServerFault policies as I was told./

3
  • Yeah, PHP is enabled that way and it works on default vhost. All files are having .php extension. Totally confusing..
    – dzhi
    Mar 22, 2013 at 7:28
  • @purpler Yes, you answer yourself I think (see link in my edited answer).
    – dsznajder
    Mar 22, 2013 at 13:07
  • Nah, default PHP module config was the real culprit. I Explained below. Thanks for help tho!
    – dzhi
    Mar 22, 2013 at 18:54
0

Yay! Got it working!

Checked Apache's PHP module conf settings at /etc/apache2/mods-enabled/php5.conf:

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
    SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Order Deny,Allow
    Deny from all
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
    Order Deny,Allow
    Deny from all
</FilesMatch>

# 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_value engine Off
    </Directory>
</IfModule>

It clearly says:

# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.)

So I did, then restarted Apache and voila:

https://i.stack.imgur.com/Be7dj.png

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .