问题
I have installed laravel by composer create-project laravel/laravel –-prefer-dist
after this run php artisan serve command to laravel project directory and get this result.
Laravel development server started: http://127.0.0.1:8000
But when i go to http://127.0.0.1:8000 in browser laravel project not running and give error
This site can’t be reached 127.0.0.1 refused to connect.
but http://localhost/laravel/public/ it is working. Can anyone tell me that what is proper way to run this laravel project.
回答1:
Try to run in different port
php artisan serve --port=9000
and then try http://127.0.0.1:9000 will work.
As might be on port 8000 something already running on your system will not make it work.
And you can also run your laravel
project without artisan serve command
If anyone wants to make the application public, the more easy and fastest way is:
- Rename the "server.php" file in root directory, in "index.php"
- Move your .htaccess from public folder to root directory
- Make your directory accessible to Apache2 (set all file permissions to 777).
回答2:
At starting level, you can use url like this http://127.0.0.1:8000 with port-number. but in further level you must working with simple url like http://localhost/laravel/public/. One more thing - you should remove "public" keyword from url, so you access direct your root-project. Review this link - Laravel 5 - Remove public from URL
回答3:
I had that problem too! And couldn't solve it. So I installed openserver from https://ospanel.io/ and put my site on the folder domains (Windows 10), then I just start Open Server and click "My Sites" and choose my site - it opened in my browser which set by default on Open Server program and click the folder on my browser cooled "public" and there you go -> your site is working. I now that isn't solve the problem with cmd and start thought cmd and server like http://127.0.0.1:8000, but you can take access to your local site through http://'your site'/public/'your pages' Good luck!
来源:https://stackoverflow.com/questions/48719658/run-laravel-project-in-localhost