I want to create a virtual host for my application i got some tutorials of how to setup a virtual host but still i am having issues with it, first i create a new file in the /etc/apache2/sites-avalable/popinbay.dev This is the popinbay.dev file please note that i am using ubuntu 14.04
<VirtualHost *:80>
ServerAdmin udemesamuel256#gmail.com
ServerName popibay.dev
DocumentRoot /var/www/laravel4
</VirtualHost>
then i edited the /etc/hosts and added this line
127.0.0.1 popibay.dev
then i did a sudo service apache2 reload based on this tutorial virtual host in ubuntu not work
But the problem is it still goes to the default localhost page instaed of the laravel4 page.
You are using a "Name-based Virtual Hosts".
From Apache docs on Using Name-based Virtual Hosts:
To use name-based virtual hosting, you must designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHost directive. In the normal case where any and all IP addresses on the server should be used, you can use * as the argument to NameVirtualHost.
Try add NameVirtualHost *:80 to the top of your configuration, then restart your apache. E.g.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin udemesamuel256#gmail.com
ServerName popibay.dev
DocumentRoot /var/www/laravel4
</VirtualHost>
Note that you might need to change your DocumentRoot to /var/www/laravel4/public. That's where your http server should point to by default in Laravel projects.
You added virtual host file in sites-available folder but didn't Enabled it.
Use
sudo a2ensite virtuatl_host.conf
In your case,
sudo a2ensite popibay.dev.conf
And then,
sudo service apache2 reload
Related
may I ask question about the Apache Virtual Host config?
I use XAMPP, and my ipv4 is 192.168.1.7
I have configured my host file (C:\Windows\System32\drivers\etc...) like
127.0.0.1 g4.org
192.168.1.7 g4.org
and C:\xampp\apache\conf\extra\httpd-vhosts.conf like
NameVirtualHost 192.168.1.7:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/rs"
ServerName g4.org
ServerAlias www.g4.org
</VirtualHost>
The virtualhost works perfectly on the machine that has installed xampp .
but the problem is in the another machine(PC) [SAME LAN] if i go to http://192.168.1.7 the page load and work perfectly
but
if i go to this link http://g4.org the page won't load and say
ERR_CONNECTION_REFUSED
In the another machine, just put the "192.168.1.7 g4.org" at the host file.
I have started working in laravel and using lampp. I have watched many tutorials that use a vhost to make user-friendly url. I want to do it on Ubuntu 16.04.
Following tutorial is not working for me:
https://ourcodeworld.com/articles/read/302/how-to-setup-a-virtual-host-locally-with-xampp-in-ubuntu
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
ServerName mywebsite.dev
</VirtualHost>
Setup a virtual host for a Laravel project
First, copy the default configuration file and rename it:
$sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myVhost
open myVhost.conf file using this command:
$sudo nano /etc/apache2/sites-available/myVhost.conf
Add the directives:
assuming that the Laravel project is in /var/www/html/
ServerAdmin webmaster#localhost
serverName www.myAwesomeLink.com
DocumentRoot /var/www/html/laravel-app/public
<Directory /var/www/html/laravel-app>
AllowOverride All
</Directory>
so now the file will look something like this:
save and close.
Now add an entry in the hosts file:
$sudo nano /etc/hosts
add this line:
127.0.0.1 www.myAwesomeLink.com
save and close.
Enable site and the rewrite mode:
$sudo a2enmod rewrite
$sudo a2ensite myVhost.conf
Restart the server:
$sudo service apache2 restart
Serve the Laravel project:
open the project folder
php artisan serve
this will serve on port 8000 by default
you can also specify the port
php artisan serve --port=4200
Open the browser:
http://www.myAwesomeLink.com:8000
or any other specified port.
Source.
Its not working because the browsers have updated their security terms and policies including SSL certificates over .dev domains. just change your extension from .dev to something else like .localhost or .test.
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
ServerName dev.mywebsite.test
</VirtualHost>
Also change the extension in /etc/hosts from .dev to .test.
127.0.0.1 dev.mywebsite.test
Also keep in mind to restart the service to load the new added virtual host i.e: restart the Apache server
Hope it helps.
I think you also need to add a host in /etc/hosts. Open the hosts file and add this line:
127.0.0.1 mywebsite.dev
You will need to restart server after this.
1.Create new file under this path /etc/apache2/sites-available/myweb.conf
2.Copy the following to the file
# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /var/www/html/mywebsite/public
ServerName dev.mywebsite.test
<Directory "/var/www/html/mywebsite/public">
Options All
AllowOverride All
Allow from all
</Directory>
3.Run "sudo a2ensite myweb.conf"
4.Add this line "Listen 80" to file "/etc/apache2/ports.conf"
5.Restart apache server
I have installed vagrant and scotchbox from scotch.io to develop locally and is running like a charm.
Now I need use the subdomains as variable, and i have googled about, but still no working.
I have changed the hosts file and added
192.168.33.10 scotch.box
Is needed add a line for wildcard subdomain hosts?
Also I have added the next line to my conf file
<VirtualHost *:80>
DocumentRoot /var/www/public
ServerName tenant.scotch.box
ServerAlias *.scotch.box
</VirtualHost>
Sorry for my broken english.
Just add
192.168.33.10 tenant.scotch.box
to hosts.
I had the same problem a couple of months ago. On the hosting OS you have to edit the hosts file.
On Windows
C:\Windows\System32\drivers\etc\hosts
On linux
sudo nano /etc/hosts
you have then to add the ip-address of your scotch box with the desired host name
192.168.33.10 tenant.scotch.box
You can even add multiple lines to your hosts file if you have multiple subdomains or you are developing multiple web applications on the same scotch box. For example :
192.168.33.10 sub1.scotch.box
192.168.33.10 sub2.scotch.box
192.168.33.10 sub3.scotch.box
BUT don't forget to edit the virtual host file inside Scotch Box which is located /etc/apache2/sites-available/YOUR_CONFIG.conf
You will need a <VirtualHost *:80> </VirtualHost> for each sub domain. Example:
<VirtualHost *:80>
DocumentRoot /var/www/public
ServerName sub1.scotch.box
ServerAlias *.scotch.box
</VirtualHost>
I am using Windows 7 with Wamp 2.2 server.
I have setup 2 virtual hosts: www.project1.com and www.project2.com.
I have modified the "hosts", the httpd.conf, and the httpd-vhosts.conf files, to the changes I mentioned below.
Using my browser, when I type www.project1.com or www.project2.com, I successfully get my web pages opened on the laptop that has the server installed on.
Changes in the "hosts file": I've appended the followings to the end of the file:-
127.0.0.1 localhost
127.0.0.1 www.project2.com
127.0.0.1 www.project1.com
Changes in the httpd.conf file:-
Include conf/extra/httpd-vhosts.conf
Changes in httpd-vhosts file:-
NameVirtualHost *:80
<Directory "D:/websites/">
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost 127.0.0.1>
DocumentRoot "D:/websites/wamp/www/"
ServerName localhost
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "D:/websites/project1/"
ServerName www.project1.com
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "D:/websites/project2/"
ServerName www.project2.com
</VirtualHost>
Now; since I can open these web pages from a browser in PC_1 (the one with the server), how can I access these web pages from a browser in PC_2? (I mean any PC connected to PC_1 via LAN.)
In addition to danp's answer, you can access the virtual host without having to change the client machine's etc/hosts file by assigning a port to the virtual host. This is ideal if you want to access the server with a mobile or tablet device:
Edit server's httpd.conf file at:
\wamp\bin\apache\apache2.2.x\conf\httpd.conf
Search for "Listen" (around line 61). You should see the following that allows for Apache to listen for port 80:
Listen 0.0.0.0:80
Listen [::0]:80
Add the following lines to add listening for port 81 (or any port):
Listen 0.0.0.0:81
Listen [::0]:81
Edit the httpd-vhosts.conf file at:
\wamp\bin\apache\apache2.2.x\conf\extra\httpd-vhosts.conf
Change your "Virtual Host" tag to port 81:
<VirtualHost *:81>
DocumentRoot "D:/websites/project1/"
ServerName www.project1.com
</VirtualHost>
Restart Apache server.
On the client machine/tablet/mobile, on the web browser, enter the server's IP address (192.168.0.10, or whatever IP) followed by the port number in the following format:
http://192.168.0.10:81
In your virtualhost directive, change 127.0.0.1 to *:80 and as Gabriel mentioned, add an entry to the hosts file in the other machine, adding your domain to be associated with the IP of your server.
When you put an explicit IP into the directive, apache will only listen on that IP - but the wildcard will tell it bind to all IPs available to it.
<VirtualHost *:80>
DocumentRoot "D:/websites/project1/"
ServerName www.project1.com
</VirtualHost>
If your server is on 192.168.1.70 for example, then in the other machines on your lan, the hosts entry will look like:
192.168.1.70 www.project1.com
Restart apache and it should work fine.
As a note, when you are using virtualhosts, apache will use the first definition as a default for when it can't make a match between the domain passed in the HTTP request header and the sites setup in the config, which is why your default page was appearing.
You told apache to bind to all IPs with the NameVirtualHost *:80 directive, but then didn't setup a site for that external IP. Hope that helps!
There are two computer in local network.
A computer(192.168.1.70) Setup(D:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf):
<VirtualHost *:80>
DocumentRoot "D:/websites/project1/"
ServerName www.project1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/websites/project2/"
ServerName www.project2.com
</VirtualHost>
B computer Setup(c:/windows/system32/drives/etc/hosts):
192.168.1.70 www.project1.com
192.168.1.70 www.project2.com
B access A,My project is working.
A couple of updated points to consider for the selected answer:
NameVirtualHost is no longer used after Apache version
2.3.11 and can be omitted.
In 2.3.11 and later, any time an IP address and port combination is
used in multiple virtual hosts, name-based virtual hosting is
automatically enabled for that address.
Because we are talking about hosting a website over LAN, let's set a
requirement* to only accept connections from IP addresses on your
local network. For example, on a common Linksys router, the default
IP assigned to each device on the network is between 192.168.1.100
to 192.168.1.255. You can allow connection from all devices on the
LAN with an IP address 192.168.1.XXX by using Require ip 192.168.1
(notice the final octet is left off the IP to allow the entire
range).
This allows you to configure access per project so that one may be
available over LAN and another is only available locally.
# This will allow all LAN connections to www.project1.com
<VirtualHost *:80>
DocumentRoot "D:/websites/project1/"
<Directory "D:/websites/project1/">
Require local
Require ip 192.168.1
</Directory>
ServerName www.project1.com
</VirtualHost>
# This will allow only the machine hosting the website to access www.project2.com
<VirtualHost *:80>
DocumentRoot "D:/websites/project2/"
<Directory "D:/websites/project2/">
Require local
</Directory>
ServerName www.project2.com
</VirtualHost>
While your site will not be served publicly without the router forwarding traffic on port 80 to your host, I believe this is considered best practice. It is especially necessary if you need to control which projects are available to devices on the LAN.
Reminder: Your host machine should be configured to use a static IP address
instead of being assigned one by your router's DHCP. Since we are
editing the hosts file of other devices to point to the server's IP,
we don't want it to change.
* I'm including this because it is common to have access restrictions on a local development server and you will need to specifically make it available to your local network.
You need to change the hosts file on the machine you're trying to view the page from.
So you need to add them to the hosts file on the other lan machine.
if you are not able to access your virtual host server in your local area network then check you have configured your firewall to allow httpd.exe file (lying in folder C:\wamp64\bin\apache\apache2.4.51\bin) to allow both incoming and outgoing connections
I am trying to setup my dev machine with virtual hosts so I can access my development projects with a simple url, like http:// project.dev/ rather that a whole http:// 127.0.0.1/dev/path/to/root/of/project/ type of url.
Now, I'm aware there are many tutorials and questions already answered about this, but after trying many of them, I feel like I'm running in circles here.
The problem is simple: after setting up my hosts file and my virtual hosts, any attempt to access a virtual hosts irremediably displays the content of my server DocumentRoot.
my hosts file:
127.0.0.1 localhost
127.0.0.1 mydomain.dev
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
my httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/pilot/Sites/
</Virtualhost>
<VirtualHost *:80>
ServerName mydomain.dev
DocumentRoot /Users/pilot/Sites/devel/vytamin/dev/
</VirtualHost>
I precise that the httpd-vhosts.conf file IS loaded in my httpd.conf and I do get a warning if I point the virtual host document root to a wrong folder.
I made a try setting the localhost virtual host to the following, without any success.
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/pilot/Sites/devel
</Virtualhost>
The following URLS all display the DocumentRoot of my server defined in my httpd.conf file, and seem to ignore the DocumentRoot defined in my VirtualHosts.
http:// 127.0.0.1/
http:// localhost/
http:// mydomain.dev/
I'm running Apache2.2 on Mac OSX 10.5 Leopard, but not the one shipped with mac os. I compiled my own under /usr/local/apache2 and web sharing IS disabled
I can't see anything wrong with my set up so I hope the community will!
Thanks for your help!
Ok, I found the problem!
The configuration above is perfectly fine, it was just that my apache was not restarting properly.
Neither apache_ctl graceful or apache_ctl restart was terminating all httpd processes I have running, therefore failing to reload properly the changes in my configuration files.
Once I killed the remaining processes and really restarted apache, it worked...
Solved, but I feel dumb to have found that!
Now I have a daemon situation to solve!