Laravel - Forbidden You don't have permission to access / on this server

LaravelLaravel 4

Laravel Problem Overview


My laravel installation was working fine yesterday but today I get the following error:

Forbidden

You don't have permission to access / on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

Does anyone know where I am going wrong?

Laravel Solutions


Solution 1 - Laravel

Create and put this .htaccess file in your laravel installation(root) folder.

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Solution 2 - Laravel

For me, It was just because I had a folder in my public_html named as same as that route!
so please check if you don't have a folder with the address of that route!
hope be helpful

Solution 3 - Laravel

I met the same issue, then I do same as the solution of @lubat and my project work well. :D My virtualhost configuration:

<VirtualHost *:80>
     ServerName laravelht.vn
     DocumentRoot D:/Lavarel/HTPortal/public
     SetEnv APPLICATION_ENV "development"
     <Directory D:/Lavarel/HTPortal/public>
         DirectoryIndex index.php
         AllowOverride All
		 Require all granted
         Order allow,deny
         Allow from all
     </Directory>
 </VirtualHost>

Solution 4 - Laravel

Check your virtual host configuration. For Ubuntu you could find it at /etc/apache2/sites-available/yourlaravel.conf It should be like this:

<VirtualHost *:80>
ServerName yourlaravel.com
DocumentRoot "/path/to/your/laravel/project/public"
ServerAlias *.yourlaravel.com

<Directory "/path/to/your/laravel/project/public">
	AllowOverride All
    Require all granted
</Directory>

The key line is Require all granted inside <Directory>.

Hope it helps!

Solution 5 - Laravel

Have you tried to change the .htaccess file that laravel suggested if the default one doesn't work? I had this similar problem and changed it to

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

and it soleved :)

Solution 6 - Laravel

Just add a .htaccess file in your root project path with the following code to redirect to the public folder:

.HTACCESS

## Redirect to public folder
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ public/ [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>

Very simple but work for me in my server.

Regards!

Solution 7 - Laravel

For those who using Mamp or Mamp pro:

Open MAMP Pro
Click on “Hosts”
Click on “Extended” (UPDATE: Only if you are using MAMP Pro 3.0.6)
Check “Indexes”
Click “Save”
That’s it! Reload your localhost starting page and it should work properly.

Solution 8 - Laravel

With me the problem appeared to be about the fact that there was no index.php file in the public_html folder. When I typed in this address however: http://azxcvfj.org/public , it worked (this address is just an example. It points to nowhere). This made me think and eventually I solved it by doing the following.

I made a .htaccess file in the app's root folder (the public_html folder) with this contents:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ public/index.php [L]
</IfModule>

And this worked. With this file you are basically saying to the server (Apache) that whenever someone is trying to access the public html folder(http://azxcvfj.org) that someone who is being redirected is redirected to http://azxcvfj.org/public/index.php

Solution 9 - Laravel

It was solved for me with the Laravel default public/.htaccess file adding an extra line:

The /public/.htaccess file remains as follows:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    DirectoryIndex index.php # <--- This line

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Solution 10 - Laravel

In your VirtualHost write the DocumentRoot to point to your Laravel Application in your home directories. In addition you must add the Directory shown below, with your own path:

<Directory /home/john/Laravel_Projects/links/public/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    Require all granted
</Directory>

The second step, you must go to your Laravel Project and run the following command.

sudo chmod -R 777 storage bootstrap/cache

At the end restart your apache2:

sudo service apache2 restart

Solution 11 - Laravel

First, update your Virtual Host configuration;

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html/example-project/public
    <Directory /var/www/html/example-project/public/>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Then, change both permission and ownership of the asset as illustrated below.

$ sudo chgrp -R www-data /var/www/html/example-project
$ sudo chmod -R 775 /var/www/html/example-project

Solution 12 - Laravel

This is solved my problem by adding this line:

DirectoryIndex index.php

Solution 13 - Laravel

In my case, this error was due to internal links in the server, PHP wasn't able to access those folders unless the proper option for that was added to .htaccess.

Add the following line after RewriteEngine On:

Options +FollowSymLinks

Solution 14 - Laravel

Chances are that, if all the answers above didn't work for you, and you are using a request validation, you forgot to put the authorization to true.

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class EquipmentRequest extends FormRequest {
  /**
   * Determine if the user is authorized to make this request.
   *
   * @return bool
   */
  public function authorize() {
    /*******************************************************/
    return true; /************ THIS VALUE NEEDS TO BE TRUE */
    /*******************************************************/
  }

  /* ... */
}

Solution 15 - Laravel

If you have tried all .htaccess answers from comments and none of them worked, it's possible that actually you have bad APP_URL in you .env config file. That worked for me.

Solution 16 - Laravel

For my case was encountering this issue with Laravel 6.x and managed to sort it out by installing an SSL Certificate. Tried playing around with .htaccess but never worked. I'm using the default Laravel 6.x .htaccess file which has the following contents

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Solution 17 - Laravel

I had the same problem and builded a .htaccess file to fix this issue with a few more improvements. You can use it as it is, just download it from Github Gist and change the filename "public/index.php" to "public/app.php" and see how it works! :)

Solution 18 - Laravel

For me this was simply calling route() on a named route that I had not created/created incorrectly. This caused the Forbidden error page.

Restarting the web server allowed proper Whoops! error to display:

> Route [my-route-name] not defined.

Fixing the route name ->name('my-route-name') fixed the error.

This is on Laravel 5.5 & using wampserver.

Solution 19 - Laravel

I had a problem with non-www website URL version - the PUT method has been not working. But when entering the website with www. - it works fine!

Solution 20 - Laravel

I had this error and i just pasted the http://127.0.0.1:8000/ directly into the url bar. you get the below when you type : php laravel serve

i was putting in localhost/http://127.0.0.1:8000/ to get the error you mentioned.

Solution 21 - Laravel

On public/.htaccess edit to

<IfModule mod_rewrite.c>
 <IfModule mod_negotiation.c>
              Options -MultiViews
          </IfModule>

          RewriteEngine On

          # Redirect Trailing Slashes If Not A Folder...
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_URI} (.+)/$
          RewriteRule ^ %1 [L,R=301]

          # Handle Front Controller...
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteRule ^ index.php [L]

          # Handle Authorization Header
          RewriteCond %{HTTP:Authorization} .
          RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

In the root of the project add file

Procfile

File content

web: vendor/bin/heroku-php-apache2 public/

Reload the project to Heroku

bash
heroku login
cd my-project/
git init
heroku git:remote -a my project
git add .
git commit -am "make it better"
git push heroku master
heroku open

Solution 22 - Laravel

The problem is the location of the index file (index.php).You must create a symbolic link in the root of the project to public/index.php with the command "ln-s public/index.php index.php"

Solution 23 - Laravel

You might be facing the file permissions issue. Verify your htacces file, did it change from yesterday ? Also, if you were doing any "composer update" or "artisan optimize" stuff, try chowning your laravel project folder for your username.

chown -R yourusername yourlaravelappfolder 

EDIT: the problem is possibly due to your local file permissions concerning Vagrant. Try to

set the permissions to the Vagrantfile containing folder to 777

Solution 24 - Laravel

I've found solution

I put following code into my public/.htaccess and now its running at rocket speed :D

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpanthroView Question on Stackoverflow
Solution 1 - LaravelAlexeyView Answer on Stackoverflow
Solution 2 - LaravelAliView Answer on Stackoverflow
Solution 3 - LaravelHieu Tran AGIView Answer on Stackoverflow
Solution 4 - LaravellubartView Answer on Stackoverflow
Solution 5 - LaravelMohammad Shoriful Islam RonjuView Answer on Stackoverflow
Solution 6 - LaravelRadames E. HernandezView Answer on Stackoverflow
Solution 7 - LaravelDPPView Answer on Stackoverflow
Solution 8 - LaravelPieterVKView Answer on Stackoverflow
Solution 9 - LaravelEvhzView Answer on Stackoverflow
Solution 10 - LaravelIoannis ChrysochosView Answer on Stackoverflow
Solution 11 - LaravelYvesView Answer on Stackoverflow
Solution 12 - LaravelPirman DwianaView Answer on Stackoverflow
Solution 13 - LaravelAntónio AlmeidaView Answer on Stackoverflow
Solution 14 - LaravelAmin NAIRIView Answer on Stackoverflow
Solution 15 - LaravelAntonije PavlicekView Answer on Stackoverflow
Solution 16 - LaravelSoftware DeveloperView Answer on Stackoverflow
Solution 17 - LaraveldudeView Answer on Stackoverflow
Solution 18 - LaravelAndrewView Answer on Stackoverflow
Solution 19 - LaravelGediminasView Answer on Stackoverflow
Solution 20 - LaravelDonQueryView Answer on Stackoverflow
Solution 21 - LaravelAnees Al-AhsabView Answer on Stackoverflow
Solution 22 - LaravelHeretic SicView Answer on Stackoverflow
Solution 23 - LaravelGadomaView Answer on Stackoverflow
Solution 24 - Laravelafrasiyab haiderView Answer on Stackoverflow