[linux] Apache VirtualHost 403 Forbidden

I recently tried to set a test server up with Apache. The site must run under domain www.mytest.com. I always get a 403 Forbidden error. I am on Ubuntu 10.10 server edition. The doc root is under dir /var/www. The following are my settings:

Content of /var/www

ls -l /var/www/

total 12
drwxr-xr-x 2 root root 4096 2011-08-04 11:26 mytest.com
-rwxr-xr-x 1 root root 177 2011-07-25 16:10 index.html

Content of the host file on the server (with IP 192.168.2.5)

cat /etc/hosts

127.0.0.1 localhost 
127.0.1.1 americano
192.168.2.5 americano.mytest.com www.mytest.com

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Site config

<VirtualHost *>
ServerAdmin [email protected]
ServerName www.mytest.com
ServerAlias mytest.com

DocumentRoot "/var/www/mytest.com"

ErrorLog /var/log/apache2/mytest-error_log
CustomLog /var/log/apache2/mytest-access_log combined

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/mytest.com">
Options -Indexes FollowSymLinks
AllowOverride None

Order allow,deny
Allow from all
</Directory>
</VirtualHost>

I have no .htaccess file in my doc root. The permissions are set correctly (readable by www-data).

If I type in the IP address from my desktop, the site shows up correctly. I changed the hosts file on my desktop to point www.mytest.com to the server's IP. When I use it, I get 403. Since many functions of this site are sitename-sensitive, I have to be able to access the site by the domain name.

Another funky thing is, even if all log files are created properly, they have no information regarding this error.

I am stuck. Can anybody help?

This question is related to linux apache ubuntu virtualhost http-status-code-403

The answer is


Apache 2.4.3 (or maybe slightly earlier) added a new security feature that often results in this error. You would also see a log message of the form "client denied by server configuration". The feature is requiring a user identity to access a directory. It is turned on by DEFAULT in the httpd.conf that ships with Apache. You can see the enabling of the feature with the directive

Require all denied

This basically says to deny access to all users. To fix this problem, either remove the denied directive (or much better) add the following directive to the directories you want to grant access to:

Require all granted

as in

<Directory "your directory here">
   Order allow,deny
   Allow from all
   # New directive needed in Apache 2.4.3: 
   Require all granted
</Directory>

Move the Directory clause out of the virtualhost, and put it before declaring the virtualhost.

Drove me nuts for a long time too. Don't know why. It's a Debian thing.


I had this issue on Arch Linux too... it costs me some time but I'm happy now that I found my mistake:

My directory with the .html files where in my account.
I set everything on r+x but I still got the 403 error.
Than I went completely back and tried to set my home-directory to execute which solved my problem.


For apache Ubuntu 2.4.7 , I finally found you need to white list your virtual host in apache2.conf

# access here, or in any related virtual host.
<Directory /home/gav/public_html/>
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

I was having the same problem with a virtual host on Ubuntu 14.04

For me the following solution worked:

http://ubuntuforums.org/showthread.php?t=2185282

It's just adding a <Directory > tag to /etc/apache2/apache2.conf


It could be you haven't setup PHP~!


The problem was that the file access permission was wrong.

I changed the permissions of the directory and it worked.


This works on Linux Fedora for VirtualHost : ( Lampp/Xampp )

Go to : /opt/lampp/etc/extra

Open : httpd-vhosts.conf

Insert this in httpd-vhosts.conf

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/opt/lampp/APPS/My_App"
ServerName votemo.test
ServerAlias www.votemo.test
ErrorLog "logs/votemo.test-error_log"
CustomLog "logs/votemo.test-access_log" common
<Directory "/opt/lampp/APPS/My_App">
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

p.s. : Don't forget to comment the previous exemple already present in httpd-vhosts.conf

Set your hosts system file :

Go to : /etc/ folder find hosts file ( /etc/hosts )

I insert this : (but not sure to 100% if this good)

127.0.0.1       votemo.test

::1         votemo.test

-> Open or Restart Apache.

Open a console and paste this command for open a XAMPP graphic interface :

sudo /opt/lampp/manager-linux-x64.run

Note : Adjust path how you want to your app folder

ex: DocumentRoot "/home/USER/Desktop/My_Project"

and set directory path too :

ex : ... <Directory "/home/USER/Desktop/My_Project"> ...

But this should be tested, comment if this work ...

Additionnal notes :

  • Localisation Lampp folder : (Path) /opt/lampp

  • Start Lampp : sudo /opt/lampp/lampp start

  • Adjust rights if needed : sudo chmod o+w /opt/lampp/manager-linux-x64.run

  • Path to hosts file : /etc/hosts


I just spent several hours on this stupid problem

First, change permissions using this in terminal

find htdocs -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +

I don't know what the difference is between 664 and 775 I did both 775 like this Also htdocs needs the directory path for instance for me it was

/usr/local/apache2/htdocs 

find htdocs -type f -exec chmod 775 {} + -o -type d -exec chmod 775 {} +

This is the other dumb thing too

make sure that your image src link is your domain name for instance

src="http://www.fakedomain.com/images/photo.png"

Be sure to have

EnableSendfile off in httpd.conf file
EnableMMAP off in httpd.conf file

You edit those using pico in terminal

I also created a directory for images specifically so that when you type in the browser address bar domainname.com/images, you will get a list of photos which can be downloaded and need to be downloaded successfully to indicate image files that are working properly

<Directory /usr/local/apache2/htdocs/images>
AddType images/png .png
</Directory>

And those are the solutions I have tried, now I have functioning images... yay!!!

Onto the next problem(s)


This may be a permissions problem.

every single parent path to the virtual document root must be Readable, Writable, and Executable by the web server httpd user

according to this page about Apache 403 errors.

Since you're using Allow from all, your order shouldn't matter, but you might try switching it to Deny,Allow to set the default behavior to "allowing."


If you did everything right, just give the permission home directory like:

sudo chmod o+x $HOME

then

sudo systemctl restart apache2

Examples related to linux

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt?

Examples related to apache

Enable PHP Apache2 Switch php versions on commandline ubuntu 16.04 Laravel: PDOException: could not find driver How to deploy a React App on Apache web server Apache POI error loading XSSFWorkbook class How to enable directory listing in apache web server Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details How to enable php7 module in apache? java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing while starting Apache server on my computer

Examples related to ubuntu

grep's at sign caught as whitespace "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? "Repository does not have a release file" error ping: google.com: Temporary failure in name resolution How to install JDK 11 under Ubuntu? How to upgrade Python version to 3.7? Issue in installing php7.2-mcrypt Install Qt on Ubuntu Failed to start mongod.service: Unit mongod.service not found

Examples related to virtualhost

how to create virtual host on XAMPP Site does not exist error for a2ensite nginx missing sites-available directory Apache VirtualHost and localhost Apache error: _default_ virtualhost overlap on port 443 Adding VirtualHost fails: Access Forbidden Error 403 (XAMPP) (Windows 7) client denied by server configuration Apache VirtualHost 403 Forbidden How to debug an apache virtual host configuration? Apache default VirtualHost

Examples related to http-status-code-403

Nginx 403 error: directory index of [folder] is forbidden HTTP error 403 in Python 3 Web Scraping MVC4 HTTP Error 403.14 - Forbidden Error message "Forbidden You don't have permission to access / on this server" WAMP 403 Forbidden message on Windows 7 Apache VirtualHost 403 Forbidden Nginx 403 forbidden for all files Emulate a 403 error page 403 Forbidden vs 401 Unauthorized HTTP responses Apache gives me 403 Access Forbidden when DocumentRoot points to two different drives