问题
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?
回答1:
Create and put this .htaccess file in your laravel installation folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
回答2:
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>
回答3:
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!
回答4:
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 :)
回答5:
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.
回答6:
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 does the trick
# 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>
回答7:
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
回答8:
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
回答9:
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!
回答10:
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
回答11:
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
回答12:
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 */
/*******************************************************/
}
/* ... */
}
回答13:
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! :)
回答14:
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.
回答15:
This is solved my problem by adding this line:
DirectoryIndex index.php
回答16:
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!
回答17:
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.
回答18:
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
回答19:
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"
回答20:
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.
回答21:
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
回答22:
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
来源:https://stackoverflow.com/questions/18272557/laravel-forbidden-you-dont-have-permission-to-access-on-this-server