1

I just installed a LAMP server in a fresh Ubuntu system.

The main problem I have is that the webroot is at "/var/www", and my default username doesn't have access to write there. I could be sudo-ing all the time, but thats quite a pain. I've tried playing with permissions and symbolic links, but I never seem to get through the problem.

How do I setup a new developer machine so that I can quick and efficiently start developing right off the bat?

3
  • Please rephrase your question. Now it sounds like you're asking for opinion and it may be put on hold. However, you can rewrite it to ask how to solve specific problem (permission issues).
    – gronostaj
    Jul 28, 2013 at 12:08
  • 1
    @gronostaj To me it looks like that's the gist of the question, "best" is being defined clearly here, so this question is fine.
    – slhck
    Jul 28, 2013 at 12:10
  • I've edited your question to better match what we're looking for here at Super User. Feel free to change, or even roll-back if you disagree. Ultimately I feel that this is a valid and good question (cc @slhck) Aug 5, 2013 at 14:46

3 Answers 3

2

Change /var/www

I would recommend you edit the /etc/apache2/sites-enabled/000-default and change the DocumentRoot and Directory to point to something along the lines of

DocumentRoot /home/USERNAME/web/

and

<directory /home/USERNAME/web>

instead of the ones with /var/www in them

Userdirs

Alternatively you can enable Userdirs, by simply

sudo mv /etc/apache2/mods-available/userdir.* /etc/apache2/mods-enabled/

Then you can access your /home/USERNAME/public_html directory from http://127.0.0.1/~USERNAME

Note: Both of these methods require you to restart apache, you can do so with

/etc/init.d/apache2 restart

I hope this helps

1
  • 2
    Good suggestions. For simplicity, the userdir module can be enabled with sudo a2enmod userdir.
    – slhck
    Jul 28, 2013 at 12:27
2

You can create a group of users that has write permissions to the /var/www directory. For example, www-users:

sudo addgroup www-users

Then, add yourself to that group:

sudo adduser $(whoami) www-users

Finally give ownership to the group, and set group-writable permissions:

sudo chgrp www-users /var/www
sudo chmod –R 775 /var/www
sudo chmod g+s /var/www

Now, you will be able to create and modify files in /var/www as long as they also belong to your group. If you need Apache to have write access, you can adduser www-data www-users to give it write permissions as well.

1
  • Is there a way that this could be written up as a script, that runs after a fresh install of the system? Because I think that's ultimately the goal of the OP. Aug 5, 2013 at 14:44
0

This is a common problem, and the best solution I have found is vagrant.

http://www.vagrantup.com

Basically Vagrant is software that integrates with virtual box, and allows you to quickly spin up a VM. It is then very easy to map the /var/www directory, to the project home. Any changes made to that directory, instantly show up live on the web server.

Vagrant advantages:

  • Standardize environments for all developers though box images.
  • Automatic symbolic linking of folders
  • Quick setup/teardown

You must log in to answer this question.

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