Virtual host - Not Found - apache

I wolud like to use virtual host on Apache 2.4
I use Xampp and I will have more site so on it.
I have already read some guide and I have edit my httpd.config
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
and the Load
also my defalut port in busy, so I have set
Listen 8080
After that I edit my httpd-vhosts.conf in this way
NameVirtualHost *:8080
<VirtualHost *:8080>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:8080>
ServerName sample.locl
DocumentRoot "C:\wwww\sample"
<Directory "C:\wwww\sample">
DirectoryIndex index.php
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8080>
ServerName sample2.locl
DocumentRoot "C:\wwww\sample2"
<Directory "C:\wwww\sample2">
DirectoryIndex index.php
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
N.B. my site is in C:/www/sample and c:/www/sample2 and my xampp in in c:/xampp.
At the end I edit my host in system32 with
127.0.0.1 localhost
127.0.0.1 sample
127.0.0.1 sample2
Now I have 404 error, neither when I wrote: "localhost" in my url browser.
If i Understand how it work I suppose that when i write localhost it will be redirect to C:\xampp\htdocs and so I should see my xampp page but it's not so.. where did I go wrong?
I always recive
Not Found
HTTP Error 404. The requested resource is not found.
thanks in advance

Related

XAMPP virtualhost site with all configs not working

I am trying to run site my.com locally on XAMPP's apache server. Here my configurations in httpd-vhosts.conf file in the path ...\XAMPP\apache\conf\extra:
<VirtualHost *:80>
DocumentRoot "D:/IDEs/XAMPP/htdocs"
ServerName localhost
<Directory "D:/IDEs/XAMPP/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Also, I remembered to add two lines in the hosts file, with is located in C:\Windows\System32\drivers\etc:
127.0.0.1 localhost
127.0.0.1 my.com
However, when I enter via link 'my.com' with enabled apache server, I've got only page with folder directories, which are in htdocs XAMPP's folder.
I have checked a lot of videos and stackoverflow questions, but nothing helped.
I would be pleased if you could help me with solving this issue.
first you should arrange directories on httpd.conf
example:
<Directory "C:/SERVER~1/web/site1">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "C:/SERVER~1/web/site2">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and then arrange vhosts.conf like this
example :
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName www.site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
After five days-night of reading, searching, trying, I finnally fould the solution and done it in some steps:
First of all, forget about every file, and concentrate on the httpd-ssl.conf which is located in D:\IDEs\XAMPP\apache\conf\extra.
Second:
find the line "SSL Virtual Host Context" which has been commented. And below, find the line <VirtualHost _default_:443>.or simmilar. Then change it to <VirtualHost *:443>.
Third, change document root to the path of xampp's htdocs, for example, "D:/XAMPP/htdocs". Also, change ServerName from www.example.com:443 or similar, to localhost.
Here we done.
And Finally, after line </VirtualHost>, insert code
<VirtualHost *:443>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Require all granted
</Directory>
</VirtualHost>
Change Document Root and Directory paths to your website location. And Servername to your server name.
RESTART APACHE
it works for me.
I also understood than some website uses SSL on localhost while the others not.
SO if you have exception like Apache/2.4.37 (Win32) OpenSSL/1.0.2p PHP/7.0.33 Server at my.com Port 443 you shold add your virtualhost configs into httpd-ssl.conf file.
If you got like ... Port 80 add yourl virtualhost configs into httpd-vhosts.conf

Wamp is Green and Online but still 403 error

C:\wamp\bin\apache\apache2.4.9:
<VirtualHost *:80>
DocumentRoot C:\wamp\wwww\sk\public
ServerName sk.localhost
SetEnv APPLICATION_ENV "development"
<Directory "C:\wamp\wwww\sk\public">
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
Require local
Allow from localhost ::1 127.0.0.1
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:\wamp\wwww\sk\public
ServerName sk.localhost
SetEnv APPLICATION_ENV "development"
<Directory "C:\wamp\wwww\sk\public">
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
Require local
Allow from localhost ::1 127.0.0.1
</Directory>
</VirtualHost>
Hosts file:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 sk.localhost
When I try to access localhost or sk.localhost it gives me 403 error (Wamp is green and Online. Anyone can help please? I don`t know what am I doing wrong here. I tried several methods from Internet but with no luck. Any help would be much appreciated. Best regards, Bogdan.
PHPMyadmin is working.
This is probably because you are using 2 different versions of the access security syntax and Apache is getting confused.
Change your Virtual Host definitions as below to use just the Apache 2.4 syntax and not the Apache 2.2 ones.
Also you should create a VH for localhost as well, as when you implement Virtual Hosts, Apache ignores the definition of localhost in the httpd.conf file.
# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
<Directory "c:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:\wamp\wwww\sk\public
ServerName sk.localhost
SetEnv APPLICATION_ENV "development"
<Directory "C:\wamp\wwww\sk\public">
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:\wamp\wwww\sk\public
ServerName sk.localhost
SetEnv APPLICATION_ENV "development"
<Directory "C:\wamp\wwww\sk\public">
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Require local
</Directory>
</VirtualHost>
The Require local tells Apache to only allow access to a VH domain if the client is on the PC running WampServer(Apache).
If you actually want to allow access from say another PC on your local network, you can add a line like this to the domain you want to access
Require local
Require ip 192.168.1
Or if you want to allow access from anwhere replace those lines with
Require all granted
WARNING Dont allow access to the universe unless you really know what you are doing.
PS The WAMPserver Online/Offline feature only controls access and does not mean APache is running or not. Also once you implement Virtual Hosts it no longer has any relevance and shoudl be set OFFLINE as access control is now held in each individual Virtual Host.

Setting a ServerName in the VirtualHost of Apache server is not working

I have tried to create a new Virtual Host in my Apache server, but I cannot address it by its new ServerName "mysite.game".
Can you spot any mistake in my code, please?
OUTPUT
What happens is that the URL http://localhost:8081/ is displaying the right website directory, while "http://mysite.game" is giving the same error HTTP Error 404.
INPUT
This is what i have done.
In C:\Windows\System32\drivers\etc\hosts, i inserted the line:
127.0.0.1 mysite.game
In http.conf I added:
Listen 0.0.0.0:8081
Listen [::0]:8081
and
<Directory "C:\game">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
In httpd-vhosts.conf, I added:
NameVirtualHost *:8081
<VirtualHost *:8081>
DocumentRoot "C:\game"
ServerName mysite.game
<Directory "C:\game">
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>

localhost redirecting to path specified for sub domain

In cakephp, I want to redirect localhost to app2 and client1.localhost to app1.
Instead both are redirecting to app1.
my httpd-vhost is defined as:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "D:\wamp\www\cakephp\app2\webroot\
ServerName localhost
</VirtualHost>
<VirtualHost www.myhost>
DocumentRoot "D:\wamp\app1\webroot"
ServerName client1.localhost
ServerAlias client1.localhost
<Directory "D:\wamp\app1\webroot">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
At first glance there are a few weird things with your vhost config:
The first document root has no closing "
the virtualhost names should both be the same
your referring to the webroot, instead of the approot (there's also a .htacces in your approot)
I use CakePHP 2.x with wamp server with a configuration like this:
make sure the vhost file is uncommented in your apache configuration:
wamp/bin/apache/Apache[version]/conf/httpd.conf (or left click wamp->apache->httpd.conf)
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Try this in wamp/bin/apache/Apache[version]/conf/extra/httpd-vhosts.conf
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# 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>
ServerName client1.localhost
DocumentRoot "D:\wamp\app1"
<Directory "D:\wamp\app1">
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
<VirtualHost *:80>
ServerName dev.localhost
DocumentRoot "D:\wamp\www\cakephp\app2"
<Directory "D:\wamp\www\cakephp\app2">
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>
and put this in your hosts file (C:\windows\system32\drivers\etc)
127.0.0.1 localhost
127.0.0.1 dev.localhost
127.0.0.1 client1.localhost
Do a wamp restart all services.
App2 will be available on both localhost and dev.localhost

Windows 7 - XAMPP: vhost keeps redirecting

My hosts file. (Win 7 ultimate)
127.0.0.1 localhost
127.0.0.1 efmm.local
My httpd-vhosts.conf (XAMPP 1.7.3)
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost efmm.local>
DocumentRoot "C:\xampp\htdocs\EFMM"
ServerName efmm.local
ErrorLog "logs/efmm.localhost-error.log"
CustomLog "logs/efmm.localhost-access.log" combined
<Directory "C:\xampp\htdocs\EFMM">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Problem
When I go to efmm.local , the browser redirects to localhost/EFMM.
I also tried <VirtualHost 127.0.0.1:80> instead of <VirtualHost efmm.local>, same result.
Here's how I do it on XP (don't expect it to make any difference in 7)
First, add the virtual host's domain to your HOST (as you did)
I don't put the virtual host webroot under the main htdocs directory. I create a specific webroot next to it, which gives me the following tree:
C:\XAMPP\htdocs
C:\XAMPP\htdocs-seconddomain
C:\XAMPP\htdocs-thirddomain
etc..
So in your case, I would create c:\XAMPP\htdocs-efmm alongside C:\XAMPP\htdocs
Then:
Edit XAMPP's httpd.conf, add and define any Apache options for the new document root, i.e.:
<Directory "C:/XAMPP/htdocs-efmm">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
[any extra apache module instructions you may require]
Order allow,deny
Allow from all
</Directory>
Edit XAMPP's httpd-vhosts.conf, adding the virtual host:
<VirtualHost *:80>
ServerName efmm.local
ServerAlias www.efmm.local
DocumentRoot "C:/XAMPP/htdocs-efmm"
ErrorLog "C:/XAMPP/htdocs-efmm/error.log"
DirectoryIndex index.php index.html index.htm
</VirtualHost>
Restart XAMPP. You may browse your new virtual host now.