laravel 为什么我应该继续运行 artisan serve 命令来保持服务器正常工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35667838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:18:53  来源:igfitidea点击:

why should I keep running artisan serve command to keep the server working?

phplaravelubuntuframeworksartisan

提问by medo ampir

I'm learning laravel, and at the beginning I had run the command

我正在学习laravel,一开始我运行了命令

php artisan serve

and keep my terminal window open so I can keep the server running, but later I wanted to just work with my app just like working on a normal php application so I created a virtual host directed to my laravel application "public" folder.

并保持我的终端窗口打开,这样我就可以保持服务器运行,但后来我想像处理普通的 php 应用程序一样使用我的应用程序,所以我创建了一个指向我的 Laravel 应用程序“公共”文件夹的虚拟主机。

here is the problem:

这是问题所在:

I still have to run the "php artisan serve" and open my virtual server url

我仍然需要运行“php artisan serve”并打开我的虚拟服务器网址

http://brk.localhost:8000

and then close the terminal, all that before I can normally open this link without defining the port number 8000. and If I left my computer and get back to continue work, I found that I can't access it unless I do the whole process again. and If I made a modification to any of the application views I get the same problem.

然后关闭终端,所有这些之前我可以在不定义端口号8000的情况下正常打开此链接。 如果我离开计算机并返回继续工作,我发现除非我完成整个过程,否则我无法访问它再次。如果我对任何应用程序视图进行了修改,我都会遇到同样的问题。

what am I missing?

我错过了什么?

回答by Basel J. Hamadeh

Just add the and symbol '&' to the end of the command. This will keep it running in the background.

只需在命令末尾添加和符号“&”即可。这将使其在后台运行。

回答by Joseph

There are 3 main ways that you can access your Laravel app while you are developing it.

在开发 Laravel 应用程序时,有 3 种主要方式可以访问它。

1) Using artisan serve

1) 使用 artisan serve

This method is probably the easiest method but it does mean that you have to remember to do this every time you start working on your project, which you have said that you do not want to do.

这种方法可能是最简单的方法,但它确实意味着您必须记住每次开始处理您的项目时都这样做,而您已经说过不想这样做。

2) Using Laravel Homestead

2) 使用 Laravel Homestead

This method requires a little more configuration but the documentationis very good. You won't have to remember to keep the terminal window open when you use it, but you'll still have to remember to keep the virtual machine running.

这种方法需要更多的配置,但文档非常好。您不必记住在使用时保持终端窗口打开,但您仍然必须记住保持虚拟机运行。

3) Set up LAMP / MAMP / WAMP or even LEMP

3) 设置 LAMP / MAMP / WAMP 甚至 LEMP

Setting up a local Apache or Nginx daemon on your own machine will require the most amount of configuration but it will mean that your web server automatically starts with your OS so whatever you put in your web directory will always be accessible through the web browser. You will not need to run and terminal commands or run a virtual machine.

在您自己的机器上设置本地 Apache 或 Nginx 守护程序将需要最多的配置,但这意味着您的 Web 服务器会自动启动您的操作系统,因此您在 Web 目录中放置的任何内容都可以通过 Web 浏览器访问。您不需要运行终端命令或运行虚拟机。

Please note, however, that by using a local Apache/Nginx daemon you will be sacrificing a lot of flexibly and you will not have the luxury of deleting it all and starting again in a few minutes if you mess up the config.

但是请注意,通过使用本地 Apache/Nginx 守护程序,您将牺牲很多灵活性,并且如果您弄乱了配置,您将无法将其全部删除并在几分钟内重新开始。

Still, a lot of people still prefer to run their own Apache/Nginx daemon locally for development. I am one of them.

尽管如此,很多人仍然喜欢在本地运行他们自己的 Apache/Nginx 守护进程进行开发。我是其中之一。

回答by Manu

I encountered a similar situation where, if I were to save any modification to project files, I had to run "php artisan serve" and quit it before apache2 can serve the site.

我遇到过类似的情况,如果我要保存对项目文件的任何修改,我必须运行“php artisan serve”并在 apache2 可以为站点提供服务之前退出它。

I fixed it by modifying the file system permissions for my project.

我通过修改我的项目的文件系统权限来修复它。

I found this, which fixed the permission issue.

我发现了这个,它解决了权限问题。

This solved the situation where I had to run php artisan serve, over and over again.

这解决了我不得不一遍又一遍地运行 php artisan serve 的情况。

Primary cause of this is running package managers as sudo. Every file is created with bad permissions.

造成这种情况的主要原因是以 sudo 身份运行包管理器。每个文件都是用错误的权限创建的。