简体   繁体   English

如何在本地运行 php 项目

[英]How do you run a php project locally

So I'm working on a project with many files and folders.所以我正在处理一个包含许多文件和文件夹的项目。 I'm using Laravel and localhost to run it locally on my browser.我正在使用 Laravel 和 localhost 在我的浏览器上本地运行它。 It runs the project fine, the problem is when I try to run a single file by itself(by right clicking on vs code and clicking PHP Server: run file in browser) to test and see what I'm doing.它可以正常运行项目,问题是当我尝试自己运行单个文件时(通过右键单击 vs 代码并单击 PHP 服务器:在浏览器中运行文件)来测试并查看我在做什么。 Doing that returns an error (localhost unexpectedly closed the connection).这样做会返回错误(本地主机意外关闭了连接)。 What could be the problem and how should I fix it or what other way should I try to run one specific file as opposed to the whole project.可能是什么问题,我应该如何解决它,或者我应该以什么其他方式尝试运行一个特定的文件而不是整个项目。 If there's anything from the code you might need, please ask如果您可能需要代码中的任何内容,请询问

Laravel is a framework that needs to be booted before all its services are available. Laravel 是一个框架,需要在其所有服务可用之前启动。

These services, and the request cycle as a whole, are started via the index.php file in the public folder.这些服务以及整个请求周期是通过公共文件夹中的 index.php 文件启动的。 This is a single entry point for all http requests.这是所有 http 请求的单一入口点。 There is another entry point via the artisan command for CLI operations.通过 artisan 命令还有另一个用于 CLI 操作的入口点。

You cannot run individual files in the manner described because they are taken out of context of the framework.您不能以所描述的方式运行单个文件,因为它们已脱离框架的上下文。

If you are developing on MAC or Windows you can download MAMP: https://www.mamp.info/如果您在 MAC 或 Windows 上进行开发,您可以下载 MAMP: https://www.mamp.info/

This will make your make into a local server.这将使您的 make 成为本地服务器。 Then just redirect your directory to your server and run it.然后只需将您的目录重定向到您的服务器并运行它。

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

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