Archive for June, 2007

Trick your computer into finding web sites on other servers

Quite often I’ve dealt with moving sites from one hosting situation to another. One issue that comes up is checking to make sure the site works on the new server, but you can’t check it because the domain is still pointing to the old server. Most clients are not okay with just waiting until the DNS switches over to the new server before finding out if their site is broken or not, so what to do? It turns out you can trick your computer into thinking the site really does live on the new server, so you can check it and verify everything is working correctly. Here’s how.

Whether you are on Windows, Linux or OS X, you can tell your computer to look for web sites at alternate IP addresses regardless of what DNS servers tell it. There is a hosts file that you can modify to do just that.

On Linux and OS X, this file is /etc/hosts, while on Windows it is the C:\WINDOWS\system32\drivers\etc\hosts file. The format is the same on both platforms, so you can use this trick no matter what OS you use. Here is the default one from OS X:

  ##
  # Host Database
  #
  # localhost is used to configure the loopback interface
  # when the system is booting.  Do not change this entry.
  ##
  127.0.0.1       localhost
  255.255.255.255 broadcasthost
  ::1             localhost

The setup is pretty simple. Enter the IP that you want your computer to point to, with the domain name you want it to use. So if you are in the process of moving www.clientwebsite.com from Dreamhost to Bluehost, then you’d find out the IP of the new server at Bluehost and enter at the end of the file like so:

  123.123.123.123 www.clientwebsite.com

Now clear out the DNS cache on your computer to make sure you’re not viewing the site from your DNS cache. On windows, open up the command line and type ipconfig /flushdns. In OS X, open up Terminal and type lookupd -flushcache. I also recommend clearing your browser cache.

Open up your browser and go to the web site you just entered in the hosts file. It should now point to the new server. If not, make sure you remembered to flush your DNS cache.

Now you can save yourself some trouble with moving sites and make sure they work before you switch them over. Your clients will be happy, and more importantly you’ll have peace of mind that you won’t be getting calls from panicking clients that their site is broken.

Install ImageMagick from source on OS X Tiger (and Leopard)

Update Feb. 10, 2008: I’ve tested and verified this also works on OS X Leopard. An additional command was needed to make the JPEG library install without errors, noted below. I’ve also updated the commands outlined below for the latest versions of the software.

If you’re like me and use mini_magick or (or RMagick) Ruby gems on OS X for building Rails apps, installing ImageMagick can be a pain. There is a universal binary package which works alright, but I prefer to build apps from source when possible. Also, I run a few web sites on my G5 Power Mac and I want ImageMagick to be compiled specifically for the PowerPC platform, which will get me a bit of an advantage in speed and reliability. I ran into a few roadblocks while getting it all compiled and installed, so I thought I’d share how I did it.

First off, I should mention that I only added in JPEG and PNG support for ImageMagick, so if you need more formats supported, this article doesn’t cover it. You’ll also need the OS X Developer Tools installed on your system. Finally, I did this on the latest version of OS X (Tiger 10.4.9) for PowerPC and Intel Macs. Both tested working. Update: Also tested on OS X Leopard on Intel.

Here is a list of packages you’ll need to download. Get all of these and place them in one directory.

Once you’re done downloading, open the Terminal app and go to the folder you downloaded the files to. For example if you downloaded them do your Desktop, type the following in the command line and hit enter:

  cd Desktop

Step One: Compile and Install JPEG Libraries

Installing the JPEG libraries is actually the trickiest part of the install. By default on OS X building and installing the JPEG libraries won’t install any libraries at all, only some binaries that allow you to manipulate JPEG files.

Update: I also discovered while installing the JPEG library on Leopard that it needs the /usr/local/man/man1 directory to install without errors. I added the command below to create it.

So here’s the magic to force it to install JPEG libraries that ImageMagick will use while compiling:

  tar zxvf jpegsrc.v6b.tar.gz
  cd jpeg-6b
  cp /usr/share/libtool/config.sub .
  cp /usr/share/libtool/config.guess .
  sudo mkdir -p /usr/local/man/man1
  ./configure --enable-shared --enable-static
  make
  sudo make install
  sudo ranlib /usr/local/lib/libjpeg.a
  cd ../

Done! You shouldn’t have gotten any errors. If you did, then make sure you definitely have the OS X Developer Tools installed.

Step Two: Compile and Install LibPNG

This is pretty straightforward, and doesn’t require any weird tricks to get it to work.

  tar zxf libpng-1.2.24.tar.gz
  cd libpng-1.2.24
  ./configure
  make
  sudo make install
  cd ../

Step Three: Compile and Install ImageMagick

This is pretty simple too. We don’t have to pass any special options to ImageMagick either. It should automatically pick up that we have JPEG and PNG libraries installed and compile in support automatically.

  tar zxf ImageMagick.tar.gz
  cd ImageMagick-6.3.8/
  ./configure

After ./configure is done, you should check to make sure the following lines are present in the output that indicated JPEG and PNG support are in there:

  JPEG v1           --with-jpeg=yes               yes
  PNG               --with-png=yes                yes

If those are both set to yes, then you’re golden. Now finish him!

  make
  sudo make install

You now have ImageMagick install from source on OS X Tiger. Now you can use mini_magick or RMagick Ruby gems in your apps. If you found this useful or have any questions, leave me a comment below.