I am having a very frustrating error. I am trying to move my local environment up to a server. It is working fine on my localhost, but I get a 403 forbidden error on all routes that require to be logged in. I can get to /login and login, but accessing the middleware routes spits out the 403.
Sidenote: I am using the same database from local as I am doing on production (Direct IP address instead of localhost). The database is hosted on the same server as production env.
Steps I have taken to move to the production environment:
- git clone the repo
- adjust the .env file to reflect production environment (debug false, env production)
- composer install
- php artisan storage:link (required for images)
- setup nginx to the domain
Here are some relevant files:
routes/web.php:
Auth::routes(['register' => false]);
Route::prefix('cms')->middleware('auth')->group(function() {
Route::get('/', 'Cms\CmsController@index')->name('cms.index');
Route::post('/upload', 'Cms\PhotoController@storeMedia')->name('photo.storeMedia');
Route::resource('projects', 'Cms\ProjectController', ['except' => ['store', 'show']]);
Route::resource('customers', 'Cms\CustomerController', ['except' => ['store']]);
Route::resource('users', 'Cms\UserController', ['except' => ['store', 'show']]);
});
Route::get('/over-ons', 'Site\SiteController@about')->name('site.about');
Route::get('/portfolio/{id}/{slug}', 'Site\SiteController@project')->name('site.project');
Route::get('/portfolio', 'Site\SiteController@projects')->name('site.projects');
Route::get('/diensten', 'Site\SiteController@services')->name('site.services');
Route::get('/klanten', 'Site\SiteController@customers')->name('site.customers');
Route::get('/contact', 'Site\SiteController@contact')->name('site.contact');
Route::get('/', 'Site\SiteController@index')->name('site.index');
Nginx subblock:
server {
listen 80;
root /sites/mediafox/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name [removed for privacy];
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
# fastcgi_pass 127.0.0.1:9000;
}
location ~ /\.ht {
deny all;
}
}
ls -l on root (permissions):
drwxrwxr-x 2 niels niels 4096 Nov 16 16:44 _dev
drwxrwxr-x 6 niels niels 4096 Nov 16 16:44 app
-rw-rw-r-- 1 niels niels 1686 Nov 16 16:44 artisan
drwxrwxr-x 3 niels niels 4096 Nov 16 16:44 bootstrap
-rw-rw-r-- 1 niels niels 1716 Nov 16 16:44 composer.json
-rw-rw-r-- 1 niels niels 208784 Nov 16 16:44 composer.lock
drwxrwxr-x 2 niels niels 4096 Nov 16 16:44 config
drwxrwxr-x 5 niels niels 4096 Nov 16 16:44 database
-rw-rw-r-- 1 niels niels 432338 Nov 16 16:44 package-lock.json
-rw-rw-r-- 1 niels niels 1307 Nov 16 16:44 package.json
-rw-rw-r-- 1 niels niels 1297 Nov 16 16:44 phpunit.xml
drwxrwxr-x 6 niels niels 4096 Nov 16 17:01 public
drwxrwxr-x 6 niels niels 4096 Nov 16 16:44 resources
drwxrwxr-x 2 niels niels 4096 Nov 16 16:44 routes
-rw-rw-r-- 1 niels niels 563 Nov 16 16:44 server.php
drwxrwxr-x 6 www-data www-data 4096 Nov 16 16:44 storage
drwxrwxr-x 4 niels niels 4096 Nov 16 16:44 tests
drwxrwxr-x 49 niels niels 4096 Nov 16 16:46 vendor
-rw-rw-r-- 1 niels niels 724 Nov 16 16:44 webpack.mix.js
So to conclude: My routes that don't require to be logged in are working fine. The problem arises when I try to visit an url which requires middleware 'auth'.
Any help would be much appreciated.
-- UPDATE 1 --
Seems to be related to Nginx. I have this in my Nginx logs:
2019/11/17 14:40:09 [error] 1525#1525: *335 directory index of "/sites/mediafox/public/cms/" is forbidden, client: [ip removed], server: www.mediafox.*****.nl, request: "GET /cms/ HTTP/1.1", host: "mediafox.******.nl"
auth
middleware to yoursite.contact
route, do you also get the 403? - lagboxphp artisan session:table
and thenphp artisan migrate
. That should solve your issue - Pavel Lint