I do this by configuring my webserver using VirtUalHost technique, details here:
https://httpd.apache.org/docs/current/vhosts/
Then I put the domain names into my hosts file, details here:
https://en.wikipedia.org/wiki/Hosts_(file)
An after thought:
Leave your first website as localhost = 127.0.0.1
just use the virtual host method to setup the extra ones.
I often use exactly the same domain name as will be use when the site is launched, just commenting out the lines in the hosts file with a hash = “#” switches the browser from accessing the localhost or using the webs domain name system.
Hello @rossmitchell, thank you for your answer. I’ve read the links you sent in your reply, I have a few more questions. I have zero knowledge in Apache, really. I’ve modified the httpd.conf file and added the following:
[...]
#Listen 12.34.56.78:80
Listen 80
Listen 81 #New port
[...]
[...]
#### Localhost VirtualHost ####
<VirtualHost 127.0.0.1:80>
<Directory "C:/Program Files/Ampps/www">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName localhost
ServerAlias localhost 127.0.0.1
ScriptAlias /cgi-bin/ "C:/Program Files/Ampps/www/cgi-bin/"
DocumentRoot "C:/Program Files/Ampps/www"
ErrorLog "C:/Program Files/Ampps/apache/logs/error.log"
CustomLog "C:/Program Files/Ampps/apache/logs/access.log" combined
</VirtualHost>
#My new VirtualHost
<VirtualHost 127.0.0.2:81>
<Directory "C:/Program Files/Ampps/www">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName mynewhostname
ServerAlias mynewhostname 127.0.0.2
DocumentRoot "C:/Program Files/Ampps/www"
ErrorLog "C:/Program Files/Ampps/apache/logs/error.log"
CustomLog "C:/Program Files/Ampps/apache/logs/access.log" combined
</VirtualHost>
[...]
After I did this, http://127.0.0.1 is now unaccessbile, and I still don’t know how to install WordPress into http://127.0.0.2. I know I’m probably missing quite a lot of information here. Have I just ruined all I’ve done so far in http://127.0.0.1? How do I recover it, and how do I create a new instance?
Thank you.
Edit:
Actually, now http://127.0.0.1 is running normally, and http://127.0.0.2 is redirecting me back to http://127.0.0.1. Maybe I did add a new Virtual Host correctly, after all. Any thoughts?
-
This reply was modified 4 years, 11 months ago by
vicentemmos.
-
This reply was modified 4 years, 11 months ago by
vicentemmos.
-
This reply was modified 4 years, 11 months ago by
vicentemmos.
Firstly restore your original httpd.conf file. There are no changes necessary for your original website.
You need to load a new set of WordPress files for the new website, it is best tyo keep them out of the “Program Files” space, the var directory will do. Make a sub directory for site2, also create a logs directory.
Add a new virtualhost block to your restored httpd.conf file like this:
(Note that it is on port 80 of 127.0.0.1)
#A new VirtualHost
<VirtualHost *:80>
<Directory "C:/var/site2">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName mynewhostname
ServerAlias www.mynewhostname
DocumentRoot "C:/var/site2"
ErrorLog "C:/var/site2/logs/error.log"
CustomLog "C:/var/site2/logs/access.log" combined
</VirtualHost>
Now add these two lines to your hosts file:
www.mynewhostname 127.0.0.1
mynewhostname 127.0.0.1
Then if you want to access your site2 from elsewhere on your LAN you do this:
– find the IP address that your server PC uses, something like 192.168.0.27
whatever it is say it is a.b.c.d
– On every computer that want to access your site2 that is on the LAN, add these lines to its hosts file:
mynewhostname a.b.c.d
www.mynewhostname a.b.c.d
Of course this requires that the IP address of the server never changes, there are ways to do this.