Today I wanted to give my users possibility to test their PHP scripts, but without all the fuss with creating virtual hosts for each one of them. My first and obvious choice was userdir – user creates public_html directory in his home dir, puts there files, and those files are accessible via http://servername/~username/ URL. To enable this behavior you only have to enable userdir module (a2enmod userdir), and remember to set correct permissions to the userdir (chmod +x $HOME) and public_html (chmod 755 $HOME/public_html). I did this, and everything was working fine, except PHP scripts – browser wanted to download them instead of displaying proper processed content. It appeared that apache in Debian has by default PHP disabled for userdirs. To enable scripting in this dirctory, open file /etc/apache2/mods-enabled/php5.conf, find that piece of code:

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

and disable it, either by deleting or by commenting it out (precede each line with # sign). You can also change php_admin_value engine setting to On, but if you do that, you will be unable to turn off PHP engine in .htaccess files.


4 Responses to “[Linux] PHP not working in userdir (public_html)”  

  1. 1 Eduardo

    Thanks !!

    It’s help me !!

    Greetings from Argentina.

    Eduardo.

  2. 2 Sami

    Thanks, it worked for me too, I commented this 5 line out :)

  3. 3 Alan

    I don’t know how I overlooked that… thanks for the tip. :)

  4. 4 Heino

    just switched from opensuse to try unbuntu – and this tip was usefull to me :)

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image