3

Recenly reinstalled my system, and came to a point where I need apache and php.

I've been searching a long time, but I can't figure out how to configure apache the best way for a developer computer. The plan is simple, I want to install apache 2 + mysql server so I can develop some php website.

I don't want to install lamp though, just the apache2, php5 and mysql. The problem that I've been looking an answer for is the permissions on the /var/www/ folder. I've tried making it my folder using the chown command, followed by a chmod -R 755 /var/www. Most things work then, but fwrite for example won't work, because I need to give write permissions to everyone, unless I change my global umask to 000 I'm not sure what I can do.

In short: I want to install apache2, php5, mysql-server without using lamp, but configured in a way so I can open up netbeans, start a project with root in /var/www/, and run every single function without permission faults. Does anyone have experiences or workarounds to this?

Extra:

  • OS: Ubuntu 10.04
  • ARCH: x86_64

3 Answers3

1

I have found out the answer so I'll post it on here

First log in as root using:

sudo su

Add a new group, all users of this group are able to control the /var/www/ folder

groupadd www-pub

Add your own username to this group like this

usermod -a -G www-pub username

Now change the owners of the /var/www/ folder, as the owner I wouldn't take root, but rather www-data, and change the group to the group just made: www-pub

chown -R www-data:www-pub /var/www/

We still have to change the permissions so that we can create file on /var/www/. If you don't know what the "2" means, this stands for SGID, information about this can be found at http://www.codecoffee.com/tipsforlinux/articles/028.html

chmod 2775 /var/www/

If there are files in /var/www/, update permissions like this

find /var/www/ -type f -exec chmod 664 {} \;
find /var/www/ -type d -exec chmod 775 {} \;

At last change your umask in the file /etc/profile to 002, umask should be the last line of that file

www-data information:

Apache runs as the user www-data. Using a generic www-data user rather than a specific "apache" one allows all web servers packaged for Debian to share the document root where files are owned by www-data.

1

Your biggest problem is that you insist on dealing with /var/www.

It is much easier to enable userdirectories (see UserDir) and let apache serve stuff from your home directory, like it does on most hosting services.

Anonymous
  • 1,550
  • 1
  • 14
  • 18
0

Another solution might be ACLs.

Modern linux you can add ACLs over and above,the old user:group:others model, using setfacl and getfacl.

You need to have the filesystem mounted with extended ACLs turned on to use ACLs though. This can be done live as a remount.

Amongst other things ACLs allow for default ACLs to be set on directories. I.e. you can set a default ACL on a directory and that ACL will be applied to every object created in that directory.

Jason Tan
  • 2,752
  • 2
  • 17
  • 24