How to Change the Host Name on an Apache Server

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.
Apache supports name-based virtual hosts and multiple IP addresses.
Image Credit: kjekol/iStock/Getty Images

The Apache HTTP daemon supports name-based hosting so that multiple domain names can share one IP address. Changing a host name effectively changes your website's domain name, since your visitors request the site by sending its host name, in the form of a URL, to your specified port in the request's HTTP headers. Whether you run Apache in Linux, Windows or OS X, your host names are stored in the main Apache configuration file, which may include virtual host names from other configuration files.

Advertisement

Step 1

Open the main Apache configuration file, httpd.conf, in your default text editor. Depending on your operating system, it's located in one of the following directories:

Video of the Day

Linux: /etc/httpd/conf/ Windows: C:\Program Files\Apache Software Foundation\conf\ OS X: /etc/apache2/

Advertisement

Step 2

Search for the word "ServerName" (without quotes, here and throughout) in the file. You can access the search function in most text editors by pressing "Ctrl-F" or by clicking "Search" or "Edit" in the menu bar. The ServerName line contains your current host name and port number separated by a colon.

Advertisement

Step 3

Enter a new host name after the ServerName keyword and ensure that you don't erase the trailing port number. The ServerName line should resemble the following example:

ServerName www.mynewhostname.com:80

Advertisement

Step 4

Search for the term "Virtual Hosts" in the configuration file. The Virtual Hosts section occurs around line 500 of the default file, but it may be lower if you've added many customizations. If your configuration file includes virtual hosts from other files, those files and their absolute paths are listed in this section. Alternatively, the virtual host information may be included directly in the httpd.conf file.

Advertisement

Advertisement

Step 5

Open the files included in the Virtual Hosts section in your text editor. In most cases, the included file is called httpd-vhosts.conf, and it's located in the same directory as httpd.conf. However, servers with too many virtual hosts to fit in one file often store them in separate files and include each one on a separate Include line. If the virtual host information is printed directly in the httpd.conf file, you can edit this section where it is.

Advertisement

Step 6

Change your virtual host's ServerName line to your new host name, but don't append the port number to the virtual host name. If Apache has been serving Web pages from your virtual host using the old host name, your IP address and port number are already included in the opening VirtualHost brackets and resemble the following example:

Advertisement

<VirtualHost *:80> ServerName www.mynewhostname.com

The asterisk following the VirtualHost keyword is a wildcard value that represents all the IP addresses on your server.

Advertisement

Step 7

Restart Apache by restarting your computer or by opening a console and executing the appropriate command for your operating system. In Linux and OS X, enter "sudo apachectl -k restart," and in Windows, enter "httpd.exe -k restart."

Video of the Day

Advertisement

Advertisement

references

Report an Issue

screenshot of the current page

Screenshot loading...