Ubuntu – How to chmod 777 all subfolders of /var/www

Apache2chmodpermissions

I’m running a webserver and FTP server, wherein /var/www is bound to /home/user/www.

I set both directories to chmod 777 (which is fine since it’s for testing only).

I can upload files into /home/user/www, but whenever I create a new directory, I always have to run chmod 777 on that folder.

Otherwise, when I try to browse it, I get the error message

You don't have permission to access /test/ on this server.

Is there a way I could make all sub-folders inside /var/www be accessible by anyone? Or could their permissions be automatically set to 777? It’s annoying that I have to type chmod 777 every time.

Best Answer

This is bad practice, but hopefully you are just using this for development, or you have another good reason. You can specify the permissions when you create a directory using the -m option:

mkdir -m 777 dirname

Or you can set the permissions recursively.

sudo chmod -R 777 /var/www

Before using either of these, really consider if you want your filesystem to be so accessible.


Edit: As mentioned by Rinzwind here is a better way of accomplishing what you want.

Check what group owns your /var/www directory and add your user to that group.

sudo adduser yourusername group

The group is probably www-data.

Then you will be OK with setting your permissions to 775.