0

I have a new laravel 8 installation which I have changed the index directory to the based_path() directory. That is the root folder of fresh laravel installation.

Now whenever I run php artisan serve It says that the $_SERVER['DOCUMENT_ROOT'] is the same as laravel public_path.

But when I use the default php -S 127.0.0.1:8000

I got the document root as the base url and public_path() as $_SERVER['DOCUMENT_ROOT']/public which is the way I want php artisan serve to be.

My question is how can I configure laravel to use the base_path() ie the index directory as the $_SERVER['DOCUMENT_ROOT']

When running php artisan serve.

I want the index directory to be $_SERVER['DOCUMENT_ROOT'] and the directory returned by public_path() to be $_SERVER['DOCUMENT_ROOT']/public.

This issue is only when running php artisan serve.

Everything else is working fine when using virtual host, or php -S localhost:8000.

If you can direct me to the file that is generating the $_SERVER['DOCUMENT_ROOT'] When php artisan serve is ran, I think the problem will be solved.

Emmanuel David
  • 410
  • 7
  • 17
  • "_I have changed the index directory to the base directory_" What does that mean? What is the index directory? And why change any paths in Laravel anyway? – brombeer Apr 17 '21 at 09:31
  • "_It says that the $_SERVER['DOCUMENT_ROOT'] is the same as laravel public_path_" That's how it's supposed to work, yes. What's wrong with that? The `public` folder is where files are served from – brombeer Apr 17 '21 at 09:33
  • @brombeer It's supposed to be served like that, but when I used ``'php -S localhost:8000``' the document root changes,. And I don't want to change the public path by doing app bind public path in the appServiceProvider – Emmanuel David Apr 17 '21 at 09:36
  • Because the [PHP webserver](https://www.php.net/manual/en/features.commandline.webserver.php) uses the current folder as docroot. Use `php -S localhost:8000 -t public/` to start from the public folder. Or ... don't use it at all but `php artisan serve` only – brombeer Apr 17 '21 at 09:39
  • I don't want to start server in the public path but base path. While using php artisan serve – Emmanuel David Apr 17 '21 at 09:46
  • Ok, got it. But why? For what reason? – brombeer Apr 17 '21 at 09:49
  • It's the way I want to build the application, making it easy to install and as well maintaining the default public folder during the artisan command and other ```server start``` settings – Emmanuel David Apr 17 '21 at 09:54
  • There are security/vulnerability reasons for keeping functionality/files out of a publicly served folder. Start a server using `php -S localhost:8000` and navigate to `http://localhost:8000/.env` - _everybody_ can see your database credentials and other sensitive information. Good luck – brombeer Apr 17 '21 at 10:07

0 Answers0