0

I am new to web development and completed some practise project on xampp on windows. without using laravel i used to access my website by typing 'localhost/myproject' but in laravel it doesnot work.

i have few quesions -

  1. what does php artisan serve do internally?

  2. After running command php artisan serve why we can only access our project by '127.0.0.1:8000/myproject' instead why we cant use 'localhost:8000/myproject'.

Dhairya Lakhera
  • 4,445
  • 3
  • 35
  • 62

2 Answers2

1

The artisan serve command uses the Built-in web server from PHP itself.

The reason you can't use localhost is probably the fault of your OS. You have to add the localhost alias to your hosts file which can be located in different places depending on your operating system.

Jerodev
  • 32,252
  • 11
  • 87
  • 108
0

You can access your project without IP address like localhost/myproject/public without doing anything but keep in mind every time you have to put public word. If want to remove public word and access like as normal php project from localhost example localhost/myproject then do these simple steps.

  1. Cut files (index.php, .htaccess and robots.txt) from public directory from your laravel project and paste files to root of your project.
  2. Now open the index.php file and change the lines like below and save.

require __DIR__ . '/bootstrap/autoload.php';

$app = require_once __DIR__ . '/bootstrap/app.php';

Now you can easily access your project without IP address :)

For better understanding you can watch this YouTube video. (Bangla Language) https://www.youtube.com/watch?v=PvuI1UiYIo4

Harun
  • 1,137
  • 1
  • 9
  • 7
  • That's a terrible way to work. All public files should always be in your `public/` folder. What you are describing is very insecure! – Jerodev Jul 30 '19 at 09:07
  • Could you please give an explanation or practical example why it's insecure! – Harun Jul 30 '19 at 09:17
  • I didn't mention all files. Just `index.php`, `.htaccess` and `robots.txt`. It'll work if only move `index.php` file only and re-link the `autoloader.php` and `app.php`. Could you please give an explanation or practical example why it's insecure! @Jerodev – Harun Jul 30 '19 at 09:24
  • Because if you set your web root to the root of your application, all config and environment files are publicly available. Also, that's not how Laravel is supposed to be used. – Jerodev Jul 30 '19 at 09:27
  • It's the batter way to remove hassle to run every time `php artisan serve` on local development and it's the way I have found to deploy the application without changing anything on Share Hosting (N.B - Maximum share hosting provider disable the ssh access to run artisan command). I did not find any security issue and all environment and config files is not available for public. https://stackoverflow.com/questions/28364496/laravel-5-remove-public-from-url – Harun Jul 30 '19 at 09:37