Virtual host not working on XAMPP, something very strange happenning - php

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>

Related

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)

Wamp directories not working after enabling virtual host

I have created a virtual host for a new application in wamp.
In my httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf //<--- Removed #
In my httpd.vhosts.conf I added a new host
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:/wamp/www/myapp"
ServerName myapp.local
ServerAlias 127.0.0.1
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/myapp/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
</Directory>
</VirtualHost>
The virtual host is working fine. But the problem is my other apps that run without virtual hosts are not working.
When i open http://localhost/fistapp/ it shows
Forbidden 403
You don't have permission to access / on this server.
Once you create a Virtual Host definition Apache basically ignores the localhost domain defined in the httpd.conf file, so you have to also define locahost in the httpd-vhosts.conf file as well. So your httpd-vhosts.conf file should look like this :
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp/www
<Directory "c:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# made some amendments to this VH as well
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/myapp"
ServerName myapp.local
# not sure why this is here ServerAlias 127.0.0.1
ServerAlias www.myapp.local
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/myapp">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride all
Require local
</Directory>
</VirtualHost>
Dont forget to amend the C:\windows\system32\drivers\etc\hosts file to add your new domain like this
127.0.0.1 localhost
::1 localhost
127.0.0.1 myapp.local
::1 myapp.local

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>

apache2 rewrite page not found

Ive just completed the setup of apache.
Setup looks as follow:
my virtualhost:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName system.local
ServerAlias www.system.local
DocumentRoot /var/www/system
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
My hosts file is:
127.0.1.1 system.local
I have also used a2enmod to enable mod_rewrite.
When i open my application and for instance go to /Admins/index i get a page not found.
Does anyone know what i might be missing?
If you are using an .htaccess file. You need to allow the use of an .htaccess file in your web directory using AllowOverride All. For that your code should look like this.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName learningbank.local
ServerAlias www.learningbank.local
DocumentRoot /var/www/system_learningbank
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/system_learningbank>
AllowOverride All
</Directory>
</VirtualHost>
Also don't forget to restart apache when making config changes.

how to run multiple projects on Apache using Virtual Hosts?

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.

Categories