如何在本地主机上运行文件?
如何在本地主机上实际运行文件? 我知道它正在工作,但是如何在其上运行文件,以及如何验证该文件确实在本地主机上运行?
这里是服务器新手,还有其他问题(我有运行 Apache 2.2 的 xampp): 从您的回复看来,我必须在浏览器中输入路径才能打开本地主机上的文件。 那么,如果我想将文件放在子目录中,我必须输入包括目录的完整路径吗?
有没有办法让浏览器在我处理 html 时指向本地主机,而不必一直输入路径?
我正在使用 Dreamweaver CS3,并且想要使用 include 命令(SSI 或 PHP),但不必继续将我的文件放在 HostGator 上以查看它们是否正常工作。
最好的方法是什么(请具体说明,我什么都不知道)。 如果有详细的教程,非常感谢链接。
谢谢
How do I actually run a file on localhost?
I know it is working, but how do I run a file on it, and how do I verify that the file is in fact running on localhost?
Server newbie here, additional questions (I have xampp running Apache 2.2):
From your responses it sounds like I have to type in the path in the browser in order to open the file on the localhost. So, if I want to have the file in a subdirectory, I would have to type the full path including the directory?
Is there a way to have the browser point to the localhost while I am working on my html, instead of having to type in the path all the time?
I am working in Dreamweaver CS3, and want to use include commands (either SSI or PHP), but not have to keep putting my files up on HostGator in order to see if they are working.
What is the best way to do this (please be specific, I know nothing). If there is a detailed tutorial anywhere, really appreciate a link.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
好的,感谢您提供更具体的信息,人们现在可以删除他们的反对票...
您所提议的是一件非常常见的事情! 您希望在本地运行您的 Web 应用程序,而不将其上传到您的主机。 这完全没问题,这就是 Apache 的用途。 Apache 是一个 Web 服务器,这意味着它的主要用途是为 HTML、PHP、ASP 等文件提供服务。 有些人喜欢 PHP;有些人喜欢 PHP; 它首先发送到解释器,然后将渲染的文件发送到浏览器。 总而言之:它只是向您的浏览器(客户端)提供页面。
您的 Web 服务器的根目录是 wwwroot (IIS) 或 htdocs (apache、xampp) 或其他类似 public_html、www 或 html 等。这取决于您的操作系统和 Web 服务器。
现在,如果您在浏览器中输入
http://localhost
,您的浏览器将被定向到此 webroot,并且服务器将为任何index.html
、index.html 提供服务。 php
等,它可以在那里找到(以可定制的顺序)。如果您有一个名为“mytutorial”的项目,您可以输入
http://localhost/mytutorial
,服务器将向您显示教程的索引文件等。如果您查看这个教程文件夹,那么它只是你的 webroot 的一个子文件夹,它本身位于你的硬盘上的某个地方,但这对你的本地主机来说并不重要。因此,相对路径是,
而绝对路径可能是
或者
如果您使用 Dreamweaver,您可以通过在项目设置中将本地服务器设置为测试服务器来简化测试过程。 尝试一下! 这很容易。 完成后,您只需按任何文件的浏览器图标,它将在本地主机上打开。
Ok, thanks for the more specific info, ppl may remove their downvotes now...
What you are proposing is a very common thing to do! You want to run your web application locally without uploading it to your host yet. That's totally fine and that's what your Apache is there for. Your Apache is a web server meaning its main purpose is to serve HTML, PHP, ASP, etc. files. Some like PHP; it first sends to the interpreter and then sends the rendered file to the browser. All in all: it's just serving pages to your browser (the client).
Your web server has a root directory which is wwwroot (IIS) or htdocs (apache, xampp) or something else like public_html, www or html, etc. It depends on your OS and web server.
Now if you type
http://localhost
into your browser, your browser will be directed to this webroot and the server will serve anyindex.html
,index.php
, etc. it can find there (in a customizable order).If you have a project called "mytutorial" you can enter
http://localhost/mytutorial
and the server will show you the index-file of your tutorial, etc. If you look at the absolute path of this tutorial folder then it's just a subfolder of your webroot, which is itself located somewhere on your harddrive, but that doesn't matter for your localhost.So the relative path is
while the absolute path may be
or
If you're working with Dreamweaver you can simplify the testing process by setting up your local server as a testing server in your project settings. Try it! It's easy. Once it's done, you can just press the browser icon with any of your files and it will open on localhost.
您可以通过运行以下命令来完成此操作。
You can do it by running with following command.
我不太确定你的意思,所以我简单地开始:
如果你试图“运行”的文件是静态内容,比如 HTML 甚至 Javascript,你不需要在“localhost”上运行它...您应该能够从计算机上的任何位置在浏览器中打开它。
如果它是一段服务器端代码(ASP[.NET]、php,无论其他),您需要运行 Web 服务器,或者如果您使用的是 Visual Studio,请启动应用程序的开发服务器(F5进行调试,或按 CTRL+F5 启动但不进行调试。
如果您使用的是 Web 服务器,则需要配置一个网站,并将主目录设置为文件所在的目录(或者只需将文件位于任何配置的主目录中)。
如果您使用的是 Visual Studio,则该文件只需位于您的项目中。
I'm not really sure what you mean, so I'll start simply:
If the file you're trying to "run" is static content, like HTML or even Javascript, you don't need to run it on "localhost"... you should just be able to open it from wherever it is on your machine in your browser.
If it is a piece of server-side code (ASP[.NET], php, whatever else, uou need to be running either a web server, or if you're using Visual Studio, start the development server for your application (F5 to debug, or CTRL+F5 to start without debugging).
If you're using a web server, you'll need to have a web site configured with the home directory set to the directory the file is in (or, just put the file in whatever home directory is configured).
If you're using Visual Studio, the file just needs to be in your project.
本地主机是您现在正在使用的计算机。 您可以通过在命令提示符处键入命令并按 Enter 来运行命令。 如果您询问如何从编程环境中运行事物,那么答案取决于您正在使用的环境。 大多数语言都有名为
system
或exec
的命令来运行外部程序。 您需要更具体地说明您实际想要做什么,以及在尝试实现目标时遇到了哪些障碍。Localhost is the computer you're using right now. You run things by typing commands at the command prompt and pressing Enter. If you're asking how to run things from your programming environment, then the answer depends on which environment you're using. Most languages have commands with names like
system
orexec
for running external programs. You need to be more specific about what you're actually looking to do, and what obstacles you've encountered while trying to achieve it.看看你的其他问题,我假设你正在尝试在你的网络服务器上运行 php 或 asp 文件或其他东西,这是你在网页设计中的第一次尝试。
一旦你正确安装了 php(当你获得 XAMPP 时你可能会这样做),只需将你想要的任何文件放在本地主机下(也许是 /www/var/html?),它就应该运行。 当然,您可以在浏览器中的 localhost/file.php 中进行检查。
Looking at your other question I assume you are trying to run a php or asp file or something on your webserver and this is your first attempt in webdesign.
Once you have installed php correctly (which you probably did when you got XAMPP) just place whatever file you want under your localhost (/www/var/html perhaps?) and it should run. You can check this of course at localhost/file.php in your browser.
这样想吧。
您在
localhost/
之后键入的任何内容都是服务器根目录(www 或 htdocs)内的路径。您不需要指定要运行的文件的完整路径,而只需指定根文件夹后面的路径,因为放置
localhost/
会将您带入根文件夹本身。Think of it this way.
Anything that you type after
localhost/
is the path inside the root directory of your server(www or htdocs).You don't need to specify the complete path of the file you want to run but just the path after the root folder because putting
localhost/
takes you inside the root folder itself.我目前正在 VScode 中工作。 我想运行我的 html 页面只是为了查看所有主要元素。
1)首先,在vs中,右键单击所需的html文件并选择“复制路径”。 不选择亲戚。
2)最后,将html路径粘贴到地址栏中(我使用chrome)并按回车键。 您的 html 页面应该显示。 希望这可以帮助别人。
i am working in VScode currently. i was wanting to run my html page just to see all my main elements.
1) first, in vs, right click desired html file and choose "copy path". do not choose relative.
2) finally, paste html path in address bar (i used chrome) and hit enter. your html page should display. hope this helps someone out.