简体   繁体   English

使用命令“php artisan serve”运行 Laravel 有什么意义?

[英]Whats the point of running Laravel with the command 'php artisan serve'?

I dont seem to understand why we need to run a Laravel app with php artisan serve vs just running it with Apache or nginx .我似乎不明白为什么我们需要运行 Laravel 应用程序和php artisan serve而不是只用Apachenginx运行它。 I know that under development, we use artisan to fire up the site and after deployment to a server, you use the webserver to load up the site.我知道在开发过程中,我们使用 artisan 启动站点,在部署到服务器后,您使用网络服务器加载站点。

Whats the use of running the app in artisan in the first place?首先在 artisan 中运行应用程序有什么用?

The serve command is just a shortcut for the PHP Built-in Webserver , something PHP has out of the box, so the point of using it is to start testing your application as fast as you could, you just need to install PHP, Composer and your application is up (if you don't need anything else, of course). serve命令只是PHP内置Web服务器的一个快捷方式,PHP开箱即用,所以使用它的目的是尽可能快地开始测试你的应用程序,你只需要安装PHP,Composer和你的申请已经开始(如果你当然不需要别的东西)。 But if you already have Nginx installed, there is no point at all, just use it. 但是如果你已经安装了Nginx,那就没有意义了,只需使用它即可。

It's not wise to use the Builtin Webserver in production. 在生产中使用Builtin Webserver是不明智的。

One advantage of using php artisan serve over a typical webserver during development is you can use Psysh as a debugger (Laravel Tinker) to set a breakpoint. 在开发期间使用php artisan serve于典型Web服务器的一个优点是您可以使用Psysh作为调试器(Laravel Tinker)来设置断点。

For example, at the line of code I want to break at I type: 例如,在我输入的代码行中我输入:

eval(\Psy\sh());

Then I hit the page that will run that section of code and when it gets to that line it will break into a Psy Shell repl (in the commandline window where I started php artisan serve ). 然后我点击将运行该部分代码的页面,当它到达该行时,它将进入Psy Shell repl(在命令行窗口中我开始php artisan serve )。 Then I can inspect variables, etc. at that point of execution. 然后我可以在执行点检查变量等。 It's very useful for debugging. 它对调试非常有用。 As far as I know, you can't do this running Apache/Nginx. 据我所知,你无法运行Apache / Nginx。 It has to be with artisan serve (or running automated tests). 它必须与工匠服务(或运行自动化测试)。

More info here: 更多信息:

https://tighten.co/blog/supercharge-your-laravel-tinker-workflow https://tighten.co/blog/supercharge-your-laravel-tinker-workflow

http://psysh.org/ http://psysh.org/

Purpose : The purpose of using Php artisan serve (PHP builtin server) is just for testing and easy starting your project it should not be used in real website deployment. 目的 :使用Php artisan服务 (PHP内置服务器)的目的只是为了测试和轻松启动您的项目它不应该用于真正的网站部署。

Asset Not working : Always put your index file in public it's the beauty and security of Laravel framework and your assets will always working. 资产不起作用 :始终将您的索引文件公开,这是Laravel框架的美丽和安全性,您的资产将始终有效。 if you are bore to use your custom URL like C:/wamp/www/pym/server.php then use Virtual host locally but don't but don't put your index outside the Public folder. 如果您厌烦使用自定义URL,如C:/wamp/www/pym/server.php,则在本地使用虚拟主机,但不要将索引放在Public文件夹之外。 if you really want to use index at your Root directory then you should customize your all asset() and url() helper functions and should put your exact url Example asset('/login') should be changed to asset('localhost/yourprojectroot/login'). 如果你真的想在你的Root目录中使用索引,那么你应该自定义你的所有asset()url()帮助函数,并且应该把你的确切url示例资产('/ login')更改为asset('localhost / yourprojectroot /登录')。

Well, was looking for the same answer but couldn't find any that is satisfying so , if your also unsatisfied just like me try running the link returned when you run 好吧,正在寻找相同的答案但找不到任何令人满意的答案,如果你也不满意就像我一样尝试运行你运行时返回的链接

php artisan serve

it returns 它返回

Laravel development server started: <http://127.0.0.1:8000>

copy that / http://127.0.0.1:8000 and run it into the browser , guess what it returns );the page that u first got when you installed laravel for the first time or i guess it will return the page in the routes folder which was set as /home directory or file(default home page). 复制/ http://127.0.0.1:8000并将其运行到浏览器中,猜猜它返回的内容);您第一次安装laravel时首次获得的页面,或者我猜它将返回路径中的页面设置为/ home目录或文件的文件夹(默认主页)。

In brief: 简单来说:

php artisan serve

starts the serve,forexample its like when your going to drive a car and you start the engine before driving whereby you can start the engine and drive at the same time ,its not neccessary to do so but depends.So to me that's php artisan serve CLI. 开始发球,例如它就像你开车时你在开车前启动发动机那样你可以同时启动发动机并开车,这不是必要的但是依赖。所以对我说这是php工匠服务CLI。

php artisan serve --host your_server_ip --port 8000

复制 http://your_server_ip:8000 并将其运行到浏览器中

Aside from the best answer here.除了这里的最佳答案。

You can see the logs directly where you execute the php artisan serve , so useful in debugging.您可以在执行php artisan serve的地方直接看到日志,这对调试非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM