I want to stop having to use sudo everytime I work in /var/www. How can I do that? I simply want to put all of my sites into this directory and work with them without too much pain.
|
Most answers here are not written with security in mind. It's good to get a feeling that running Note: Starting with Apache 2.4.7 / Ubuntu 14.04, See - Where to place my local website starting with the 2.4.7 version of apache2? https://stackoverflow.com/questions/21660621/why-has-the-apache2-www-dir-been-moved-to-var-www-html https://lists.debian.org/debian-devel/2012/04/msg00301.html Bad ideas:
NOTE: in the below solutions, I've granted
Where possible, do not grant write permissions to the Solution 1Add yourself to the
Correct previously created files (assuming you to be the only user of
(even safer: use Solution 2Create a symlink for each project to your home directory. Say your project is located at
If your home directory has no execute bit (descend) set for
Set the group to
Even safer: use 640 and 2750 by default and manually chmod files and directories that need to be writable by the webserver user. The setgid bit should be added only if you want every newly created file in From now on, you can access your site at See also |
|||||||||||||||||||||
|
|
Rather than storing my web sites in /var/www I place links there to the sites which are located in my home folder. I can freely edit, or add pages to my sites. When I happy with changes I then FTP to a hosting company where my domain name links. |
|||||
|
|
If you make /var/www writeable by its group and add yourself to the group, you will not have to use sudo while still being fairly secure. Try this:
You should then be able to edit The first line adds you to the |
|||||
|
Don'ts
Dos
|
||||
|
|
|
It's that simple. You neither need to enable apache 'UserDir' (not recommended) nor messing up with 'www-data' groups (apache group in case on Fedora) Just create your project directory inside /var/www/html
Then just chown the project directory to your user.
Now you can start working on your project folder as a regular user with any editor, IDE of your choice. No more sudos : ) |
|||||
|
|
chmod in /var on www to allow the owner access, and chown to make sure you own it. Probably a stupid idea, but it would definitely work. |
|||||
|
|
You could start a www-session in a terminal by
Combined with a differently colored prompt*, to make it more obvious that it is the shell of a different user, and a policy always to put the corresponding xterm (and editor and such) on - for example - the virtual desktop 4, so that you get used to it, to avoid confusion. *) For a differently colored prompt with a differnt character, create a file /etc/prompt like this:
and source it from As additional tool to help distinction, you could always edit your files with an alias 'edit' or a symlink, which points, depending on your identity (taylor/www-data) to either gedit or mousepad, vim or pico. Or you could use different editor profiles, at least in gedit you may set your preferences to black text on white ground or white text on black ground for instance. I only have such a policy for working as root, so I'm not sure how good it will fit to working with www-data. Combined with ssh-sessions to differnt hosts, which have their own prompts, it didn't stop me from being sometimes wrong, but if it happens, I realize fast, what is wrong, and it happens rarely. note: The prompt-script is partly a copy of the manpage of bash. |
|||||
|
|
On this page of my site I cover the commands for changing the permission in
then an apache restart
|
||||
|
|
sudo -u www-databut restrict yourself in thesudoersfile to only be able tosudo www-data(and not sudo root). See serverfault.com/questions/295429/… – Simon Woodside May 31 '16 at 4:18