1

I managed to change DocumentRoot directory form /var/www to /home/user/www and working fine except the problem that I can not copy/paste or even delete any file without root access.

Since I use SASS compiler software in which some files are compiled and outputted within the project directory. It is no more output any files and give permission denied.

I need help making all DocumentRoot sub folders and files have full permission without root access.

mikewhatever
  • 33,013

2 Answers2

0

You can change owners of folders and files with chown.

sudo chown $USER:$USER path/to/fileorfolder

After that make sure you don't create new files and folders as root in that folder, because then the new files and folders will be owned by root again.

mkdrive2
  • 206
0
sudo su

Assuming you have su permission, if not all the following commands should be prepended with sudo

add yourself to the server users group

adduser user:www-data (could be another user group)

Change ownership of all files in the document root to ensure server can manage them

chown www-data:www-data -R /path/to/directory

As a side note the chown can be run with your-user:www-data which would mean you own the files but the webserver can still access them. (you will definitely want umask if you do this, otherwise you may be changing ownership and permissions frequently as the web server will own the files it creates).

make all files read and write including the directory (possible security implications with chmod and -R recursive flag so use it cautiously)

chmod g+rw -R /path/to/directory

Now if the files are created by the webserver itself they usually only have write access to the owner and read to the group. To resolve that matter you will need to look into umask as mentioned above and get directions as to where to set the umask and the correct setting your for your specific application.

For apache 2 (ive used nano as i find it the easiest editor in terminal).

nano /etc/apache2/envvars

add to end of file: umask 002
save the file.

service apache2 restart

This was found here: https://stackoverflow.com/questions/428416/setting-the-umask-of-the-apache-user and should probably be the accepted answer submitted by patrick fisher