In this scenario I was tasked with setting up a local server on our company network (so not accessible out side our network) for students to access and upload their own websites, and give them access to their own MySQL database through PhpMyAdmin.
The first thing is to direct your desired domain name to the networked computer (since I don’t want to keep typing the IP address in the address bar, and it helps my students relate to a real web server). In the DNS manager of your domain host, have the domain point to your local IP address (this is usually a 192.168.1.##). Once the DNS record is saved it may take up to 48 hours before it updated, but their is still some other things to do before we see this work.
You’ll want to already have your favourite Apache, MySQL, PHP package installed. I personally love XAMPP so I’ll be using that.
Navigate to your XAMPP’s httpd-vhosts.conf file, it should be in this directory:
C:\xampp\apache\conf\extra\httpd-vhosts.conf
Go to the bottom of the file add the following:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs\yourfolder"
ServerName yourdomain.com
<Directory "C:\xampp\htdocs\yourfolder">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Replace the area the says “yourdomain.com” the the domain name you need the server to accept.
Replace the “yourfolder” with the folder in your htdocs folder your want the domain to point to (remove if your want to just use your htdocs folder as the site root).
That will get the domain pointing to the folder and acting as a website, but we aren’t done yet; One issue we have is PhpMyAdmin does not accept requests from names outside the localhost, so we need to tell it to allow. Find the http-xampp.conf file, it should be located here:
C:\xampp\apache\conf\extra\httpd-xampp.conf
Go to the bottom of the file and you should find an area labeled as “New XAMPP security concept”, change the “Allow from” part to just allow “all”. it should look like this:
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
Deny from all
Allow from all
ErrorDocument 403 /error/HTTP_XAMPP_FORBIDDEN.html.var
</LocationMatch>
Finally, that is all we need to do in XAMPP, but for security purposes Window does not allow outside access to your computer unless strictly approved. We just need to add our domain to the safe list; navigate to your windows hosts file found here:
C:\Windows\System32\drivers\etc\hosts
In this file, near the bottom, you’ll find where Windows is allowing even your localhost to access your computer (“# 127.0.0.1 localhost”). At the bottom of any other localhost name resolutions, add your domain to be resolved to the same local IP (127.0.0.1 which is just a reference to your computer), so your file should look like this:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# 127.0.0.1 yourdomain.com