Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to disable php for all my user directories, which I implemented by adding php_admin_value engine Off to them:


<IfModule mod_userdir.c>
    UserDir "public_html"
    <Directory /home/*/public_html>
        php_admin_value engine Off

But I want one user (myself) to be able to execute php, but only in one subdirectory. I tried to follow, which specified creating a new file with following lines (I don't think it matters if it's separated to conf.d but it's cleaner imo so I complied):


<VirtualHost *:80>
    <IfModule mod_userdir.c>
        <Directory /home/gunther/public_html/php>
            php_admin_value engine on

These instructions are added to the apache config, as I can see in the server-info:

Module Name: mod_php5.c
Content handlers: yes
Current Configuration:

<VirtualHost *:80>
  11:   <Directory /home/*/public_html>
  12:     php_admin_value engine Off
    :   </Directory>
    : </VirtualHost>
In file: /etc/apache2/conf.d/php-in-homedirs.conf
   2: <Directory /home/gunther/public_html/php/*>
   3:   php_admin_value engine On
    : </Directory>

But it just ain't working, it downloads the php file. If I remove the php_admin_value engine off from the default vhost, php works, but then it works for all users in all directories. I just want it working for that one subdirectory.

share|improve this question
have you tried to copy-paste the content of php-in-homedirs.conf in the default file before the /home/*/public_html section ? ( and remove the php-in-homedirs.conf ) ? – Olivier S Feb 23 '14 at 7:43
I tried by switching the position of Includes sites-enabled and Include conf.d in apache2.conf, didn't work. Just tried what you suggested, although that would change not much imo -> no results either :/ – Gunther Struyf Feb 23 '14 at 10:06
Is it normal that your home directory is referenced as /media/data/gunther instead of /home/gunther ? Reading again your conf I do not see how the engine Off on /home/*/public_html would affect the /media/data/gunther/public_html ?? – Olivier S Feb 23 '14 at 13:38
oops, that's supposed to be /home/gunther/public_html/php I copied the wrong things – Gunther Struyf Feb 23 '14 at 13:42
Did you try / is it possible to set the variable to Off at the virtual host level, and setting it "On" only in <Directory /home/gunther/public_html/php/> ? – Olivier S Feb 23 '14 at 13:52

The order of precedence that Apache uses to merge directives in different sections is described here. It can be hard to get right, and this seems to be a case where the precedence is unclear and not what you want or expect.

In a case like that you can force the precedence you want by changing your <Directory> section to one with higher precedence, for example:

<DirectoryMatch ^/home/gunther/public_html/php/> ... </DirectoryMatch>


<Location /~gunther/php> ... </Location>
share|improve this answer
Using Location for this is very likely to be a bad idea. You want to disable /enable php for directories/files, not for urls. – Olivier S Feb 23 '14 at 13:39
tried all of those, but neither is working. If I reverse the enable/disable, ie turn the php engine on in public_html and off in public_html/php, this does work. Is it possible that you can only override engine on and not engine off? – Gunther Struyf Feb 23 '14 at 13:47
up vote 0 down vote accepted

As far as I understand it, it's a combination of how to use php_admin_value engine and precedence of apache configuration files.

If I put the dis/enable next to eachother and use engine 1 instead of engine on, it works, all other combinations do not work. If anybody has an explanation, please tell!

I ended up putting the php enable/disable of userdirs in the php5.conf file:

<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_value engine Off
    <Directory /home/gunther/public_html/php>
        php_admin_value engine 1

which by default gets loaded before sites-enabled and conf.d.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.