Can't access localhost
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.
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:
- sudo gedit /etc/apache2/sites-available/default
- 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
Related videos on Youtube
fenerlitk
Updated on September 18, 2022Comments
-
fenerlitk over 1 year
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. -
Fero about 12 yearsA good thing is to move your mysql file to /home folder too. When you install a new version of OS, the home folder stays untouched