Managing multiple sites on XAMPP - apache

I have multiple sites deployed on xampp. For now, all of the sites are using one port i.e. 80. For this reason, whenever I am logged into one of the sites, I am automatically logged out from the other and vice versa. I have looked at this article to How to run multiple websites on XAMPP on Windows. And tried to follow it but I am unable to do the needful.
I have added one more port to listen
Listen 80
Listen 8080
In my httpd-vhosts.conf I have done the following
NameVirtualHost *:8080
<VirtualHost *:8000>
DocumentRoot "F:\xampp\htdocs\mdc"
ServerName localhost:8080
<\VirtualHost>
After doing this I have turned off my xampp and then tried to restart apache and mysql. But apache is not starting
My URL is http://localhost:8080/mdc/backend/web
Note: Without doing any virtual host setting the above URL is accessible on both 80 and 8080 ports
Update 1
Herer is my httpd.conf file

This is not a fix for your issue, Here i will explain how i manage multiple websites on xampp.
First i assumes that your using windows
i always use the same port with different server names.
on : E:\xampp\apache\conf\extra\httpd-vhosts.conf (In my case i installed xampp on E drive)
i added this code
<VirtualHost *:80>
DocumentRoot "e:/xampp/htdocs/mysite1"
ServerName mysite1.flames.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "e:/xampp/htdocs/mysite2"
ServerName mysite2.flames-team.com
</VirtualHost>
And on ( C:\Windows\System32\drivers\etc\hosts) my windows host file i added this lines
127.0.0.1 mysite1.flames.com
127.0.0.1 mysite2.flames-team.com
With this approach you can access the site with a clean readable URLs
In this case if you want to see the first site just enter this URL mysite1.flames.com on browser.
Cheers

Write the closing tag </VirtualHost> instead of <\VirtualHost> in the file httpd-vhosts.conf. I did it and it worked for me.

Related

Xampp vhost cannot load the virtualhost without port number

I am not sure if this is a repost but I couldn't find a solution.
I have an application setup in my local environment which the name I added in my hosts file (C:\Windows\System32\drivers\etc) as follows,
127.0.0.1 skeletonpage.lk
Also I added a record in httpd-vhosts.conf as below.
<VirtualHost *>
DocumentRoot "C:/xampp/htdocs/skeleton/public"
ServerName skeletonpage.lk
<Directory "C:/xampp/htdocs/skeleton/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I run the application on browser I can only load the homepage with the port number tagged with the site name. Ex: http://skeletonpage.lk:83/
I have both XAMPP and WAMP in my machine and my site runs in XAMPP for which the port 83 is given, If I remove :83 it loads the homepage of wamp server which has port 80.
I tried removing and modifying above code snippet but still cant get rid of port 83. I know this is something simple, but would be glad if someone can help.
I modified as <VirtualHost *:83> also <VirtualHost 127.0.0.1:83> and restarted XAMPP also modified NameVirtualHost *:83 but no use.

Multiple web applications with Apache 2.4

I want to have two webapps (webapp1 and webapp2 resident under /var/www/html/webapps/), both using PHP and JSP, running on the same machine:
Apache 2.4
Tomcat 7.0.50 (+APJ connector)
and want to make them accessible through the following URLs (with identical IP and ports):
localhost/webapp1
localhost/webapp2
I am aware of Virtual Hosts facility. The problem is that Apache seems to "see" only the first site available: whenever I look for localhost/webapp2, I get a 'Not Found' error. Note that if I look for "localhost:8080/webapp2" (i.e., bypassing apache2) everything works fine.
Each webapp has its own conf file under sites-available directory. For example, in webapp2.conf I have
JkMountCopy On
JkMount /webapp2/* tomcat_worker
How can I solve?
From the documentation
Note
Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.
Listen 80
Listen 8080
<VirtualHost 172.20.30.40:80>
ServerName www.example.com
DocumentRoot "/www/domain-80"
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.com
DocumentRoot "/www/domain-8080"
</VirtualHost>
<VirtualHost 172.20.30.40:80>
ServerName www.example.org
DocumentRoot "/www/otherdomain-80"
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.org
DocumentRoot "/www/otherdomain-8080"
</VirtualHost>
If you want additional help, show us your configuration files related.

Apache different sites on different ports, still links to same site. Bind9 for domain names

I've been trying to create 3 different domains linking to 3 different sites on the same machine, 2 which works but the third on the different port links to the first page.
My apache config looks like this:
Listen 81
NameVirtualHost *:81
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/www
</VirtualHost>
<VirtualHost *:80>
ServerName www2.example.com
DocumentRoot /var/www/www2
</VirtualHost>
<VirtualHost *:81>
ServerName controlpanel.example.com
DocumentRoot /var/www/controlpanel
</VirtualHost>
I've used Bind9 to set up the domains.
www IN A 123.123.123.123
www2 IN A 123.123.123.123
controlpanel IN A 123.123.123.123
www and www2 works fine and shows the correct site, however controlpanel.example.com also links to the first www site. When I enter the port manualy on the ip, xxx.xxx.xxx.xxx:81, i get linked correctly. The thing is that I don't really know where I'm doing it wrong, this is the first time I'm trying anything like this. You got any ideas?
Im also running this on an old ubuntu 12.04 server.
Regarding where you're going in the comments for the previous answer:
You could add a port 80 virtualhost for controlpanel.example.com and put a single statement inside,
Redirect / http://controlpanel.example.com:81
The purpose of the ServerName is not to inform the browser what port your webserver is using. It's used for name-based virtualhosts and as a last resort for self-referential links (out of the box, self-referential links are generated with whatever the client already thought it was accessing via the Host: header)
But there is definitely something quite bizarre about your requirement. Usually the motivation is to not use custom ports, and if they are, to address the server with a low port and have the por remapped by some intermediary (load balancer, proxy).
If you want your third virtualhost to be simulataneously the defautl on port 81 and a name-based option on port 80:
Change
<VirtualHost *:81>
to
<VirtualHost *:80 *:81>
Apache finds the set of virtual hosts with the best IP:PORT based match first, then if NameVirtualHost also matches, starts looking at the ServerNames from that set.

creating Subdomain in Xampp doesn't work

I made a subdomain on Localhost over Xampp with following code in httpd-vhosts.conf (guide from different sources)
NameVirtualHost *:80 (uncommented by removing #)
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/sub
ServerName sub.localhost.com
</VirtualHost>
and following code into hosts of Windows/System32/drivers/etc/
127.0.0.1 localhost
127.0.0.1 sub.localhost
now the problem is subdomains are not working. One more thing I just noticed that when I start apache service in Xampp Control Panel, it has set the port as 80,443 for Apache which is good but as soon as I hit localhost in browser it changes port to different ports like 52352 etc. I also tried to setting up code in hosts file as
127.0.0.1:80 localhost
127.0.0.1:80 sub.localhost
but not working. I tried many other things but all in vein. While a month before I created successfully in the same Xampp Installation. off course i have created sub directory in htdocs.
Make sure you have this line uncommented in httpd.conf
#Include conf/extra/httpd-vhosts.conf
Remove this line in httpd-vhosts.conf (or comment it out):
NameVirtualHost *:80
Make sure you have a blank line at the end of both httpd-vhosts.conf and hosts, and make sure you're using tabs to separate IPs with their associated domains in the hosts file.
Make sure another application is not using ports 80, 443 (Skype for example).
Ultimately, restart your Apache server.
If you want to create sub directory, *emphasized text*127.0.0.1:80 localhost*emphasized text*
the settings back to original and change only *emphasized text*DocumentRoot C:/xampp/htdocs/sub*emphasized text*

Having challenges creating virtual servers on apache server for win7 (resolving hostname)

I have an apache server installed on my portable windows 7 machine using xampp as an interface. I've been working with a few people on an irc channel but must soon go to bed and replies are getting slower.
I have the following code added to my httpd.conf file:
#virtual servers
#Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost.MEALS
DocumentRoot C:\xampp\htdocs\MEALS
DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.HA
DocumentRoot C:\xampp\htdocs\Hackers
DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.WIK
DocumentRoot C:\xampp\htdocs\WhoIKnow
DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.TUS
DocumentRoot C:\xampp\htdocs\Unity
DirectoryIndex index.php
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.PHP
DocumentRoot C:\xampp\htdocs\phpMyAdmin
DirectoryIndex index.php
</VirtualHost>
And I have the following configuration:
Setting environment for using XAMPP for Windows.
John#ASSIMILATER C:\xampp
# httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 localhost (C:/xampp/apache/conf/extra/httpd-ssl.conf:80)
*:80 is a NameVirtualHost
default server localhost.MEALS (C:/xampp/apache/to which there was conf/httpd.conf:512)
port 80 namevhost localhost.MEALS (C:/xampp/apache/conf/httpd.conf:512)
port 80 namevhost localhost.HA (C:/xampp/apache/conf/httpd.conf:516)
port 80 namevhost localhost.WIK (C:/xampp/apache/conf/httpd.conf:520)
port 80 namevhost localhost.TUS (C:/xampp/apache/conf/httpd.conf:524)
port 80 namevhost localhost.PHP (C:/xampp/apache/conf/httpd.conf:528)
Syntax OK
John#ASSIMILATER C:\xampp
#
However when I try to access localhost.PHP in my web browser it tells me the server is not found. I was instructed that I need to resolve the host names on my machine. I was directed to a few irc channels (dns and windows) to which there was no reply. I searched google and ran across this site: http://technet.microsoft.com/en-us/library/bb727005.aspx#EEAA. I'm not quite sure what I'm reading and as near as I can tell it doesn't quite give me a clear instruction on where to resolve the host name or a file to edit.
Also currently the default server is the top virtual server in the code. I would like to call localhost and show a simple html page I created which is in "htdocs/index.html" which will navigate to the other servers (links pointing to "localhost.PHP" etc). is there a way to have the default server remain "localhost" which points to "htdocs/index.html" while maintaining the other virtual servers, or will I have to create another virtual server and make that the default?
Any and all help appreciated.
edit: I had someone help me find the HOSTS file on my machine but am unable to edit it. I turned off all antivirus features, turned off spybot (UAC was always off and I always run with administrator privileges) specifically right clicked on np++ editpadlite and windows notepad and was only able to edit in notepad, but was required to save the file with a different name.
You have to explicitly run Notepad as an administrator (regardless of UAC settings) and when you go to save, make sure you select 'all files' rather than the default *.txt.
I found the same thing when I tried to edit the hosts file on W7, but it seems that just being an administrator on the machine isn't quite the same as explicitly running the program as an administrator.