Web Hosting Talk







View Full Version : Need help with the local Apache(?) setup


BurakUeda
02-12-2010, 05:09 AM
There is a public website, accesible to the world:
http://www.somesite.com, located in /home/somesite/html/

I created the same location in my local server, and I need my browser to show me local contents when I type http://www.somesite.com instead of the live site.

The company I work for is using Mercurial version control system, so I need to test my work in local, then update/pull/push/merge/commit to the live server. But I don't want to change the links, absolute paths etc. everytime I upload the files. And then change it back to work in local environment.

Both local and public machines are running on linux with apache 2.2.

I am no linux/apache expert so any "for dummies" instructions appreciated.

Thanks/

TheSimpleHost-Nathan
02-12-2010, 05:21 AM
If you are saying that you have a mirror of the website on your machine, then it will be really simple for you.

Just open your host files (WIN: c:\windows\system32\drivers\etc\hosts LINUX: /etc/hosts) and add 127.0.0.1 somesime.com to the end of the file.

When you're done, remove that and you'll go back to the server :)

Don't forget to do this on the the local server if you are using two machines (one to develop, one to run httpd)

mattle
02-12-2010, 05:16 PM
If you are saying that you have a mirror of the website on your machine, then it will be really simple for you.

Just open your host files (WIN: c:\windows\system32\drivers\etc\hosts LINUX: /etc/hosts) and add 127.0.0.1 somesime.com to the end of the file.

When you're done, remove that and you'll go back to the server :)

Don't forget to do this on the the local server if you are using two machines (one to develop, one to run httpd)

You'll also have to refresh your DNS cache in Windows or you won't notice the change. Easiest way I've found to do this is (XP--don't know about Vista or 7)

1. Go to Control Panel > Network Connections
2. Right-click on your active connection
3. Choose "Repair"

BurakUeda
02-12-2010, 08:28 PM
Thanks guys.
Well, I did what Nathan said but browser was still getting the content from the remote (live) server.
So I changed the browser network settings.

Entered 127.0.0.1 as the proxy, but browser still saw the remote server.
Added port number 80 to the proxy, this time browser accessed the local content for the index page, but any other sub-pages giving 404-Not found error.

Even if I achieve this in Nathan's way, I can setup only one website, in the web root correct? As a matter of fact, I need to set this up for couple of sites.

Few years ago, when I was working in a project for another company, some network guy did something with the proxy. He setup a proxy server, and setup the browser. So when I use that browser, http://www.somesite.com showed the local content, any other browser showed the live/remote content.
Any ideas how that is done?

Thanks...

mattle
02-12-2010, 08:55 PM
Thanks guys.
Well, I did what Nathan said but browser was still getting the content from the remote (live) server.

Did you do it in conjunction with my suggestion?


So I changed the browser network settings.

Entered 127.0.0.1 as the proxy, but browser still saw the remote server.
Added port number 80 to the proxy, this time browser accessed the local content for the index page, but any other sub-pages giving 404-Not found error.

Even if I achieve this in Nathan's way, I can setup only one website, in the web root correct? As a matter of fact, I need to set this up for couple of sites.

Incorrect. If you're running apache, for example, you could have several VirtualHost entries that are all listening on 127.0.0.1:80.

Few years ago, when I was working in a project for another company, some network guy did something with the proxy. He setup a proxy server, and setup the browser. So when I use that browser, http://www.somesite.com showed the local content, any other browser showed the live/remote content.
Any ideas how that is done?

Thanks...

Are you actually running proxy software? I'm sure if you were, you could route the requests any way you wanted to. I still think, however, that Nathan's solution is way easier. I'm sure you could even write a batch file that switched between two hosts files and restarted the network interface.

Alternatively, you could set up subdomains that are directed to 127.0.0.1 on your DNS server. (devel.somesite.com, for example). Useless to anyone else, because it will only redirect them to their own machine, but very useful to you--that's exactly the behavior you want! As long as you're not referencing other live subdomains (www.somesite.com, secure.somesite.com) in your code, you'll be fine with that method as well.

BurakUeda
02-12-2010, 10:50 PM
Thanks mattle.
I just installed the Squid, and digging the configurations etc.
Already set my Firefox proxy to Squid, and currently using it through the proxy.

I guess I need to find a way to set Squid to handle the requests. e.g.:
When user enters http://www.somesite1.com, contents will be from local: /home/somesite1/html
and for http://www.somesite2.com, contents will be from local: /home/somesite2/html