Wamp directories not working after enabling virtual host - php

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

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>

Setting up virtual host on windows condeignitor

I am trying to set up the virtual host for my app written in Codeignitor. Here is what I am doing
In my config.php file in codeignitor I do this
$config['base_url'] = 'http://app.com';
Then in my hosts file I do this
127.0.0.1 www.myapp.com
127.0.0.1 api.myapp.com
127.0.0.1 files.myapp.com
Then in my vhosts file I add this code
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "C:\xampp\htdocs\
ServerName localhost
</VirtualHost>
<VirtualHost www.myapp>
DocumentRoot "C:\xampp\htdocs\myApp"
ServerName myapp.com
ServerAlias myapp.com
<Directory "C:\xampp\htdocs\myApp">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I type http://www.myapp.com/ in my browser it gives me Access forbidden! error. Can I get some headers?
Now it works. I a had to add .com in the VH files.

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>

Wamp : You don't have permission to access file.html on this server

I tried to create a virtualhost to access to my local website using wampserver, but i get a 403 Forbidden when i'm trying to access to the webpage :
I put the following line in my browser :
mywebsite/html/start.html
Here is the content of my httpd-vhost file :
<VirtualHost *:80>
ServerName mywebsite
DocumentRoot "D:\pathToMySite"
<Directory "D:\pathToMySite">
AllowOverride All
Allow from all
Require all granted
</Directory>
</VirtualHost>
I put the alias also in my host file :
127.0.0.1 mywebsite
I will share my httpd.conf for AMPPS under windows(should be very similar to wamp)
<VirtualHost 127.0.0.1:80>
<Directory "{$path}/www">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName localhost
ServerAlias localhost 127.0.0.1
ScriptAlias /cgi-bin/ "{$path}/www/cgi-bin/"
DocumentRoot "{$path}/www"
ErrorLog "{$path}/apache/logs/error.log"
CustomLog "{$path}/apache/logs/access.log" combined
</VirtualHost>
<VirtualHost *:80>
<Directory "F:/www">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
DocumentRoot "F:/www"
ServerName site1.com
</VirtualHost>
I also use host file for local DNS
127.0.0.1 site1.com
hope that helps !

Categories