php 在本地主机中运行 Laravel 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48719658/
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-08-26 02:43:10  来源:igfitidea点击:

Run laravel project in localhost

phplaravel-5.5

提问by Magecode

I have installed laravel by composer create-project laravel/laravel –-prefer-dist

我已经通过 composer create-project laravel/laravel --prefer-dist 安装了 laravel

after this run php artisan serve command to laravel project directory and get this result.

在此之后运行 php artisan serve 命令到 Laravel 项目目录并获得此结果。

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

Laravel 开发服务器启动:http: //127.0.0.1:8000

But when i go to http://127.0.0.1:8000in browser laravel project not running and give error

但是当我在浏览器中访问http://127.0.0.1:8000 时,laravel 项目没有运行并给出错误

This site can't be reached 127.0.0.1 refused to connect.

无法访问此站点 127.0.0.1 拒绝连接。

but http://localhost/laravel/public/it is working. Can anyone tell me that what is proper way to run this laravel project.

但是http://localhost/laravel/public/它正在工作。谁能告诉我运行这个 Laravel 项目的正确方法是什么。

回答by Naincy

Try to run in different port

尝试在不同的端口运行

php artisan serve --port=9000

php artisan serve --port=9000

and then try http://127.0.0.1:9000will work.

然后尝试 http://127.0.0.1:9000会起作用。

As might be on port 8000 something already running on your system will not make it work.

可能在端口 8000 上已经在您的系统上运行的某些东西将无法正常工作。

And you can also run your laravelproject without artisan serve command

你也可以在laravel没有 artisan serve 命令的情况下运行你的项目

If anyone wants to make the application public, the more easy and fastest way is:

如果有人想公开应用程序,更简单快捷的方法是:

  1. Rename the "server.php" file in root directory, in "index.php"
  2. Move your .htaccess from public folder to root directory
  3. Make your directory accessible to Apache2 (set all file permissions to 777).
  1. 重命名根目录中的“server.php”文件,在“index.php”中
  2. 将您的 .htaccess 从公用文件夹移动到根目录
  3. 使 Apache2 可以访问您的目录(将所有文件权限设置为 777)。

回答by Amit-Inex Patel

At starting level, you can use url like this http://127.0.0.1:8000with 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

在初始级别,您可以使用带有端口号的http://127.0.0.1:8000这样的 url 。但在更高级别,您必须使用简单的 url,如 http://localhost/laravel/public/。还有一件事 - 你应该从 url 中删除“public”关键字,这样你就可以直接访问你的根项目。查看此链接 - Laravel 5 - 从 URL 中删除公共

回答by Игорь Колганов

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://ospanel.io/安装了 openserver并将我的站点放在文件夹域(Windows 10)上,然后我只需启动 Open Server 并单击“我的站点”并选择我的站点 - 它在我的浏览器中打开并设置默认情况下,在 Open Server 程序上并单击我的浏览器上冷却的“公共”文件夹,然后您就可以 -> 您的站点正在运行。我现在这并没有解决 cmd 的问题,并开始认为 cmd 和 server 像http://127.0.0.1:8000,但是您可以通过 http://'your site'/public/' 访问您的本地站点你的页面'祝你好运!

回答by Philcz

Changing the port will help. php artisan serve --port=9000 worked for me

更改端口会有所帮助。php artisan serve --port=9000 为我工作

回答by neeraj sharma

Try this

尝试这个

php -S 127.0.0.2:8000 -t public/

php -S 127.0.0.2:8000 -t 公共/

It will start your local development to http://127.0.0.2:8000which will work great.

它将开始您的本地开发到http://127.0.0.2:8000,这会很好用。

OR

或者

You can try instead

你可以试试

php -S 127.0.0.1:8000 -t public/ It will work in any browser as compare to command php artisan serve which open url http://127.0.0.1:8000.

php -S 127.0.0.1:8000 -t public/ 与打开 url http://127.0.0.1:8000 的命令 php artisan serve 相比,它可以在任何浏览器中工作。