I'm using plain Ubuntu Desktop 11.04 and installed my lamp stack using lamp-server. I am trying to use Netbeans as my IDE.

Currently, all virtual hosts are being run from /var/www/vhostname -- but as I have not configured any groups or permissions, if I try to open any of the files through Netbeans it does not have write permission.

How can I properly set up permissions (or configure Apache or Netbeans) so that:

  • Files created by a php script can be rw by Netbeans
  • Files created by Netbeans can be rw by Apache

I attempted to chown everything to my user/group which gave Netbeans write permission, but then Apache did not have write permission.

Note: This is purely for a development machine -- not used in production, and I am the only user on this box.


I used to use the method in the answer I marked as accepted, but nowadays I do something much simpler:

  1. I set Apache to run as my user and my group (this is done either in httpd.conf, apache2.conf, or envvars depending on your distro)
  2. I chown /var/www to my user and group

Voila, Apache has read/write access, and I have read/write access while working on projects.


3 Answers 3


What I recommend doing has been mostly described in this Ask Ubuntu question.

For this particular case I would install suPHP which in short allows you to execute PHP scripts as your user under Apache.

By doing the following:

sudo chown -R youruser:youruser /var/www
find /var/www/ -type d -exec chmod 0755 {} \;
find /var/www/ -type f -exec chmod 0644 {} \;

Install suphp-common and libapache2-mod-suphp from this ppa (What are PPAs and how do I use them?)

Disable mod_php5 and enable mod_suphp

sudo a2enmod suphp
sudo a2dismod php5

Update your virtual hosts to include this line at the bottom of them:

suPHP_UserGroup youruser youruser

Replacing youruser with the user you use to edit files on the server. Restart Apache.

From this point forward Apache will execute all php scripts are your user, which means they can be owned by your user/group and there is no need to use crazy permissions like 777. Since everything is run as your user all files created by the php scripts will be owned by your user as well! There are many other cool things you can do with suPHP; however, from what it sounds like this is all you'll need to get started.

  • I'm on Ubuntu Desktop, so those sources didn't work. I tried Synaptic and USC, but couldn't quite get suPHP_UserGroup to work. The error was Invalid command 'suPHP_UserGroup', perhaps misspelled or defined by a module not included in the server configuration, even though Server API under phpinfo(); changes from Apache 2.0 Handler to CGI/FastCGI when I disable php5 and enable suphp.
    – Nick
    Oct 7, 2011 at 20:59
  • @hztetra Those sources should work just fine, I use it on my desktop setup. If you're getting Invalid command then that likely means you didn't install from the PPA. The default suPHP install from the repos doesn't enable that (crazy! right?) Verify you have 0.7.1-1ubuntu0+ondina1 installed as that source has suPHP compiled with the appropriate flags (paranoid mode) to use the suPHP_UserGroup configuration option. Oct 7, 2011 at 21:28
  • I got a few errors the first time I attempted to add the sources, but tried again and worked perfectly.
    – Nick
    Oct 10, 2011 at 16:03

You'll want to make the files rw by others (not group and owner only). It should be noted that there could be security issues with doing this, but I'd chown the folders back to the Apache user/group then use chmod o+rw on the folders to allow Netbeens to read/write the files. I haven't tested that, but it should work. If you prefer bitmasks, I believe chmod 766 on the folders will achieve the same result.


Set the group on /var/www/vhostname to apache recursively. Add yourself to the apache group. Set permissions on var/www/vhostname to 775.

chown -R apache /var/www/vhostname
chmod -R 775 /var/www/vhostname
usermod -a -g apache $USERNAME

This will ensure that you(and others in the apache group, like Apache, can write to the server directory, but noone else can. It will also ensure that a runaway script can't write gibberish over your home directory, or that a cracked script can't, for example, echo PATH=/path/to/evil/script/directory:$PATH >> ~/.bashrc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .