[英]How to run PHP application out of localhost?
I got this task form school, to make a PHP web application. 我从学校开始这个任务,制作一个PHP Web应用程序。 But I don't really understand what this requirement might mean 但我真的不明白这个要求可能意味着什么
It should be possible to run this application outside the domain root eg sample URL: http://localhost/task/ . 应该可以在域根之外运行此应用程序,例如示例URL: http:// localhost / task / 。
I searched a little bit on the internet but was not able to find anything that I could understand ? 我在互联网上搜索了一下但是找不到任何我能理解的东西?
I have wamp, and the folder where is my sites is wamp/www/task
我有wamp,我的网站所在的文件夹是wamp/www/task
When they say "outside of domain root" it means that you should not be forced to go to 当他们说“在域根之外”时,这意味着你不应该被迫去
http://localhost/yourfile.php
but you could put it in a subdir, like 但你可以把它放在一个子目录中,比如
http://localhost/task/yourfile.php
What they want you to do is harder to guess, but it could mean that you need to be able to run it in any subdir, so take care of you imports to be able to handle that (eg: not hardcode the dir you're working in). 他们想要你做的更难猜测,但这可能意味着你需要能够在任何子目录中运行它,所以要注意你的导入能够处理它(例如:不硬编码你的目录)在工作)。
Domain root seems to be at localhost
, this just means it should be easy to rename your web application folder and make it still work at anywhere. 域根似乎是在localhost
,这只是意味着它应该很容易重命名您的Web应用程序文件夹,并使其仍然可以在任何地方工作。
# http://localhost/task
$ cd wamp/www/
# http://localhost/task2 - should be accessible without you needing to change anything
$ mv task task2
From technical point of view, you should use relative path for all your links and images as well as external resources such as javascript / css files 从技术角度来看,您应该为所有链接和图像以及外部资源(如javascript / css文件)使用相对路径
you can set vitual host for your web server & access your PHP Application likw www.oorja.local 您可以为您的Web服务器设置虚拟主机并访问您的PHP应用程序,如www.oorja.local
in the wamp server, just add below code at end of your httpd.conf file, which allow you access your PHP application without localhost, Document root and Directory have your physical pathe of your application directory. 在wamp服务器中,只需在httpd.conf文件的末尾添加以下代码,这样就可以在不使用localhost的情况下访问PHP应用程序,文档根目录和目录可以对应用程序目录进行实际操作。
ServerName oorja.local DocumentRoot E:/LAMPSYSTEM/wamp/www/oorja/public ServerName oorja.local DocumentRoot E:/ LAMPSYSTEM / wamp / www / oorja / public
<Directory E:/LAMPSYSTEM/wamp/www/oorja/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.