I am trying to setup a dev wamp server on my local machine so I can do some dev work without giving my boss a heart attack if something goes wrong.
I have wamp running and working just fine, the problem is the project I am working on was developed using <?php include $_SERVER['DOCUMENT_ROOT'].'/
for all the paths.
The Document root of the server is D:/wamp/www which is correct for the dev server.
Is there a way that I can setup a project so that the relative document root for that particular project would be d:/wamp/www/project
I've tried to use vhosts and aliases to no avail. When I setup the vhost everything for the project worked fine but it was the only site on localhost.
You probably can do that with a script like this one:
$basePath = dirname(__FILE__); // assuming this script is in D:/wamp/www
$projectPath = preg_replace('#('.$basePath.'/[^/]+)/.*#i', '\\1', $_SERVER['PHP_SELF']);
$_SERVER['DOCUMENT_ROOT'] = $projectPath;
The preg_replace
line strips everything from the current script's path up to BASE + 1 segment . Then then the last line overwrites the current DOCUMENT_ROOT index from $_SERVER with the new path.
You can then set auto_prepend_file
in php.ini:
auto_prepend_file = D:/wamp/www/prepend_script.php
Or .htaccess (in D:/wamp/www):
php_value auto_prepend_file prepend_script.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.