Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

/etc/apache2/sites-available/default:

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

But I want one user (myself) to be able to execute php, but only in one subdirectory. I tried to follow https://wiki.ubuntu.com/UserDirectoryPHP, 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):

/etc/apache2/d.conf/php-in-homedirs.conf:

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

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 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 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 at 13:38
    
oops, that's supposed to be /home/gunther/public_html/php I copied the wrong things –  Gunther Struyf Feb 23 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 at 13:52

2 Answers 2

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>

or

<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 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 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>
    <Directory /home/gunther/public_html/php>
        php_admin_value engine 1
    </Directory>
</IfModule>

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

share|improve this answer

Your Answer

 
discard

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.