Apache: How to change the server name from localhost to custom name

I recently installed the Bitnami WAMP stack which simultaneously installs Apache 2, PHP, and MySQL. The default domain name when installing Apache server is either “localhost” which is found at the default IP address of 127.0.0.1. For example, web pages can be found at:

http://localhost/
http://127.0.0.1/

and scripts in the cgi-bin can be accessed like so:

http://localhost/cgi-bin/env.py
http://127.0.0.1/cgi-bin/env.py

What I wanted to do was use a made up local domain name instead, called “bluegalaxy.dev”. With the Bitnami Apache configuration, the way to do this is very simple and was just a matter of editing my Windows 10 “hosts” file. This file is located at:

C:\Windows\System32\drivers\etc

Open the “hosts” file in Notepad++ or another plain text editor (Run in Administrator mode). The solution is to add a new line to the hosts file with 127.0.0.1 on the left, and the desired server name on the right. Note: You MUST remove the pound sign, or this won’t work.

For example:

Now I can still access the server via localhost, but I can also use my made up server name in script URLs. For example:

http://bluegalaxy.dev
http://bluegalaxy.dev/cgi-bin/env.py

Note: In the Environment variables, this affects both SERVER_NAME and HTTP_HOST, but it does not affect the REMOTE_ADDR, which stays at 127.0.0.1.

Update (April 8, 2018):  Local host names with “.dev” can no longer be used without https.

What was working before at bluegalaxy.dev was no longer working, so I changed the local domain to “bluegalaxy.local”.

Note: In addition to having multiple local domains point at 127.0.0.1 by editing the hosts file:

These different local host names can point to different server paths. This is done by editing the httpd-vhosts.conf file of the Apache server, which can be found here:

C:\Bitnami\wampstack-7.1.14-0\apache2\conf\extra\httpd-vhosts.conf

For example, localhost should point to the htdocs folder and I want lsapp.local to point to a specific folder inside htdocs called lsapp/public:

<VirtualHost *:80>
    DocumentRoot "C:/Bitnami/wampstack-7.1.14-0/apache2/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/Bitnami/wampstack-7.1.14-0/apache2/htdocs/lsapp/public"
    ServerName lsapp.local
</VirtualHost>

Important: 

1. In order for Apache to use the httpd-vhosts.conf file, this line inside the httpd.conf file needs to be uncommented (remove the pound sign from the beginning of the line):

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

2. The Apache server needs to be restarted in order for the changes to be seen.

In Summary

1.

2.

3.