So I have a virtual host setup that is working but it is an internal server so we have no domain name for it. So under my server name I just have the IP Address and it works fine, however now I need to setup a subdomain and apache doesn't seem to be cooperating. Below essentially what I am trying to do but with the IP address removed. Any idea how this can be done?
<VirtualHost *:80>
ServerName 111.111.111.111
DocumentRoot "/var/www/laravel/public"
<Directory "/var/www/laravel/public">
AllowOverride all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName payment.111.111.111.11
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
AllowOverride all
</Directory>
</VirtualHost>
A good way to achieve this is by using a different port:
<VirtualHost *:80>
ServerName 111.111.111.111
DocumentRoot "/var/www/laravel/public"
<Directory "/var/www/laravel/public/">
AllowOverride all
</Directory>
</VirtualHost>
Listen 8000
<VirtualHost *:8000>
ServerName 111.111.111.111
DocumentRoot "/var/www/html"
<Directory "/var/www/html/">
AllowOverride all
</Directory>
</VirtualHost>
I set the port 8000 as an example, in order to avoid side effects by using "reserved ports" you might check this list, so you can choose any unassigned one.
Don't forget to add the
Listen 8000
directive so the webserver attends for connections on that specific port, and also, it is convenient to add the trailing backslash within the tag:
<Directory "/var/www/html/">
Related
I'm running xampp on Linux and want to set up virtual hosts, so I can quickly jump between projects.
I have two projects set up like this:
/home/(user)/webdev/app1 which contains an index.html
/home/(user)/webdev/app2 which contains an index.html
My httpd.conf includes these snippets:
<Directory "/home/(user)/webdev/app1">
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride All
Require all granted
</Directory>
<Directory "/home/(user)/webdev/app2">
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride All
Require all granted
</Directory>
and Include etc/extra/httpd-vhosts.conf is uncommented.
My httpd-vhosts.conf includes this:
<VirtualHost *:80>
ServerAdmin webmaster#webdev.app1
DocumentRoot "/home/(user)/webdev/app1"
ServerName webdev.app1
ErrorLog "logs/app1.example.com-error_log"
CustomLog "logs/app1.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#webdev.app2
DocumentRoot "/home/(user)/webdev/app2"
ServerName webdev.app2
ErrorLog "logs/app2.example.com-error_log"
CustomLog "logs/app2.example.com-access_log" common
</VirtualHost>
And my /etc/hosts file looks like this:
127.0.0.1 localhost
::1 localhost
127.0.0.1 webdev.app1
127.0.0.1 webdev.app2
To my understanding, I did everything right. Unfortunately, when I go to webev.app1 or webdev.app2, it serves the regular htdocs folder instead of the modified DocumentRoot. When I go to localhost, it serves whatever is named first in httpd-vhost.conf, in this case /home/(user)/webdev/app1.
The behavior I expect would be that app1 is served when I visit webdev.app1 and app2 is served when I visit webdev.app2. What am I missing?
Your virtual hosts are set up incorrectly, you are telling Apache that if any request comes in on port 80 serve app1 and at the same time if any request comes in on port 80 serve app2. Fix it using one of the examples below:
----------START DIFFERENTIATE VIA DIFFERENT DOMAINS----------------
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/app1"
ServerName www.app1.com
ServerAlias *.app1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/app2"
ServerName www.app2.com
ServerAlias *.app2.com
# Other directives here
</VirtualHost>
----------END DIFFERENTIATE VIA DIFFERENT DOMAINS----------------
----------START DIFFERENTIATE VIA SUB FOLDERS----------------
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/apps"
# in the 'apps' folder place subfolders 'app1' and 'app2'
# navigate in the browser to each app i.e. 127.0.0.1/apps/app1 and 127.0.0.1/apps/app2
# Other directives here
</VirtualHost>
----------END DIFFERENTIATE VIA SUB FOLDERS----------------
----------START DIFFERENTIATE VIA DIFFERENT PORTS----------------
Listen 81
Listen 82
<VirtualHost *:81>
DocumentRoot "/www/app1"
# Other directives here
</VirtualHost>
<VirtualHost *:82>
DocumentRoot "/www/app2"
# Other directives here
</VirtualHost>
----------END DIFFERENTIATE VIA DIFFERENT PORTS----------------
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>
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.
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
I would like Apache to serve documents from c:/Apache24/htdocs and d:/www resp on my Windows local machine. In httpd-vhosts.conf I'm trying:
<VirtualHost *:80>
DocumentRoot "c:/Apache24/htdocs"
ServerName test.localhost
Options Indexes FollowSymLinks
<Directory "D:/www">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
and in hosts
127.0.0.1 test.localhost
but browsing to http://test.localhost results in a list of directories under C:/htdocs being displayed?
Am I getting any closer with this:
Alias c:/Apache24/htdocs D:/www
<Directory c:/Apache24/htdocs>
Require all granted
</Directory>
If so, where do I add it? N.B. I want to store and serve web documents from D:/ since C:/ is getting rather full now.
check you have row: NameVirtualHost *:80 before your virtual host. That should usually be there already, but check it.
Change your host to point just into one folder like:
<VirtualHost *:80>
DocumentRoot "D:/www"
ServerName localserver
Options Indexes FollowSymLinks
<Directory "D:/www">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
Create symbolic link from your c:/Apache24/htdocs to for example D:/www/apache folder.
Then you can access to your c:/Apache24/htdocs folder from url:
localserver/apache
Read more about symlinks:
http://en.wikipedia.org/wiki/NTFS_symbolic_link
Another option is to create two urls (domains) and virtualhosts like (add this after above):
<VirtualHost *:80>
DocumentRoot "c:/Apache24/htdocs"
ServerName other.localserver
Options Indexes FollowSymLinks
<Directory "c:/Apache24/htdocs">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
and in your hosts:
127.0.0.1 localserver other.localserver
On Windows 7 with WAMP installed on C:\Apache24 and serving documents out of C:\Apache24\htdocs you may want to serve documents from the D drive instead, since C is getting full. Go to: C:\Apache24\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "D:/www/apache/site1"
ServerName site1.dev
<Directory "D:/www/apache/site1">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/www/apache/site2"
ServerName site2.dev
<Directory "D:/www/apache/site2">
Options Indexes MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
And edit: C:\Windows\System32\drivers\etc\hosts
127.0.0.1 site1.dev
127.0.0.1 site2.dev
You should now be able to serve (locally) you're web documents from D:\www\apache with no need for sym links.