As i tried to configure my virtual host in apache. I put something like this,
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>
And in my hosts file i put something like this,
127.0.0.1 localhost
127.0.0.1 gift.loc
And i run it on the browser,
http://gift.loc - is fine
But when i tried using this,
http://localhost/othersite - can't found
Do i missed somehting to configure? ANy ideas...
Thanks in advance,
There are few steps you need to follow to setup the virtual host on ubuntu: Let say that your project folder name is myProject
Step 1:Place your folder inside /var/www/html
Step 2: Give ownership of project folder to www-data
Step 3:Create new site inside Sites available:
Here you will see existing 000-default.conf and default-ssl.conf .Copy the content of both file into one file and replace your folder name or copy this one into new file named myProject.conf
Include the path of self signed certificate also in this as shown ssl key and ssl certificate that can be downloaded easily.
Step 4:Add your project into apache configuration file.
put this lines in the file:
Step 5:Add your virtual server name (specified in myProject.conf) into host file.add that line:
Step 6:Now all set ,enable site,restart apache
Just hit project.com in your browser.
you need to put localhost in the vhosts.conf
This works fine (Make sure you restart apache). If you need to check your configuration you can (on linux at least) run httpd -S.
From the docs, it looks like we need to create a block for each different host that you would like to serve.
Further in the same doc, If you are adding virtual hosts to an existing web server, you must also create a block for the existing host.
You need a VirtualHost entry for every host you want apache to handle. The first one in the config file will be used as the default if no other VirtualHosts match the request.
For example if we have:
A request for foobar.org will get handled by the gift.loc virtual host.