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.

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
share|improve this question

migrated from stackoverflow.com Apr 25 '10 at 3:59

This question came from our site for professional and enthusiast programmers.

1  
If you are running Linux, and install Apache + Mysql + Php, you will have a LAMP server ;-) –  Pascal MARTIN Apr 24 '10 at 20:14
    
My mind was just blown, I never noticed LAMP means Linux Apache Mysql PHP. But I can imagine LAMP might come with a lot of extra features? –  Jeffrey Vandenborne Apr 24 '10 at 22:12
    
Not really. A LAMP setup can be as small or as large as required. –  Ignacio Vazquez-Abrams Apr 25 '10 at 12:58

3 Answers 3

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.

share|improve this answer

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.

share|improve this answer

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.

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.