6

My /etc/apache2/mods-enabled/userdir.conf file looks like:

<IfModule mod_userdir.c>
        UserDir /var/zpanel/hostdata/*/public_html/
        UserDir disabled root

        <Directory /var/zpanel/hostdata/*/public_html/*>
                AllowOverride All
                Options MultiViews Indexes SymLinksIfOwnerMatch
                <Limit GET POST OPTIONS>
                        # Apache <= 2.2:
                        Order allow,deny
                        Allow from all

                        # Apache >= 2.4:
                        # Require all granted
                </Limit>
                <LimitExcept GET POST OPTIONS>
                        # Apache <= 2.2:
                        Order deny,allow
                        Deny from all

                        # Apache >= 2.4:
                        #Require all denied
                </LimitExcept>
        </Directory>
</IfModule>

And file /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
   Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
    Require all denied
</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 /var/zpanel/hostdata/*/public_html/*>
#        php_admin_value engine On
#    </Directory>
#</IfModule>

But php not working when in accessing web site via userdir. www.example.com/~admin When i access via domain then it works. I have zPanel installed

Server version: Apache/2.4.18 (Ubuntu)

4
  • You haven't said which version of Apache this is despite the repeated hints in the config that 2.2 is different from 2.4 Commented Mar 10, 2016 at 23:45
  • I forgot to mention that. Server version: Apache/2.4.18 (Ubuntu) Commented Mar 11, 2016 at 8:18
  • If you use Apache 2.4 perhaps you shouldn't use the directives tagged as "Apache <= 2.2" :-? Commented Mar 11, 2016 at 8:47
  • I tried to delete this few lines and it is the same Commented Mar 11, 2016 at 10:50

3 Answers 3

6

In my /etc/apache2/mods-available/php7.0.conf I have this section

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

I think now you know what to do.

Sign up to request clarification or add additional context in comments.

1 Comment

now /etc/apache2/mods-available/php8.0.conf
3

Try the following actions:

  • Make sure mod_userdir is enabled (a2enmod userdir).
  • The $HOME and public_html dirs have the right read permissions.

    sudo -Hu SOMEUSER sh -c 'chmod 755 $HOME $HOME/public_html'
    
  • Make sure php_admin_value engine is On.

    sudo vim /etc/apache2/mods-enabled/php*.conf
    

    Then find the line containing php_admin_flag and change it to:

    php_admin_flag engine On
    

    This is due that PHP is disabled by default for user dirs for Apache 2.


In your particular case, you've to uncomment the following lines:

<IfModule mod_userdir.c>
    <Directory /var/zpanel/hostdata/*/public_html/*>
        php_admin_value engine On
    </Directory>
</IfModule>

Comments

2

As mention by @kenorb, this is because PHP is disabled php_admin_value engine Off by default in userdirs for Apache2.

But instead of changing the php_admin_value engine to On in /etc/apache2/mods-enabled/php*.conf, it is advised in the .conf file itself that the lines starting from <IfModule> to </IfModule> be commented out, so that .htaccess can handle the setting separately. This can be done as shown below:

#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_flag engine Off
#    </Directory>
#</IfModule>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.