在没有php artisan服务的情况下运行laravel 5应用 [英] Run laravel 5 app without php artisan serve

查看:96
本文介绍了在没有php artisan服务的情况下运行laravel 5应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在laravel 5.2中创建了一个小型博客应用程序.只要我使用php artisan服务运行该应用程序,该应用程序就可以正常工作.但是在没有运行artisan serve的情况下,例如当我从公用文件夹访问它时localhost/blog/public/addBlog,它显示未找到错误页面.

I have created small blog application in laravel 5.2 .the app works whenever i run it using php artisan serve. But without running artisan serve , when i access it from public folder for e.g. localhost/blog/public/addBlog it gives error page not found.

我的routes.php具有以下几行路线:: get('addBlog','BlogsController');

My routes.php has following lines Route::get('addBlog','BlogsController');

与php artisan服务配合使用时效果很好,请访问 http://localhost:8000/addBlog

It works fine with php artisan serve with visiting http://localhost:8000/addBlog

推荐答案

解决方案非常简单.Laravel希望您的公用文件夹是webserver/url/domain的根目录.

The solution is pretty simple. Laravel expects your public folder to be the root of the webserver / url / domain.

使用serve命令是有效的,因为那时localhost:8000是根.

Using the serve command works since localhost:8000 is the root then.

使用更长的url无效,因为您的根目录是localhost/blog而不是localhost.

Using the longer url doesn't work since your root is localhost/blog not localhost.

一个相当简单的解决方案是创建一个虚拟主机,以解释您如何做到这一点,我们需要知道您的本地主机(xampp?wamp?)上正在运行什么.

A fairly simple solution is to create a virtualhost, to explain how you can do this we would need to know what is running on your localhost (xampp? wamp?)

不过,解决方案将是指向localhost/blog/public的虚拟主机

Nevertheless, the solution would be a virtualhost pointing to localhost/blog/public

更新虚拟主机示例

C:\ Windows \ System32 \ drivers \ etc \ hosts =>以管理员身份打开并添加

C:\Windows\System32\drivers\etc\hosts => open as admin and add

127.0.0.1 blog.dev

C:\ wamp \ bin \ apache \ apache2.4.9 \ conf \ extra \ httpd-vhosts.conf

C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
  ServerName blog.dev
  DocumentRoot "C:\wamp\www\blog\public"
  ServerAlias blog.dev
</VirtualHost>

xampp基本上相同,但虚拟主机conf的路径不同

It's basically the same for xampp, but the path to the vhosts conf is different

完成更改后,请不要忘记重新启动wamp/xampp.然后只需通过浏览器打开 http://blog.dev 并享受

Don't forget to restart wamp/xampp after doing the changes. Then simply open http://blog.dev via browser and enjoy

这篇关于在没有php artisan服务的情况下运行laravel 5应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆