I'm doing a job for a guy with a site online. It's an alien site to me, and I'm slowly working through the strange code. I have MAMP locally and my http://localhost/ has many client folders coming off from that. Inside this code there is a lot of $_SERVER['document_root'] commands and references like which are just getting lost on my local PHP dev area.
How can I easily set the document_root reference to what it should be (just locally though, don't really want to mess with the site files, as I'll need to upload them again and don't want to break live site! And is there a way of indirect setting where PHP thinks the root of the site is so the image's src references "/images/..." will show up properly... My local PHP dev URL for this site is: http://localhost:8888/_CLIENTS/clientsite/www/ ...but in the code the '/' at the beginning of '/images/...' is referencing http://localhost:8888/ ??
Thank you.
It's a server-specific setting. If you're running Apache, all you'll need to do is edit your
httpd.conf
file (on a Unix-based system, it should be either in/etc/apache2/httpd.conf
or/etc/httpd/httpd.conf
, depending on which version of Apache you have). There should be a line in the file that looks like this:Technically, Eli's way works as well, but I don't think editing server variables is really a good idea, in general.
Maybe you would find the following site useful. There are simple-to-follow tutorials that show you just what settings to manipulate to set up this'n'that to you satisfaction. I found a lot explained there.
Tanguay's tutorial
For the current process, you can just do
$_SERVER["document_root"] = "whatever";
Be careful though.
@Eddie's answer helped me a lot, but I had to still do a little extra research to solve the same problem for myself using XAMPP on OSX. I thought I would add my full solution here for the benefit of posterity.
First I added the following entries to httpd-vhosts.conf (under the "etc/extra/" folder in XAMPP):
Note that I specifically used a wildcard instead of "localhost" for the VirtualHost urls and added the ServerName config where I specified each subdomain name. Note also that I used my machine's name ("my-machine") instead of "localhost" -- that way all requests from any machine (not just localhost) can be properly evaluated. I develop in OSX but test browsers in various VM's via Parallels. Using this approach I can access http://client1.my-machine from any machine or VM on my network. With "localhost" specified it would only work on my development machine.
NOTE: The first VirtualHost entry is used as the default (as explained here: http://httpd.apache.org/docs/2.2/vhosts/name-based.html) and is required so that requests do not default to one of the custom sites.
I also added the permissions settings to httpd.conf as shown in @Eddie's answer. This is not always required, but I ran into 2 separate cases where I needed to make this change:
AllowOverride
option makes the cause of the error obvious, but I had overlooked that before. Changing this to "All" fixed the error.Note that while editing httpd.conf, you may need to uncomment the following line (it was commented out for me by default), or the vhosts change made above will not take effect:
Finally, I also had to add the custom domain names to my hosts file as noted in the comments above. On OSX, you do this by editing "/private/etc/hosts" (on Windows this would be "Windows/System32/drivers/etc/hosts") and added the following lines:
NOTE: In the default OSX Finder UI, hidden folders (including /private) are not visible. You can change this permanently by hacking internal Finder options (Google for details), or more simply to make an occasional change, just use the "Go > Go to folder" menu option which will let you open hidden folders directly by name. Personally, I use a third party OSX shell called PathFinder that I would heartily recommend (it is worth the small license fee). It includes a menu option to hide/show hidden files, among many other useful features.
One thing that's a drag is that I also did have to add matching entries in my Windows VM hosts file pointing to my physical dev machine so that the urls would resolve via Apache/OSX:
I don't need an entry for the machine name alone (that resolves automatically) but adding the subdomain to it does not resolve correctly without those host entries. This does suck in that on occasion my Mac's IP changes (via DHCP), but it's a minor nuisance. I would assume that I could set it up to not need those IP's, but I could not figure that out and am ready to move on :) (If someone knows the answer please leave a comment)
Now I have multiple client sites running in one place and accessible from all of my dev/test environments. Hope this helps someone else.
What I would recommend is vhosts so you can serve up "alien site" locally without messing with your default web server.
In apaches global config file or included vhost.conf;
You can control permissons and set a overall global site by specifying the below first
in apache's global server config