Apache Virtual Host

See this for reference:  https://ultimatefosters.com/hosting/setup-a-virtual-host-in-windows-with-xampp-server/

Click Here for Helpful Video

  • Virtual host will set up an alias for localhost and allow you to access each website with a specific name.  This is good for backend api so that the front end application can set its api endpoint to a specific name rather than something starting with “localhost”
  • Open httpd.conf file present in C:\xampp\apache\conf\httpd.conf
    Remove the #(hash) sign present to include the “httpd-vhosts.conf” file in httpd.conf file.
  • Go to c:\xampp\apache\conf\extra\httpd-vhosts.conf. Go to the bottom of the file and add these lines:
    # a comment about local database
    <VirtualHost *:80>
    	DocumentRoot "path to index.php"
            ServerName   localdb-name.com
    	ServerAlias  www.localdb-name.com
    	ServerAlias  server.ngrok.io
    	<Directory "path to index.php">
    	Options +Indexes +Includes +FollowSymLinks +MultiViews
    	AllowOverride All
    	Require all granted
    	</Directory>
    </VirtualHost>

     

  • Open c:\Windows\System32\drivers\etc\hosts. Add the following line at the end of the file:
    #comment about local database
    127.0.0.1 		localdb-name.com