Apache: PHP not working in UserDir

Submitted by Renan on Thu, 29/07/2010 - 18:30

Here is a tip to PHP developers that uses the Debian family of distros: how enable the execution of PHP scripts in the public_html folder. Apparently, this feature is disabled by default in the Debian based distros. Before start, I'm assuming that you already have both Apache and PHP installed, configured and running.

The interest in using Apache's mod_userdir is to increase the system security at the same time making easy the file handling. All the files inside the public_html folder present in your home dir will be accessible through Apache.

As root, run the following commands. First, we enable the userdir mod:

# a2enmod userdir

The script will enable the module and will tell you do restart Apache. At next, create the public_html folder using your normal user, inside your Home, and define its permissions:

  1. $ mkdir public_html
  2. $ chmod 711 public_html

Now, as root, define the Home's folders permissions(this is a critical detail):

# chmod 711 /home /home/[your_login]

The next step is enable the execution of PHP scripts inside public_html. To do that, as root, open the file /etc/apache2/mods-enabled/php5.conf and find the following lines:

  1. <IfModule mod_userdir.c>
  2.   <Directory /home/*/public_html>
  3.     php_admin_value engine Off
  4.   </Directory>
  5. </IfModule>

Comment them by putting a # in the beginning of each one. Save and close. Now restart the Apache server by running the following command as root:

# /etc/init.d/apache2 restart

The end! You can now run your PHP apps inside your public_html folder without being worried about doing weird tricks to read/write the default /var/www. :)

3 comments

Gabriel Francisco's picture

Valeeu!! Muito útil sua

Submitted by Gabriel Francisco (not verified) on Wed, 25/01/2012 - 17:35.

Valeeu!!

Muito útil sua dica!
resolveu um problema que tive aqui em tempo record!

rs

Abraço!

Spike's picture

It's good to see someone

Submitted by Spike (not verified) on Wed, 18/01/2012 - 21:42.

It's good to see someone tihiknng it through.

Luís's picture

Great, it's works. Tks you!

Submitted by Luís (not verified) on Sat, 30/04/2011 - 20:43.

Great, it's works. Tks you!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <css>, <drupal6>, <html>, <java>, <javascript>, <jquery>, <php>, <python>, <ruby>, <sql>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.
"If debugging is the process of removing bugs, then programming must be the process of putting them in." Drupal theme by Kiwi Themes.