简体   繁体   English

使用PHP为Apache设置实际的DOCUMENT_ROOT

[英]Set the actual DOCUMENT_ROOT for Apache with PHP

I'm trying to have several versions of the same PHP application in different directories. 我正在尝试在不同目录中使用同一PHP应用程序的多个版本。 The application is written so that it has to be in Apache's Document_root. 编写应用程序时,必须将其放置在Apache的Document_root中。

I have tried $_SERVER['DOCUMENT_ROOT'] = '/htdocs/version2'; 我已经尝试过$_SERVER['DOCUMENT_ROOT'] = '/htdocs/version2'; but that only works for things being included using $_SERVER['DOCUMENT_ROOT'].'filename.php' . 但这仅适用于使用$_SERVER['DOCUMENT_ROOT'].'filename.php'

All other files executed is in the original root /htdocs/version1. 执行的所有其他文件在原始根目录/ htdocs / version1中。

How can I make the document_root to actually change for a PHP session and not just setting the variable $_SERVER['DOCUMENT_ROOT'] ? 我如何才能使document_root实际上针对PHP会话进行更改,而不仅仅是设置变量$_SERVER['DOCUMENT_ROOT']

You don't need to do anything what you're just doing (what you wrote just now at least, like server stuff). 您不需要做任何事情(至少是您现在刚刚写的内容,例如服务器内容)。

Situation 1. 情况1。

If you want to use 2 folders as a separate websites (on a local machine), just copy those 2 folders in a htdocs folders and youre done. 如果要使用2个文件夹作为单独的网站(在本地计算机上),只需将这2个文件夹复制到htdocs文件夹中即可。 Use 采用

http://localhost/vesion1 //version 1 is actually your copied folder name.. and version2 also http://localhost/vesion1 //版本1实际上是您复制的文件夹名称..和version2也是

http://localhost/vesion2

entries to access them. 条目以访问它们。

ps:if this aint gonna work, you should edit your website configuration .php file and change main url / path to version1 /or version 2 ie! ps:如果这个方法行得通,则应编辑您的网站配置.php文件,并将主url /路径更改为version1 /或version 2,即! (That is your problem actually, not "server root".) (实际上,这是您的问题,而不是“服务器根”。)

If you have database driven url set, you should create new DB for your copy/pasted website (or force new main url/path manually). 如果您设置了数据库驱动的URL,则应为复制/粘贴的网站创建新的数据库(或手动强制使用新的主URL /路径)。

For ie.. you can have 10 "versions" with only one DB, or 10 versions with 10 DBs (databases). 例如,您可以仅使用一个DB来拥有10个“版本”,或者使用10个DB(数据库)来拥有10个版本。

Situation 2. 情况2。

If you want to run 2 versions/sites using one index.php (root index) - what are not 2 versions actually, but more like a "2 websites in one" - you should edit .htaccess file to jump over root index / or not. 如果要使用一个index.php(根索引)运行2个版本/站点-实际上不是2个版本,而是更像“ 2个网站合而为一”-您应编辑.htaccess文件以跳过根索引/或不。

I'm kinda confused what youre trying to achieve but I guess situation 1 is a go (if you're trying to do this on a local machine). 我有点困惑您想要实现的目标,但是我想情况1是可行的(如果您尝试在本地计算机上执行此操作)。

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

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