2

I am trying to set up laravel in a subfolder (laravel-project) of a project. I somehow got the home page to work doing this in the config file: rewrite "/project/home.php" /laravel-project/public/index.php$1;

However I cannot figure out how to get the routing work. I would like that any request containing laravel-project would be redirected to laravel-project/public/index.php so that laravel can figure out which controller and which method are to be called. I did this:

location /laravel-project {
  root /home/www/virtual/mysite/laravel-project/public;
  try_files $uri $uri/ /index.php?$query_string;
}

However, when I try to navigate to mysite/laravel-project or mysite/laravel-project/contacts the application never hits public/index.php file in the laravel-project folder.

Hope the information given is enough. Please let me know if any further info is required, and thank you for helping!

2
  • Check this out. laravel-news.com/subfolder-install. Essentially, you want to make sure that all of the non-public folders and files are not in a public path. This will ensure that users can't browse to sensitive files, especially your .env. Then you'll have to change the location for bootstrapping the app. The article explains all of this. Commented Oct 15, 2017 at 22:53
  • Thank you but I think I am at a an even earlier stage of the set up. I can't get Laravel to work at all, beside the home page, (with a hard redirect) so, I am still stuck there. Commented Oct 16, 2017 at 3:08

3 Answers 3

4

I found a proper configuration for deploy laravel in sub-folder

location /websocket {
    alias /var/www/html/websocket/public;
    try_files $uri $uri/ @websocket;
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                  
    }  
}

location @websocket {
    rewrite /websocket/(.*)$ /websocket/index.php?/$1 last;
}
Sign up to request clarification or add additional context in comments.

Comments

3

I want to put some new updated tips, maybe it's helps somebody :

If you want to put your laravel project in a subfolder on a server with ngnix-ubuntu 16-php.7.2, so here is update ngnix config :

1) your nested(subfolder) isn't inside your main folder

/var/www/main:
/var/www/nested:

then your config :

location /nested {

        alias /var/www/nested/public;

        try_files $uri $uri/ @nested;

               location ~ \.php$ {
                        include fastcgi_params;
                        fastcgi_param SCRIPT_FILENAME $request_filename;
                        fastcgi_pass   unix:/run/php/php7.2-fpm.sock;

                                }
   }

location @nested {
        rewrite /nested/(.*)$ /nested/index.php?/$1 last;
}

2) your laravel-test folder (subfolder) inside your main :

/var/www/main:
/var/www/main/nested:

then your config :

location /laravel-test {

    alias /var/www/main/laravel-test/public;

    try_files $uri $uri/ @laravelTest;

           location ~ \.php$ {
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $request_filename;
                    fastcgi_pass   unix:/run/php/php7.2-fpm.sock;

                            }


  }

location @laravelTest {
        rewrite /laravel-test/(.*)$ /laravel-test/index.php?/$1 last;
}

Comments

1
# megadealer
    location ^~ /megadealer {  
        alias /var/www/choppies/megadealer/public;  
        try_files $uri $uri/ @megadealer;  

        location ~ \.php {  
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
            fastcgi_param SCRIPT_FILENAME /var/www/choppies/megadealer/public/index.php;
        }  
    }  

    location @megadealer {
        rewrite /megadealer/(.*)$ /megadealer/index.php?/$1 last;  
    }
    # end megadealer

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.