Copy link to clipboard
Copied
I created a virtual host by copying and pasting this code in my httpd-vhosts configuration file:
!
##<VirtualHost *:80>
##ServerAdmin webmaster@dummy-host.example.com
##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
##ServerName dummy-host.example.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>
If I delete this code I won't be able to access the site for which I created the fake domain. On the other hand, I can't create another site because now 127.0.0.1 is synonymous with the virtual domain.
So do you keep the changed code and comment it out until the day you might need to access the site? Or do you change the site host name to localhost/sitename as you would normally when you create a site to test locally?
I usually just put the site folder name after the localhost/ so I don't have to do anything.
Sure. I think many people do that, but it won't be as close a match to the remote system as if you used virtual hosts. I never use an extension (com net org) when I create virtual hosts, but if I have two sites with the same name but different extensions, I use:
china_com
china_net
Copy link to clipboard
Copied
I have about 20 virtual hosts pointed to 127.0.0.1
In windows / system32 / drivers / hosts you attach all of them to 127.0.0.1 but in Apache you point each domain to the specific "physical location" in the file path
Example:
<VirtualHost *:80>
DocumentRoot "D:/Apache24/htdocs/yogasite/55"
<Directory "D:/Apache24/htdocs/yogasite/55">
Options +Indexes +FollowSymLinks +ExecCGI
DirectoryIndex index.php
Order allow,deny
Allow from all
AllowOverride All
Require all granted
</Directory>
ServerName china:80
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# include the folder containing the vhost aliases for zend server deployment
IncludeOptional "D:\ZendServer\etc\sites.d\http\china\80/*.conf"
</VirtualHost>
Copy link to clipboard
Copied
Hi Rob. For some reason it stripped out my code in the previous post.
The code I added my virtual domain information is
##<VirtualHost *:80>
##ServerAdmin webmaster@dummy-host.example.com
##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com"
##ServerName dummy-host.example.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>
Copy link to clipboard
Copied
That is the example code from Apache 2.4. Assuming that you are replacing dummy-host with your domain name and removing the comment characters, that is correct code. The most important lines are the DocumentRoot and ServerName.
Copy link to clipboard
Copied
Creating a virtual host this way enables you to create a subdomain of localhost. But now I can't create for example a new site on 127.0.0.1 such as localhost/newsite because localhost is synonymous with this virtual domain. So is the only way to switch between this virtual domain and new sites created on localhost to comment out the virtual domain code with hashtags?>
Copy link to clipboard
Copied
. . .because localhost is synonymous with this virtual domain.
If you really did that, and unless you have an incredibly good reason for having done so, then therein lies your problem. Otherwise it would be possible to create a subdomain on localhost so that:
localhost points to the web root (public_html, for example) which may also be the root of the main website
example.localhost points to localhost/example
. . .so if you really have localhost pointing to something like. . .
public_html/newsite
. . .then you have created the problem you are now trying to solve
Copy link to clipboard
Copied
The reason was to mimic the URL structure of the eventual site in order to test the central authentication service on localhost.
Copy link to clipboard
Copied
The reason was to mimic the URL structure of the eventual site in order to test the central authentication service on localhost.
I recall that from a thread you started some time back. I was skeptical then that your solution was correct.
I always create a virtual host that allows my development environment to match the remote environment, for example:
http://china -- local development
http://china.com -- remote public site
And PHP allows you to simply get the host name and use it as a variable, like this:
$domain = $_SEVER['HTTP_HOST'];
Apache has a lot of capability around domain names and where they can point, so I suggest you dive into the Apache documentation. There are significant differences between Apache 2.2 and 2.4, so make sure you review the documentation for the version you are using.
Copy link to clipboard
Copied
I recall that from a thread you started some time back. I was skeptical then that your solution was correct.
Problem is I'll never know. The CAS plugin I wanted to use to test was outdated or otherwise didn't work.
Copy link to clipboard
Copied
I usually just put the site folder name after the localhost/ so I don't have to do anything.
Copy link to clipboard
Copied
I usually just put the site folder name after the localhost/ so I don't have to do anything.
Sure. I think many people do that, but it won't be as close a match to the remote system as if you used virtual hosts. I never use an extension (com net org) when I create virtual hosts, but if I have two sites with the same name but different extensions, I use:
china_com
china_net