I have ubuntu installed on my local computer with apache / php / mysql.
I now have a directory at /var/www – inside which I have several of my ongoing projects. I also work with opensource ( drupal, magento, sugarcrm ).
The problem I am facing is changing file permission with terminal. Sometime I need to change the permission of entire folder and its subsequent sub-folders and files. I have to individually change using
sudo chmod 777 foldername
How can I do this recursively.
Also why do I have to always do it 777, I tried 755 for folders and 644 for files, but that won't work.
Best Answer
Just add the
-R
option to recursively change the permissions of files. An example, recursively add read and write permissions for the owner and group onfoldername
:Permissions will be like 664 or 775.
Setting the permissions to 777 is highly discouraged. You get errors in either Apache or your editor regarding permissions because apache runs under a different user (
www-data
) than you.If you want to write to
/var/www
, add yourself to thewww-data
group and set umask+permissions accordingly.www-data
group:sudo adduser $USER www-data
/var/www
:sudo chown -R www-data:www-data /var/www
umask 007
to/etc/apache2/envvars
.www-data
) write permissions:sudo chmod -R g+w /var/www
.