Subversion hosting, CVS hosting, Trac hosting, Bugzilla hosting and software collaboration Providing hosted Subversion, CVS, Trac and Bugzilla repositories
 

January 31, 2008

Apache Auto-configuration with a Dynamic IP Address

Filed under: Operating Systems — Tags: , , — Greg Larkin @ 6:02 pm

Hi everyone,

As I was setting up the new FreeBSD 6.2 VM with Apache 2.2 preinstalled in it, I ran into a problem. The VM’s virtual Ethernet adapter is configured for DHCP, and the VMware software acts as a DHCP server to hand out IP addresses as VMs are started.

The problem is that Apache likes to know the IP address of the machine it’s running on, and in some cases, it won’t start unless it does. Luckily, the DHCP client in FreeBSD, and likely other operating systems, calls separate hook scripts (if they exist) before and after configuring the adapter with a dynamic address.

In my case, I wanted to automatically create a ServerName directive for Apache with the dynamic address. The default Apache 2.2 installation on FreeBSD provides a user configuration file include directory at /usr/local/etc/apache22/Includes. As it starts up, Apache loads any file placed in that directory and named with the “.conf” suffix. I think we’ve got a solution!

It’s also necessary to tweak the contents of the /etc/hosts file so that the VM can resolve its own hostname. I wrote a DHCP client exit hook script that configures both Apache and the /etc/hosts file. This script should be easily adaptable to other operating systems, as it uses the standard Bourne shell syntax.

Simply download the script, unzip the contents into /etc, and let me know what you think!

Bookmark and Share

Keep in touch,
Greg
SourceHosting.net, LLC


3 Comments

  1. It’s working good! Thank you.

    P.S. I just used a second part ofa script, without a string related ServerNames.

    Comment by Alexander KrasilnikovNo Gravatar — March 8, 2010 @ 10:12 am

  2. Thank you
    but i can’t download the torrent file!!

    Comment by M JoudehNo Gravatar — February 1, 2011 @ 9:39 am

  3. @M Joudeh: The torrent file refers to a VM with an obsolete version of FreeBSD at this point. I would suggest downloading an updated VM from this site: http://www.thoughtpolice.co.uk/vmware/#freebsd8.1

    Once you do that, it’s pretty easy to install Apache 2.2 using the ports system.

    Hope that helps,
    Greg

    Comment by Greg LarkinNo Gravatar — February 4, 2011 @ 5:09 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.


Call me - Greg Larkin: error

Powered by WordPress