I have Laravel(5.7) project and will be deployed to a server (nginx) with multiple projects. I am running the project in my Local machine using Apache and I tried to run it with subdirectory and it is working in my machine.
We have a problem in deployment of my project in subdirectory of the server (nginx), I don't know if the Laravel project has the problem because everytime we go to the http://172.1.1.1/sample of my project it always show the "404 Page not found" of Laravel because Laravel thought that /sample is a path so I think 172.1.1.1/sample runs the Laravel but it didn't make /sample as it's root but when we go to 172.1.1.1 the other project running here is working. What I already did is add the following code in my Laravel project.
In my AppServiceProvider.php - I add the following code:
public function boot()
{
\URL::forceRootUrl(\Config::get('app.url'));
if (str_contains(\Config::get('app.url'), 'https://')) {
\URL::forceScheme('https');
//use \URL:forceSchema('https') if you use laravel < 5.4
}
}
So that when I change the APP_URL in .env of my project, it will work.
APP_URL=http://localhost:9021/sample
And add the following in the .htaccess of my public folder:
RewriteEngine On
RewriteBase /sample/
So it is working for my local machine but this doesn't work when we tried to deploy this. Once we go to 172.1.1.1/sample (sample-ip) it will just show the "404 Page not found".
What I want to know is if there are other way to change the context path of laravel 5.7. Because I am not the one who configure the nginx in the server but I want to make sure that the problem is not because of Laravel 5.7.
Thank you for your help guys.
see this documentation