将我的本地开发服务器作为 http://local.dev/test-laravel/ 运行的 artisan 命令是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23167097/
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
What is the artisan command for running my local dev server as http://local.dev/test-laravel/?
提问by maxxon15
What is the artisan command for running my local dev server from an address like http://local.dev/test-laravel/?
从http://local.dev/test-laravel/ 之类的地址运行我的本地开发服务器的 artisan 命令是什么?
test-laravelis the folder in which I installed laravel.
test-laravel是我安装 laravel 的文件夹。
When I run a command like php artisan serve --host=local.dev/test-laravel/
it says server started at http://local.dev/test-laravel:8000(which doesn't work)
当我运行一个命令时,php artisan serve --host=local.dev/test-laravel/
它说服务器在http://local.dev/test-laravel:8000启动(这不起作用)
Ideally the url should be http://local.dev:8000/test-laravel
理想情况下,网址应为http://local.dev:8000/test-laravel
How do I achieve this?
我如何实现这一目标?
采纳答案by maxxon15
Since I'm running a XAMPP installation in a Ubuntu VM, I figured I should't have to use artisan to create another localhost address for me.
由于我在 Ubuntu VM 中运行 XAMPP 安装,我认为我不应该使用 artisan 为我创建另一个本地主机地址。
I just modified the Application Url in the app.php file and pointed it to the location where I installed laravel.
我只是修改了 app.php 文件中的 Application Url 并将其指向我安装 laravel 的位置。
'url' => 'http://local.dev/test-laravel/'
Now I can access the public folder from URL: http://local.dev/test-laravel/public
现在我可以从 URL 访问公共文件夹:http: //local.dev/test-laravel/public
:-)
:-)
回答by SaschaDens
One of the ways you can achieve this is by editing your Host file so the name “local.dev” can get resolved to an IP address.
实现此目的的方法之一是编辑主机文件,以便将名称“local.dev”解析为 IP 地址。
This is the simplest solution and depends on the Operating System you're using.
On a Windows system you can modify your host file at %Systemroot%\System32\Drivers\Etc\hosts
这是最简单的解决方案,取决于您使用的操作系统。在 Windows 系统上,您可以在以下位置修改主机文件%Systemroot%\System32\Drivers\Etc\hosts
On an Linux system this host file is located in the /etc/hosts
在 Linux 系统上,此主机文件位于 /etc/hosts
In these files you can add the following DNS translation.
在这些文件中,您可以添加以下 DNS 转换。
127.0.0.1 local.dev
Now when you try to put your server online you can use the following command php artisan serve –host=local.dev
and can access your webfolder on http://local.dev:8000/. This won't interfere with any other server that's running on http://local.dev/as long as the ports don't interfere.
现在,当您尝试将服务器置于联机状态时,您可以使用以下命令php artisan serve –host=local.dev
并访问http://local.dev:8000/上的 web 文件夹。只要端口不干扰,这不会干扰在http://local.dev/上运行的任何其他服务器。
If the port 8000 is already used you can use the following command to change port
如果8000端口已经被使用,可以使用以下命令更改端口
php artisan serve –host=local.dev --port=8080
Update
更新
Once you got the local.dev registered you can make use of it. php artisan serve won't do the DNS translation for you.
一旦你注册了 local.dev,你就可以使用它了。php artisan serve 不会为您进行 DNS 转换。
PHP 5.4.0 comes with a built-in web server where php artisan serve makes use of.
PHP 5.4.0 带有一个内置的 web 服务器,php artisan serve 使用了它。
http://www.php.net/manual/en/features.commandline.webserver.php
http://www.php.net/manual/en/features.commandline.webserver.php
"URI requests are served from the current working directory where PHP was started, unless the -t option is used to specify an explicit document root."
“URI 请求是从 PHP 启动的当前工作目录提供的,除非 -t 选项用于指定显式文档根目录。”
You can also configure a webserver to handle off this requests. At Laravel.iois an How-to guide.
您还可以配置网络服务器来处理此请求。在Laravel.io是一个操作指南。