Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied inside /var/www/html when creating a website and it's files with the apache2 server

screenshot from inside atom UPDATE** The screenshot is within atom, but when I navigate to the directory using the file explorer, and right click, the option to rename or create a new folder are restricted and I cannot click on them.

I just finished setting up the LAMP stack on my fresh UBUNTU 18.04 installation. I have everything working, the default /var/www/html/index.html page from Apache2 is being served on localhost, no port forwarding or any unique domain name, i just wanna run this on my network from my computer for now.

If there is a simple way to create multiple websites and easily choose which folder to serve than that's fine, but I want to serve just one website for now.

When I go to my /var/www/html folder and try to edit the index.html file it says permission denied. What do I need to do in order to work inside this directory for the remaining time that I am building the website. I am signed in as the root user on my system.

Also, if I do change permissions to allow me to work in this directory, what does it mean for people trying to access my server if it was available to the public. (RIGHT NOW JUST ON LOCALHOST).

Lemme know if you need more info or explanation thanks!

like image 763
jreyes Avatar asked May 16 '18 19:05

jreyes


People also ask

How do I get permission for VAR www?

chmod g+w /var/www to allow your account to be able to add files to /var/www. If there are any subdirectories beneath /var/www, you will want to do the same chmod command if you need to be able to write to those directories ever.


2 Answers

sudo chown -R $USER:$USER /var/www

this works, it changes the owner to my user instead of root user. I still don't understand because my user already had sudo rights and all those permissions. It was the user I created during the ubuntu18.04 setup, so there shouldn't be an issue, or idk.

like image 187
jreyes Avatar answered Nov 16 '22 04:11

jreyes


File ownership issues can be fixed at the command line by typing:

sudo chmod 777 /var/www/html -R

One caveat from turnkeyLinux.com:

Changing file permissions is a trade off (often increasing security reduces user-friendliness and/or usability). For security 'best practice' only the folders that require write access by the webserver should be owned by the webserver. If your webserver has write access everywhere and your server is compromised it makes it easier to hack your WordPress install) but for ease of use giving the webserver ownership should resolve all your issues...


This article on Understanding File Permissions was great, too.

like image 25
Kelly Avatar answered Nov 16 '22 04:11

Kelly