avoid using sudo when working in /var/www

Question

 

How to avoid using sudo when working in /var/www?

 

 

 

Answer  :

Add  the  user  to the

www-data

group and set the setgid bit on the

/var/www

directory so that all newly created files inherit this group as well.



sudo usermod -a -G www-data "$USER"

Correct previously created files (assuming you to be the only user of

/var/www

):



sudo chown -R "$USER":www-data /var/www
find /var/www -type f -exec chmod 0660 {} ;
sudo find /var/www -type d -exec chmod 2770 {} ;<br /><br /><br /><strong><br /></strong><span style="font-size: large;"><strong>OR</strong><br /></span><br />


sudo chgrp www-data -R /home/[YourHome]

Then by replacing /var/www by your own folder :


<span style="font-size: small;">sudo mv /var/www /var/www.old;
sudo ln -s /home/[YourHome]/public_html /var/www;
<br /></span>

<br />