Permission errors on web server

Im getting the classic permission error after I setup a new apache server on debian 9.3

I was trying to append the index.html file by doing:

sudo echo 'hello world, etc' >> /var/www/html/index.html

but it is returning as permission denied. I am doing this under my user account and not under root or www-data. I can do everything else with sudo including move files into the /var/www/html directory and change their permissions

My permissions are:

/var/www/

drwxr-xr-x 2 www-data www-data 4.0K Mar 23 11:41 html

/var/www/html

xr-x 1 www-data www-data 11K Mar 23 11:22 index.html

Posted Mar 23, 2018, 5:50 PM UTC

13
Swedophone•

sudo echo 'hello world, etc' >> /var/www/html/index.html

The redirection is handled by the shell (running as user) and not by the echo command.

2
LinuxHostSupport•

You can append to files with sudo using tee, try the following command: echo 'hello world, etc' | sudo tee -a /var/www/html/index.html

2
lykwydchykyn•

This stackoverflow response explains the issue pretty well:

https://stackoverflow.com/a/82278/1454109

2