0

I've hit a wall while setting up a new localhost on windows 8. The setup was done with laragon (3.0.5) and is comprised of:

  • php 7.1.5
  • laravel 5.4.24
  • nginx 1.12.0

The config file for nginx is

server {
    listen 8080;
    server_name new_project.dev *.new_project.dev;
    root "C:/lar/laragon/www/new_project/dir1/";

    index index.html index.htm index.php;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass php_upstream;      
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }


    charset utf-8;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    location ~ /\.ht {
        deny all;
    }
}

in routes/web.php I have added the following route

Route::get('/foo', function () {
    return 'Everything is awesome!';
});

I would expect when going to http://new_project.dev:8080/dir1/public/foo to see the string "Everything is awesome!", instead i get a 404 from nginx.

Absolutely any help will be more than appreciated.

---- UPDATE 1 ----

Again in routes/web.php there is the following route

Route::get('/', function () {
    return 'You are on the home page.';
});

When I go to http://new_project.dev:8080/dir1/public/ I get a 200 and the expected string.

ek_1234
  • 1
  • 2
  • Aren't you forgetting the `.dev` extension in the url you tried? – Douwe de Haan Jun 09 '17 at 13:13
  • Updated the post. To clarify, I am trying with http://new_project.dev:8080/dir1/public/foo and still getting a 404 – ek_1234 Jun 09 '17 at 13:16
  • To get the message you need to route to `http://new_project.dev:8080/dir1/foo` – linktoahref Jun 09 '17 at 13:19
  • The only thing I can think of is that the `dir1` is obsolete and should be removed from the URL. I don't have any experience with Laragon, so I can't help you with that. – Douwe de Haan Jun 09 '17 at 13:19
  • @linktoahref given that in the config file root has been set to "C:/lar/laragon/www/new_project/dir1/", am i missing something in the route that has been set for foo? – ek_1234 Jun 09 '17 at 13:25
  • @ek_1234 : Are you still getting `404` error? – linktoahref Jun 09 '17 at 13:27
  • @linktoahref yep – ek_1234 Jun 09 '17 at 13:32
  • Apparently it laragon which was overwriting the root somewhere. So for me the solution was to select the root directory in laragon via Menu->www->Switch Document Root->Select another and selecting the target root directory. – ek_1234 Jun 11 '17 at 19:27

3 Answers3

2

You are using Laragon's power but you destroyed it with wrong setting and wrong url.

Your setting must like this: (note the public/)

 root "C:/lar/laragon/www/new_project/dir1/public/";

Now, your life is easier - this url should work:

http://new_project.dev:8080/foo

lanlele
  • 41
  • 2
  • Unfortunately I had also tried it out earlier as well as now again to double check and still not working – ek_1234 Jun 09 '17 at 16:07
  • Actually when i set the root to "C:/lar/laragon/www/new_project/dir1/public/" the home page is still accessible only from http://new_project.dev:8080/dir1/public/ which implies the root isn't respected. Please correct me if i'm wrong. – ek_1234 Jun 09 '17 at 16:09
0

new_project/dir1/ is a part of your root directive and it must not be in request as all file and script searches are doing relative to it. Correct request is http://new_project.dev:8080/public/foo

Alexander Ushakov
  • 5,139
  • 3
  • 27
  • 50
  • Updated the post with an extra route which does work. Unfortunately your suggested url did not work. – ek_1234 Jun 09 '17 at 13:33
0

With your current configuration I think this make work. I updated the try_files index.php location

server {
    listen 8080;
    server_name new_project.dev *.new_project.dev;
    root "C:/lar/laragon/www/new_project/dir1/";

    index index.html index.htm index.php;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass php_upstream;      
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }


    charset utf-8;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    location ~ /\.ht {
        deny all;
    }
}

Although I am not sure about your configuration, I would suggest you set your project root to the public folder instead of having to do /public. You would then leave the try_files from above as it once was.

Laravel Homestead is also a great choice for setting up a dev enviroment: https://laravel.com/docs/5.4/homestead

fppz
  • 409
  • 2
  • 9