Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant 403 Forbidden

I've been running Vagrant successfully for about a week. Last night I ran vagrant reload and now I can no longer access my sites.

  • VirtualBox version 4.2.16
  • Vagrant version 1.2.7
  • My Vagrantfile and bootstrap.sh: https://github.com/kriskd/vagrant-settings
  • Running on Mac

My files live at /vagrant/Sites. At first my "welcome page" which lives at /vagrant/Sites rendered at

http://localhost:4567/ 

All my projects are folders under Sites. For example, /vagrant/Sites/test won't render index.html. I get the following

Forbidden

You don't have permission to access / on this server. Apache/2.4.6 (Ubuntu) Server at localhost Port 4567

The vhost looks like:

<VirtualHost *:80>
  DocumentRoot "/vagrant/Sites/test"
  ServerName test
  <Directory "/vagrant/Sites/test">
    AllowOverride All
  </Directory>
</VirtualHost>

The vhosts are owned by root. My project files are owned by vagrant and chmod'ed 0777.

After no success, I did a full vagrant destroy followed by vagrant up and then the localhost host welcome page stopped rendering as well with the forbidden error.

like image 315
Kris Avatar asked Aug 06 '13 10:08

Kris


People also ask

What is a 403 Forbidden error?

Here are some examples of 403 error messages: Often, 403 forbidden errors are caused by an access misconfiguration on the client-side, which means you can usually resolve the issue yourself. A common cause of these errors is the file or folder permission settings, which control who can read, write, and execute the file or folder.

How do I prevent 403 errors on my website?

If you operate the website in question, and you want to prevent 403 errors in these cases, enable directory browsing in your web server software. Clear your browser's cache. Issues with a cached version of the page you're viewing could be causing 403 Forbidden issues.

What does the error message 401 Unauthorized mean?

The error message could mean that you need additional access before you can view the page. Typically, a website produces a 401 Unauthorized error when special permission is required, but sometimes a 403 Forbidden is used instead.

What does 403 mean on a website?

Clear Your Web History/Cache 403 is an HTTP status code, which is a standard response code from the web server to the client’s browser. When there is an error, these codes communicate the cause of the problem so that users know why the page isn’t loading.


2 Answers

My hunch is that this is not a vagrant issue at all but solely an Apache configuration glitch. There are a few things I can think to check.

First, obviously, is to confirm that the user that apache is running under has read and execute permissions for the DocumentRoot folder.

Since you mentioned Apache 2.4, there have been changes in the configs from 2.2. Make sure your Allow from all statements now read Require all granted. (If you were still on 2.2, you'd want to make sure they said Allow from all instead of Deny from all.) In either case, you can set this in each <VirtualHost> individually, or set a default in your <Directory /> block of the main httpd.conf file.

Getting more obscure, you could check for selinux, although I'm pretty sure this isn't present in Ubuntu by default. (It is in CentOS, for example.)

like image 58
beporter Avatar answered Sep 28 '22 10:09

beporter


This is solved and in the end came down to some very simple things.

  • Use "Require All granted" instead of "Allow from All"
  • Put each websites' content at the same level namely /vagrant/Sites/default, /vagrant/Sites/test, /vagrant/Sites/real-site
  • Add .conf extension to vhost names such as test.conf and real-site.conf
  • Add AllowOverride All to vhosts to respect sites' .htaccess file (I realize that was in my original post, it got lost as I tried to solve this)

All very basic things that eluded me for a better part of a week. I hope this can help someone else.

like image 31
Kris Avatar answered Sep 28 '22 09:09

Kris