Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 13101  / 1 Year ago, tue, april 11, 2023, 4:07:39

I can't access anything inside of localhost, whenever I try to access anything inside of localhost it gives me 403 Forbidden error. I also can't add any files into the var/www/ folder unless I open it through sudo; Nonetheless, when I access localhost itself the default html appears which says it works. What could be causing this to happen? Thanks.


More From » server

 Answers
7

Well, for security reasons, /var/www folder is usually only accessed via sudo. If you wish to drop your files, let's say: your index.html, images folder and other stuff inside of it you will be in the need to start nautilus (or your preferred files browser) with elevated privileges by running sudo nautilus in a terminal or gksudo nautilus in the "Run application" dialog window, this will cause the /var/www to be accessed with both read and write access.


enter image description here


Related to your "403 Forbidden error" you must be sure that the files inside of /var/www have the right permissions, which can be changed via sudo chmod 755 /var/www -R in a terminal for read/write permission only for the owner and read and execute permissions for users and others.


However, if we wish to use another local folder for testing in our website/HTML/PHP code, we can change the default folder location used by our localhost/php engine to manage these files. This is done using the following procedure:



  1. sudo gedit /etc/apache2/sites-available/default

  2. Provide user password


Then, change all occurrences of "/var/www/" to the folder that we use to test our site/HTML/PHP. (Example: /home/geppettvs/www/ or where appropriate, change "geppettvs" with your local folder.


After that you must restart the computer for the purpose of the changes to take effect. Do not forget also that the files must have the proper file permissions to run properly. (755 is usually sufficient, but some folders [and/or files] may need 777 permissions to read and write them correctly.)


Another trick would be to stop/restart the Apache service but I prefer to restart the computer. In addition, you might need to clear your cache/browsing history in order to the changes take effect and stop receiving the It works! from the sample page.


Good luck!


Parts of this answers comes from: https://askubuntu.com/a/25045/9598


[#38748] Wednesday, April 12, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
damomnning

Total Points: 422
Total Questions: 90
Total Answers: 106

Location: Mali
Member since Thu, Aug 13, 2020
4 Years ago
;