0

I have extracted the laravel.phar contents into c:\www\laravel correctly.

I have two problems which I believe are related.

  • I have to visit localhost/laravel/public/ instead of just localhost/laravel/ to get the default "you have arrived."
  • If I setup a test in app/routes.php labelled 1) below and visit localhost/laravel/public/testdir or localhost/laravel/testdir I get a 404 not found error from nginx

1)

    Route::get('/testdir', function()
    {
        return 'Working';
    });

The Routes seem to be partially working because if I setup are route like 2) below and visit localhost/laravel/public/ I will see "Base test" correctly.

2)

    Route::get('/', function()
    {
        return 'Base test';
    });

My enviroment specifics

  • c:\www\laravel Project Directory.
  • Laravel 4.1
  • Nginx nginx-1.5.12
  • php-5.4.27-nts-Win32-VC9-x86

Nginx.Conf file setup

http {

include       mime.types;
default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;


server {
    listen       80;
    server_name  localhost;

    location / {
        root   C:/www;
        index  index.php index.html index.htm;
    }

    location ~ \.php$ {
        root           C:/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $request_filename;
        include        fastcgi_params;
    }
}
5
  • did you set the documentroot path to laravel/public? you get the same errors when you'd use the builtin server with php artisan serve ? Apr 26, 2014 at 13:35
  • and please post your nginx config
    – VF_
    Apr 26, 2014 at 13:36
  • @zwacky I tried php artisan serve and this seems to fix the problems, visiting localhost:8000 directs to laravel/public and localhost/testdir also redirects accordingly.
    – cecilli0n
    Apr 26, 2014 at 14:53
  • You just need to add/public to your domain route. As detailed by @user3348022 Apr 27, 2014 at 9:50
  • @keithm Have you read the comments under user3348022 answer? It still leaves parts broken unless I assign complete server blocks + cgi settings to cater for each and every Laravel project. There is a workaround I am sure but I do not know it and I have spent 4 hours messing around with all sorts of paths inside Laravel and nginx.conf settings. Its a absolute joke that something so common and fundamental to using Laravel isn't documented by them in the official docs. I will be using the php artisan serve for the time being.
    – cecilli0n
    Apr 27, 2014 at 12:27

1 Answer 1

1

You have to update your nginx config to match the public folder of your laravel installation.

Here's a sample to get you started:

http {

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;


server {
    listen       80;
    server_name  localhost;
    root   C:/www/;

    location / {
        index  index.php index.html index.htm;
    }

    location /laravel/ {
        root   C:/www/laravel/public/;
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$query_string;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $request_filename;
            include        fastcgi_params;
        }
    }

    location ~ \.php$ {
        root           C:/www/;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $request_filename;
        include        fastcgi_params;
    }
}

Make sure to restart nginx after you have made changes to the config!

Update:

Since we now defined C:/www on the server level, everything will be served according to the config made at server level. `location /laravel/ overrides this with its own block. All scripts not located under /laravel/ will work as before...

9
  • After trying this neither now work, I get nginx 404 not found for both localhost/laravel/ and also localhost/laravel/public/
    – cecilli0n
    Apr 26, 2014 at 13:49
  • Have you tried http:://localhost/ ? I also added another line to the location / block...
    – VF_
    Apr 26, 2014 at 13:51
  • Just noticed your edit, I appended the try_files variable, this now changes the previuos error message, my page now displays No input file specified. * for both *localhost/laravel/public and localhost/laravel/
    – cecilli0n
    Apr 26, 2014 at 13:51
  • Ok, If I set my location ~ \.php$ path root likewise, it seems to work However before I mark it I have to test some other non-laravel projects, not sure if this is going to make everything else broken as the settings are just for that laravel directory
    – cecilli0n
    Apr 26, 2014 at 13:57
  • Well if you want to server other directories else than this particular one, you would have to copy the location / block and alter it to match your other folders, of course.. e.g. location /laravel and location /and location /myproject
    – VF_
    Apr 26, 2014 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.