how to run multiple projects on Apache using Virtual Hosts? - php

My vhosts are:
# for localhost to work properly
<VirtualHost *:1983>
ServerAdmin admin#localhost
DocumentRoot "d:/wamp/www"
ServerName localhost
</VirtualHost>
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf
# - #: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/
# - #: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope)
# afm : Agile Farm Manager
#<VirtualHost *:1983>
# DocumentRoot "D:/projects/afm/Code"
# ServerName dafm.dev
# <Directory "D:/projects/afm/Code">
# Order allow,deny
# Allow from all
# AllowOverride All
# </Directory>
#</VirtualHost>
# mrs : Meeting Request System
<VirtualHost mrs.dev:1983>
DocumentRoot "D:/wamp/www/mrs_site/mrs"
ServerName mrs.dev
ServerAlias mrs.dev
<Directory "D:/wamp/www/mrs_site/mrs">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
# dtk : Kit Designer
<VirtualHost dtk.dev:1983>
DocumentRoot "D:/wamp/www/designertoolkit/"
ServerName dtk.dev
ServerAlias dtk.dev
<Directory "D:/wamp/www/designertoolkit/">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
And my windows' hosts file has the following mappings
#VIRTUAL DOMAINS
127.0.0.1 dafm.dev
127.0.0.1 mrs.dev
127.0.0.1 dtk.dev
My configured port is :1983 so i access wamp like: http://localhost:1983/
or http://mrs.dev:1983/ goes to my current project. but my other projects are not accessible anymore.
like when i go to dtk.dev:1983/ goes to same project http://mrs.dev:1983/ for every valid request to wamp server.
I need to run multiple projects on WAMP simultaneously. What is the problem with the Virtual Hosts?
please help

You need to use NameVirtualHost. See Apache manual: http://httpd.apache.org/docs/current/vhosts/name-based.html
Like this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
Maybe this is working:
NameVirtualHost *:1983
# for localhost to work properly
<VirtualHost *:1983>
ServerAdmin admin#localhost
DocumentRoot "d:/wamp/www"
ServerName localhost
</VirtualHost>
# mrs : Meeting Request System
<VirtualHost *:1983>
DocumentRoot "D:/wamp/www/mrs_site/mrs"
ServerName mrs.dev
ServerAlias mrs.dev
</VirtualHost>
# dtk : Kit Designer
<VirtualHost *:1983>
DocumentRoot "D:/wamp/www/designertoolkit/"
ServerName dtk.dev
ServerAlias dtk.dev
</VirtualHost>
<Directory "D:/wamp/www/designertoolkit/">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
<Directory "D:/wamp/www/mrs_site/mrs">
Order allow,deny
Allow from all
AllowOverride All
</Directory>

Thanks to the anonymous #user4311956's answer for pointing out that the NameVirtualHost directive is important.
But with my own testing I found out that if I mention NameVirtualHost directive before each Virtual Host i create it works, fails otherwise.
here the code for httpd-vhosts.conf file that worked the magic:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:1983
# for localhost to work properly
<VirtualHost *:1983>
ServerAdmin admin#localhost
DocumentRoot "d:/wamp/www"
ServerName localhost
</VirtualHost>
# - See more at: http://yogeshchaugule.com/blog/2014/how-setup-virtual-hosts-wamp#sthash.zVhOHBlJ.dpuf
# - #: http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/
# - #: http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp (maybe out of usable scope)
# afm : Agile Farm Manager
#<VirtualHost *:1983>
# DocumentRoot "D:/projects/afm/Code"
# ServerName dafm.dev
# <Directory "D:/projects/afm/Code">
# Order allow,deny
# Allow from all
# AllowOverride All
# </Directory>
#</VirtualHost>
NameVirtualHost mrs.dev:1983
# mrs : Meeting Request System
<VirtualHost *:1983>
DocumentRoot "D:/wamp/www/mrs_site/mrs"
ServerName mrs.dev
</VirtualHost>
NameVirtualHost dtk.dev:1983
# dtk : Kit Designer
<VirtualHost *:1983>
DocumentRoot "D:/wamp/www/designertoolkit/"
ServerName dtk.dev
</VirtualHost>
Thanks again to #user4311956's answer for pointing me in right direction.

Related

Virtual host not working on XAMPP, something very strange happenning

Hi I have browsed all the resources, but still seems can't find the solution.
I have XAMPP Control Panel v 3.2.4 (compiled Jun 5th 2019) installed on my computer, it is installed in d:\xampp. I want to create a Virtual host, so that I can correctly use various global PATH variables.
I followed instructions closely.
This is from my D:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\xampp\htdocs"
<Directory "D:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName ikeen.localhost
DocumentRoot "D:\xampp\htdocs\ikeen"
SetEnv APPLICATION_ENV "development"
<Directory "D:\xampp\htdocs\ikeen">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have added following lines to the end of httpd.conf:
<Directory />
AllowOverride none
Require all granted
</Directory>
I have the following line in my hosts file in windows:
127.0.0.1 ikeen.localhost
This is the structure of my site directory
In order to avoid cache I open URL in the incognito mode and from different browsers. I always get redirect to dashboard - https://ikeen.localhost/dashboard/, it opens the standard "Welcome to XAMPP for Windows 7.4.3"
I have heard that it has something to do with https, as I'm always transferred to https URL even if I try to use http. I've looked at httpd-ssl.conf, but I don't know what to do there. Any ideas?
Finally! For everyone who is looking for the solution do the following:
My desired site is located at D:\xampp\htdocs\ikeen.
1) Add this to your httpd-vhosts.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\xampp\htdocs"
<Directory "D:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName ikeen.localhost
DocumentRoot "D:\xampp\htdocs\ikeen"
SetEnv APPLICATION_ENV "development"
<Directory "D:\xampp\htdocs\ikeen">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
2) Add this to the end of httpd.conf:
<Directory />
AllowOverride none
Require all granted
</Directory>
3) Add this line to your hosts file in Windows directory
127.0.0.1 ikeen.localhost
4) Finally, this is the step that is missing from all the solutions. Add this to your httpd-ssl.conf, after the same section for your localhost (usually www.example.com), change example.com to your local settings for localhost, so that the whole section looks smth like this
<VirtualHost _default_:443>
# General setup for the virtual host
DocumentRoot "D:/xampp/htdocs"
#ServerName www.example.com:443
ServerName localhost
ServerAdmin admin#example.com
ErrorLog "D:/xampp/apache/logs/error.log"
TransferLog "D:/xampp/apache/logs/access.log"
# General setup for the ikeen host
DocumentRoot "D:/xampp/htdocs/ikeen"
#ServerName www.example.com:443
ServerName ikeen.localhost
ServerAdmin admin#example.com
ErrorLog "D:/xampp/apache/logs/error.log"
TransferLog "D:/xampp/apache/logs/access.log"
I had the same issue. Problem was solved by removing the standard virtual host entry and i wasn't redirected to the root directory.
Just remove these lines of code:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "D:\xampp\htdocs"
<Directory "D:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
If the case does not work, maybe change httpd-ssl.conf
My 3 sites worked, localhost, test1.com, test2.com
#
<VirtualHost _default_:443>
DocumentRoot "c:/xampp/htdocs"
ServerName localhost
ServerAdmin admin#example.com
ErrorLog "c:/xampp/apache/logs/error.log"
TransferLog "c:/xampp/apache/logs/access.log"
...
</VirtualHost>
#test1
<VirtualHost _default_:443>
DocumentRoot "c:/xampp/htdocs/test1"
ServerName test1.com
ServerAdmin admin#example.com
ErrorLog "c:/xampp/apache/logs/error.log"
TransferLog "c:/xampp/apache/logs/access.log"
...
</VirtualHost>
#test2
<VirtualHost _default_:443>
DocumentRoot "c:/xampp/htdocs/test2"
ServerName test1.com
ServerAdmin admin#example.com
ErrorLog "c:/xampp/apache/logs/error.log"
TransferLog "c:/xampp/apache/logs/access.log"
...
</VirtualHost>

Configuring localhost and virtalhost redirecting in dashboard with lampp

I'm attempting to configure a virtualhost to a subdirectory into /opt/lampp/htdocs. This is the httpd-vhost.conf file:
NameVirtualHost *:80
<VirtualHost localhost:80>
ServerAdmin localhost
DocumentRoot /opt/lampp/htdocs
ServerName localhost
<Directory /opt/lampp/htdocs>
Options All
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.localhostwmf.com
ServerAlias localhostwmf.com
DocumentRoot /opt/lampp/htdocs/wmf
DirectoryIndex index.php
<Directory /opt/lampp/htdocs/wmf>
Options All
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
I uncommented this line in httpd.conf:
Include etc/extra/httpd-vhosts.conf
And i added the following line in etc/hosts:
127.0.0.1 www.localhostwmf.com
But it redirects me always in the dashboard page of xampp! Thank you in advance for answers!
I solved this morning the problem, i hope that this solution will be useful for another one:
I modified my httpd-vhosts.conf file as follows:
NameVirtualHost *:80
<VirtualHost localhost:80>
ServerAdmin localhost
DocumentRoot /opt/lampp/htdocs/wmf
ServerName localhost
<Directory /opt/lampp/htdocs>
Options All
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.localhostwmf.com
ServerAlias localhostwmf.com
DocumentRoot /opt/lampp/htdocs/wmf
DirectoryIndex index.php
<Directory /opt/lampp/htdocs/wmf>
Options All
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
(i added wmf folder in localhost document root)

avoid redirecting all folder as hostname in wamp

I have created two one virtual host and other are normal folder.my virtual host name is testVirtualHost.Along with this I have other folder as'trial','learn'.
other folder are also redirect as http:/learn instead of localhost/learn and vice versa.I have given below my virtual host code in 'httpd-vhosts.conf'.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
<Directory "c:/wamp/www">
AllowOverride All
#Options Indexes FollowSymLinks
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:\wamp\www\testVirtualHost"
ServerName testVirtualHost
ServerAlias testVirtualHost
</VirtualHost>

Server name on virtual host not working

please i need your help. I am working on a zend framework 2 project, the project's name in Wamp/www folder is pizza.
i tried to configure a virtual host on hosts file,httpd.conf and httpd-vhosts.conf to work with this project url: pizza.local/
instead of this: localhost:8080/pizza/public/
but something is not ght with my configuration.
note that I am using localhost:8080 not localhost.
Please help me to find what I did wrong. Here's my files:
httpd.conf:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
httpd-vhosts.conf:
<VirtualHost *:8080>
ServerAdmin webmaster#localhost.com
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias www.localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "c:/wamp/www/pizza/public"
ServerName pizza.local
<Directory "c:/wamp/www/pizza/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
hosts file:
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 pizza.local
127.0.0.1 localhost
As you are using this VHOST on port 8080. You need to mention in URL as below.
http://pizza.local:8080/

PHP will not run in Virtual Hosts in apache

I cannot get PHP scripts to run in my Virtual Hosts. It works fine on the default host, but will not run in any other hosts. I've tried everything I could find on the web. Mac 10.8 Server.
#/private/etc/apache2/extra/httpd-vhosts.conf
Listen 80
Listen 8080
Listen 8010
NameVirtualHost *:80
NameVirtualHost *:8080
NameVirtualHost *:8010
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "/Library/Server/Web/Data/Sites/Gradschool"
ServerName gradschool.local
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/Library/Server/Web/Data/Sites/PMST"
ServerName PMST.local
</VirtualHost>
<VirtualHost *:8010>
DocumentRoot /library/server/web/data/sites/test
ServerName test.local
</VirtualHost>
PHP could be disabled for the virtual hosts. Try enabling it with "php_admin_flag engine on":
<VirtualHost *:80>
DocumentRoot "/Library/Server/Web/Data/Sites/Gradschool"
ServerName gradschool.local
<Directory /Library/Server/Web/Data/Sites/Gradschool>
php_admin_flag engine on
AllowOverride AuthConfig FileInfo
Order allow,deny
allow from all
</Directory>
</VirtualHost>

Categories