Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx configuration for laravel

Tags:

php

nginx

laravel

I created this config file for nginx to access my laravel page:

server {
    listen 80;
    listen [::]:80;

    root /var/www/mfserver/public;
    index index.php index.html index.htm;

    server_name dispo.medifaktor.de;

    location / {
        try_files $uri $uri/ /index.php?is_args$args;
    }

    error_page 404 /index.php;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /var/www/mfserver/public;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }
}

When I call the page dispo.medifaktor.de I see the main page. But when I call http://dispo.medifaktor.de/v1/incidents I get an Server Error 500. Why can't I access the pages?

The routes file is working:

Route::group(['domain' => 'dispo.medifaktor.de', 'namespace' => 'API'], function() {
    Route::group(['prefix' => 'v1', 'namespace' => 'v1'], function() {
        // INCIDENTS ROUTES
        Route::get('/incidents', 'Incidents\APIIncidentController@index');
        Route::post('/incidents', 'Incidents\APIIncidentController@store');
        Route::get('/incidents/{incidents}', 'Incidents\APIIncidentController@show');
        Route::get('/incidents/{incidents}/responders', 'Incidents\APIIncidentResponderController@index');
    });
});

The error.log of nginx states:

2016/05/26 11:22:40 [error] 32590#0: *22 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/mfserver/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /var/www/mfserver/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:97
Stack trace:
#0 /var/www/mfserver/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/mfserver/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /var/www/mfserver/vendor/monolog/monolog/src/Monolog/Logger.php(615): Monolog\Logger->addRecord(400, Object(UnexpectedValueException), Array)
#3 /var/www/mfserver/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\Logger->error(Object(UnexpectedValueException), Array)
#4 /var/www/mfserver/vendor/laravel/framework/src/Illuminate/Log/Writer.php(113): Illuminate\Log\Writer->writeLog('error', Object(UnexpectedV...
PHP message: PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/mfserver/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied' in /var/www/mfserver/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:97
Stack trace:
#0 /var/www/mfserver/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
#1 /var/www/mfserver/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#2 /var/www/mfserver/vendor/monolog/monolog/src/Monolog/Logger.php(615): Monolog\Logger->addRecord(400, Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)
#3 /var/www/mfserver/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\Logger->error(Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)
#4 /var/www/mfserver
like image 961
sesc360 Avatar asked May 26 '16 09:05

sesc360


1 Answers

Most folders should be normal "755" and files, "644".

For nix based OSs. Use the following .

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
like image 57
Gammer Avatar answered Sep 24 '22 19:09

Gammer