403 forbidden for /var/www after editing apache.conf - apache

Code:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
After editing some code in /var/www thinking I'd fix a small error where it denied access from everyone except me, somehow I screwed it up and I'm not firmiliar with this file at all. Now, everyone who visits any dir on my website gets 403 forbidden including myself.

is better to know that OS using often resolved by changing the permissions on the folder
for example server Ubuntu
sudo chmod 777 -R /var/www/html/youfile
that's it
Regards

Related

httpd (apache server) on fedora, symbolic links work but unable to see/access files inside?

I'm running httpd on fedora server 35 and want to use it to serve files on my local network. It works fine for files stored under the /var/www/html directory directly (e.g. /var/www/html/videos/video.mp4 can be accessed with http://IP/videos/video.mp4 on any local device).
I want to serve files stored in other locations in the file system. My plan was to create symbolic links to those locations. When I do that, I run into forbidden errors when trying to access the files (e.g. A video file /files/videos/video.mp4 linked with a sym link /var/www/html/videos-link -> /files/videos/ so that I would (theoretically) access it with http://IP/videos-link/video.mp4
I can navigate to http://IP/videos-link fine (an Index of DIRECTORY page, but no files are listed), but trying to access the file (http://IP/videos-link/video.mp4) gives me 403 forbidden.
My config (/etc/httpd/conf/httpd.conf) looks like this (it's a bit messy since I've been trying to fix this myself):
<Directory />
Options FollowSymLinks Indexes
AllowOverride All
Require all granted
</Directory>
...
<Directory "/var/www">
Options +FollowSymLinks +Indexes
AllowOverride All
Require all granted
</Directory>
...
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
...
<Directory "/files/videos">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
In attempts to make it work I've made sure the sym link and all the directories have the same owner and that their all 777 so ownership/read perms shouldn't be an issue. Would greatly appreciate some help, thanks.
My issue was with SELinux. To get it working immediately I was able to set SELinux to permissive mode with
# setenforce 0
That refreshes on boot and is probably insecure, so the permanent fix (to just let httpd through) would be:
# semanage permissive -a httpd_t
More details on SELinux in Fedora can be found here: https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-selinux/

Apache2: Cannot access Userdir - Forbidden

I am trying to run Apache 2.4 on Ubuntu 21.10. However, I cannot get userdir to work. I did everything I can possibly google, except reinstalling apache. I am normally a Windows person, so this is driving me nuts.
What I did:
Enable userdir.conf
Set Permission of the folder public_html into 777, and change ownership to www-data
Add Require all granted to literally everywhere I can think of: apache2.conf, userdir.conf, and the config in sites-available to include
<Directory /home/*/public_html >
Require all granted
AllowOverride All
Options +Indexes
</Directory>
Yet, for some reason, all I have is ERROR 403: Forbidden when trying to go to http://localhost/~myusername
What could I possibly be missing?
Thank you.
It turns out it is "because search permissions are missing on a component of the path". So just "chmod -R 755" my entire home folder. Probably not that good of a solution, but still, it works.

Change root directory of Apache2

sorry if this is simple but I looked everywhere online I still cannot find a solution.
- I'm running ubuntu 14 and installed Apache2.
- the problem is that I'm trying to change the root directory to my home directory.
the original directory is /var/www/html and checking permission it belongs to root.
I edited two files,
sudo nano /etc/apache2/sites-available/000-default.conf
sudo nano /etc/apache2/apache2.conf
for the latter I changed, /var/www/html to my home/user1/wwww
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
at one point I even changed permssion of my home/user1/www to www-data:webdev ut I keep getting page forbidden. Can anyone help with this? thanks in advance.

403 Forbidden You don't have permission to access /folder-name/ on this server

I was looking for an answer to my problem, but I could'nt find any answer which solves my case.
The problem is that I can't access the app folders in my var/www/ folder. When I go to localhost/ i get the message that my server is running and I have access to phpmyadmin too. But when I go to any localhost/folder-name i get the 403 error:
Forbidden
You don't have permission to access /folder-name/ on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
How can I solve it? Btw I'm using Ubuntu 13.04, and thanks for your answers. :)
Solved the problem with:
sudo chown -R $USER:$USER /var/www/folder-name
sudo chmod -R 755 /var/www
Grant permissions
under etc/apache2/apache2.conf, you can find one or more blocks that describe the server directories and permissions
As an example, this is the default configuration
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
you can replicate this but change the directory path /var/www/ with the new directory.
Finally, you need to restart the apache server, you can do that from a terminal with the command: sudo service apache2 restart
if permission issue and you have ssh access in root folder
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
will resolve your error
**403 Forbidden **
You don't have permission to access /Folder-Name/ on this server**
The solution for this problem is:
1.go to etc/apache2/apache2.conf
2.find the below code and change AllowOverride all to AllowOverride none
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all Change this to---> AllowOverride none
Require all granted
</Directory>
It will work fine on your Ubuntu server
Solved issue using below steps :
1) edit file "/etc/apache2/sites-enabled/000-default.conf"
DocumentRoot "dir_name"
ServerName <server_IP>
<Directory "dir_name">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory "dir_name">
AllowOverride None
# Allow open access:
Require all granted
2) change folder permission
sudo chmod -R 777 "dir_name"

Fixing 403 Forbidden on alias directory with Apache

I am trying to setup an alias to point to some directory on my filesystem not in DocumentRoot. Now I get a 403 Forbidden response. These are the steps taken:
1. edit http.conf, adding:
Alias /example "/Users/user/Documents/example"
then...
<Directory "/Users/user/Documents/example">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all</Directory>
2. setting permissions with chmod in terminal:
chmod 755 /Users/user/Documents/example
Now it should work? instead I get the access forbidden. This is the output from error_log:
[Sun Jul 24 06:57:57 2011] [error] [client xx.xx.xx.xx] (13)Permission denied: access to /example denied
I was having this issue on OS X too. It turned out gliptak was right, but I've some more detail to add.
We're both attempting to configure a virtual directory for a folder under a user's home folder; I think this is why we're having the problem. In my case, I had the following setup:
Home folder is /Users/calrion.
Virtual directory folder is /Users/calrion/Path/to/www.
There's a symlink /Users/calrion/Path pointing to /Volumes/Other/Users/calrion/Path.
The problem was the user and group _www (which Apache runs as on OS X) lacked execute access to /Users/calrion and /Volumes/Other/Users/calrion.
Running chmod o+x /Users/calrion and chmod o+x /Volumes/Other/Users/calrion resolved the issue (on OS X 10.7.4).
The rule here is that Apache requires execute access to all folders in the path in order to serve files. Without this, you'll get a HTTP 403 (forbidden).
The last straw ;) Required local in the Directory Entry...
like
<Directory "/Users/user/Documents/example">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
Order allow,deny
Allow from all
</Directory>
if everything else doesn't work (correct Alias, Directory Entry in httpd.conf and correct mod/usr/grp).
keep in mind: if you put your site in user-space the apache user (running httpd) needs access to your home!
Check permission on /Users/user/Documents/, /Users/user/ (higher level permissions are enforced first ...)
/bin/su into the user running Apache (like www, www-data) and cat a file in the /Users/user/Documents/example directory. That might point you to permission problems with your setup.
These are all very good answers.
None of them worked for me.
I have an alias specified in OSX server pointing to a user directory. I spent a long while chmodding and messing with _www user, adding executable permissions recursively, uninstalling macports and all sorts of stuff trying to get this to work. I tried 777. Nope. No idea why it wasn't working.
Eventually, I just checked the "shared folder" checkbox in the Finder for that folder, and it worked, on the specified domain, with php active, the way I wanted it to. :/ ...so that was easy.
I was just having this exact same issue. What I found was SE_Linux was enabled, and the security context of the files in my Aliased directory was incorrect, missing httpd_sys_content_t.
You can view the security context with ls -Z. If your files/folders don't have httpd_sys_content_t then apache won't server them up! You can add the proper context with something like chcon -R --type=httpd_sys_content_t /new_html_directory. This will change the context of the files currently in the directory, but not any files that are added afterwards (for that you'll need to work with semanage). Your other option is to just leave the files under /var/www.
Here's what fixed it for me:
in /etc/apache2/httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride None
# REMOVE THESE LINES
#Order deny,allow
#Deny from all
# ADD THIS LINE
Require all denied
</Directory>
This change implements changes made in the apache update from 2.2 to 2.4. The OSX Yosemite update brought the apache update with it (PSA: if you're planning on upgrading to Yosemite, budget yourself a week to fix everything it breaks).
The weird thing is that I already got apache 2.4 working, and suddenly it breaks again....
PSA: if you're planning on upgrading to Yosemite, budget yourself a week to fix everything it breaks
After lots of time waste i fixed the issue and i wanted to share to save your time.
All the gentelmen above and on other posts has some correct parts in their answers but below is the sum
In your "/etc/apache2/httpd.conf" file:
1- change your document root
Original: DocumentRoot "/Library/WebServer/Documents"
Change to: DocumentRoot "/Users/yourname/www"
2- change
Original:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Change to:
<Directory /Users/yourname/www>
Options FollowSymLinks Includes ExecCGI
AllowOverride None
Order deny,allow
Deny from all
</Directory>
3- Change:
Original:
<Directory "/Library/WebServer/Documents">
Change to:
<Directory "/Users/yourname/www">
4- Finally, you might not need this step if you are the supper user, this is to set the right permition on your new root folder
chmod 755 /Users/yourname/www
Hope this will help
It certainly does look right, do a sanity check.
you restarted apache
check group and user ownership
I think the quotes can be removed
there is something in /Users/user/Documents/example ?
try 777
-sean
SELinux was the culprit for me. If you're having this issue on a linux box and your alias and file permissions are correct than try doing a "setenforce 0" to put SELinux into permissive mode. That did the trick for me.
I had to revert my apache config file and then set up the server again. found this useful:
https://apple.stackexchange.com/questions/41143/how-to-revert-default-mac-apache-install-to-original
Quick Solution:
Use these commands as root on Linux:
find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;