{"id":1540,"date":"2018-02-27T00:04:19","date_gmt":"2018-02-27T05:04:19","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=1540"},"modified":"2018-04-08T11:21:17","modified_gmt":"2018-04-08T16:21:17","slug":"apache-change-server-name-localhost-custom-name","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2018\/02\/27\/apache-change-server-name-localhost-custom-name\/","title":{"rendered":"Apache: How to change the server name from localhost to custom name"},"content":{"rendered":"<p>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 &#8220;localhost&#8221; which is found at the default IP address of 127.0.0.1. For example, web pages can be found at:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">http:\/\/localhost\/\r\nhttp:\/\/127.0.0.1\/<\/pre>\n<p>and scripts in the cgi-bin can be accessed like so:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">http:\/\/localhost\/cgi-bin\/env.py\r\nhttp:\/\/127.0.0.1\/cgi-bin\/env.py<\/pre>\n<p>What I wanted to do was use a made up local domain name instead, called &#8220;bluegalaxy.dev&#8221;. With the Bitnami Apache configuration, the way to do this is very simple and was just a matter of editing my Windows 10 &#8220;hosts&#8221; file. This file is located at:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">C:\\Windows\\System32\\drivers\\etc<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" id=\"img_ds\" class=\"alignnone size-full wp-image-1543\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hosts.jpg\" alt=\"\" width=\"163\" height=\"148\" \/><\/p>\n<p>Open the &#8220;hosts&#8221; 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&#8217;t work.<\/p>\n<p>For example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" id=\"img_ds\" class=\"alignnone wp-image-1545 size-full\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hostsfile.png\" alt=\"\" width=\"725\" height=\"445\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hostsfile.png 725w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hostsfile-300x184.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hostsfile-676x415.png 676w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/p>\n<p>Now I can still access the server via localhost, but I can also use my made up server name in script URLs. For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">http:\/\/bluegalaxy.dev\r\nhttp:\/\/bluegalaxy.dev\/cgi-bin\/env.py<\/pre>\n<p>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.<\/p>\n<p><strong>Update (April 8, 2018):\u00a0 <\/strong>Local host names with\u00a0&#8220;.dev&#8221; can no longer be used without https.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1836\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/dev-https.png\" alt=\"\" width=\"1084\" height=\"89\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/dev-https.png 1084w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/dev-https-300x25.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/dev-https-768x63.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/dev-https-1024x84.png 1024w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/dev-https-676x56.png 676w\" sizes=\"auto, (max-width: 1084px) 100vw, 1084px\" \/><\/p>\n<p>What was working before at bluegalaxy.dev was no longer working, so I changed the local domain to &#8220;bluegalaxy.local&#8221;.<\/p>\n<p>Note: In addition to having multiple local domains point at 127.0.0.1 by editing the hosts file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1838\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hosts-1.png\" alt=\"\" width=\"604\" height=\"514\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hosts-1.png 604w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hosts-1-300x255.png 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/p>\n<p>These different local host names can point to different server paths. This is done by editing the <mark>httpd-vhosts.conf<\/mark> file of the Apache server, which can be found here:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">C:\\Bitnami\\wampstack-7.1.14-0\\apache2\\conf\\extra\\httpd-vhosts.conf<\/pre>\n<p>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:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">&lt;VirtualHost *:80&gt;\r\n    DocumentRoot \"C:\/Bitnami\/wampstack-7.1.14-0\/apache2\/htdocs\"\r\n    ServerName localhost\r\n&lt;\/VirtualHost&gt;\r\n\r\n&lt;VirtualHost *:80&gt;\r\n    DocumentRoot \"C:\/Bitnami\/wampstack-7.1.14-0\/apache2\/htdocs\/lsapp\/public\"\r\n    ServerName lsapp.local\r\n&lt;\/VirtualHost&gt;\r\n<\/pre>\n<p><strong>Important:\u00a0<\/strong><\/p>\n<p>1. In order for Apache to use the httpd-vhosts.conf file, this line inside the <mark>httpd.conf<\/mark> file needs to be uncommented (remove the pound sign from the beginning of the line):<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\"># Virtual hosts\r\nInclude conf\/extra\/httpd-vhosts.conf<\/pre>\n<p>2. The Apache server needs to be restarted in order for the changes to be seen.<\/p>\n<h3><strong>In Summary<\/strong><\/h3>\n<h4>1.<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1840\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hosts-graphic.png\" alt=\"\" width=\"522\" height=\"292\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hosts-graphic.png 522w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/hosts-graphic-300x168.png 300w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/p>\n<h4>2.<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1841\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/httpd-conf.png\" alt=\"\" width=\"522\" height=\"292\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/httpd-conf.png 522w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/httpd-conf-300x168.png 300w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/p>\n<h4>3.<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1842\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/httpd-vhosts-conf.png\" alt=\"\" width=\"522\" height=\"292\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/httpd-vhosts-conf.png 522w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/02\/httpd-vhosts-conf-300x168.png 300w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;localhost&#8221; 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 &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2018\/02\/27\/apache-change-server-name-localhost-custom-name\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Apache: How to change the server name from localhost to custom name<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78],"tags":[106,124],"class_list":["post-1540","post","type-post","status-publish","format-standard","hentry","category-technologies-and-tools","tag-apache","tag-httpd-conf"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=1540"}],"version-history":[{"count":10,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1540\/revisions"}],"predecessor-version":[{"id":1843,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1540\/revisions\/1843"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=1540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=1540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=1540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}