0

I'm working to migrate a PHP site from one server at Godaddy to another. The site has a lot of "legacy" code in it, with links to images, css, etc. in the format:

<img src="/img/img.png" />

and required/included content like...

require_once($_SERVER['DOCUMENT_ROOT']."/_inc/required-stuff.php");

The problem I have is the current site is "www.mycurrentsite.com" and when I set up a new account in the cPanel stuff it created something like..

111.111.111.111/~mycurrentsite/

So all the items starting with "/" and the $_SERVER['DOCUMENT_ROOT'] do not point to the right spot.

I've read about setting up a host, but that will only get me to the ip, not the "~substuff" area. I know there has to be something faster than going in and rewriting everything or setting a variable = "~mycurrentsite/" that I put in at the front of everything and set to "" when I go live.

I'm at a loss and willing to take the down votes I'll probably get for "not researching" after spending the last couple hours trying to find a solution.

When I look at where $SERVER['DOCUMENT_ROOT'] currently points on the setup, it's "/usr/local/apache/htdocs". I was able to set the index.html page in this location to at least push any traffic to the IP to the "~mydomain" subfolder, but that doesn't help with the mapping of files.

I'm guessing it may be something in Apache to change but I'm afraid to break something in there since cPanel set it up and most of it says "DO NOT EDIT" in areas that I think I would possible touch.

EDIT: I made changes to the area in my httpd.conf file and set the values I had in the area where ServerName matched the ~mydomain info.

This seems to work, but I'm not confident this is the best way to do it since it has "DO NOT EDIT. AUTOMATICALLY GENERATED..." all over by it. I plan to uncomment my changes and put back what was there before I roll the DNS, but for now, it seems like A solution, if not the best one.

EDIT:

I ran into this problem again and while editing the VirtualHost options manually in the apache http.conf file I realized I could set up different ports for each site. I now set up a.domain.com on port :80 and b.domain.com on port :8080, etc.

Worked like a charm. the one issue I ran into next was with PHP sessions being read by the different sites, but this was set by updating in the code like so...

ini_set('session.name', 'DOMAIN1'); // session name for a.domain.com

HTH save someone else some time.

Don
  • 1,570
  • 4
  • 22
  • 38
  • Is the site running in the root directory, e.g. do you access it with `http://www.example.com`, or is it in a subdirectory such as `http://www.example.com/mysite`? The PHP environment variable `$_SERVER['DOCUMENT_ROOT']` comes from the VirtualHost DocumentRoot as defined in the Apache config. There's no reason it shouldn't be portable given a correct setup. – dartonw Mar 22 '15 at 21:15
  • Yes, images, etc. are all in /home/mydomain/public_html/ folder w/ resolves to the web root. – Don Mar 22 '15 at 21:30
  • Can you use mod_rewrite? If so you could rewrite all requests which are not `^/~mydomain/*` and prepend '/~mydomain/' to paths. It will work only with request send to apache not php includes. With php includes you could try using relative paths to current php file like `require_once(__DIR__ . "/../_inc/required-stuff.php");` – piotrekkr Mar 22 '15 at 21:55
  • Hadn't thought about mod_rewrite and looking for NOT matching... the __DIR__ option would require rewriting all the pages that make calls, and they may be at various levels, which works with the DOCUMENT_ROOT option. I edited my original post to explain how I was able to edit the httpd.conf to work. Long term, this may not be the best solution b/c I'll have to edit again before I roll the DNS – Don Mar 22 '15 at 22:41
  • 1
    Do you have some option to add virtual host inside cpanel and not by editing files by hand? – piotrekkr Mar 23 '15 at 19:20
  • I added this one in cPanel, but until the DNS rolls, it displays them in the url in the http://1.1.1.1/~domain format. – Don Mar 23 '15 at 20:12
  • Have you looked here http://tecadmin.net/add-custom-settings-in-whm-cpanel-apache-virtualhost/ or here http://stackoverflow.com/questions/6900306/how-do-i-add-virtual-hosts-the-right-way-while-running-whm ? Maybe it will help. – piotrekkr Mar 23 '15 at 21:20
  • I'll edit my queston, but I think the solution is to add the VirtualHost entries on different ports, then listen on those ports. I can use the IP for one site that way on port 80, and use 8080, etc. for the others. – Don Jun 03 '15 at 18:34

0 Answers0