Jan 3, 2015 |
Comments Off on Full guideline to make VHOST (Virtual Host) on XAMPP/WAMP

Note: To start with, the only difference for this guideline, between XAMPP and WAMP or other Apache packages for Windows, is question where those packages are installed on your computer.

Introduction: vhost (virtual host) is a great solution if you intend to develop many independent project in php and keep them isolated from each others, like:

Project 1 is based on php and has local url address php.localhost

Project 2 is a Laravel project with url laravel.localhost

Project 3 is a Codeigniter with url codeigniter.locathost

Project 4 is a WordPress with url wordpress.locathost

You are expected to have installed the latest version of XAMPP/WAMP. Btw, in my case, I have only installed Apache and MySQL.

*Note: By default, most web servers will uses port 80 as default port, in some situation if you have another web server installed like (Microsoft IIS), it uses port 80 as well OR in other cases SKYPE does also some times use port 80 like it is the case for some in Windows 8/10 for some users, in that case you can do two thing’s

Change your Apache port to port 8080, 8081 etc. or some other free ports (note: 8080 can some times also give some problems)

OR Change your others software/IIS port and keep Apache to default port 80 in case of Skype, just kill the Skype app and restart it after installing Apache on port 80, Skype will automatically get new port.

I have chosen to change my Apache to port 8080.

Note:
– For next section, we need to use text editor like notepad or regular IDE. I used sublime text editor.
– If you keep Apache to default port 80, skip this part and move on to Virtual hosts

Click on Config -> Apache (httpd.conf)
Or you find the file here C:XAMPPapacheconfhttpd.conf, C:XAMPPapache2confhttpd.conf, C:Bitnamiwampstackapacheconfhttpd.conf or C:Bitnamiwampstackapache2confhttpd.conf or similar location.

Change the line with

Listen 80

To 8080 or other, free ports.

Listen 8080

While we have httpd.conf file open we need to ensure that httpd-vhosts.conf is included:
Include conf/extra/httpd-vhosts.conf

Virtual hosts

Note: By default server documents are locate on C:XAMPPhtdocs or C:Bitnamiwampstackapache2htdocs that’s fine if you have only one project or many small test files. However, if you need to develop many projects then it suggested separating them by virtual host, as mentioned earlier.

Step 2. Setting Virtual host

Create a folder for your projects; I have create one in c:vhost you can call it projects etc.

In c:vhost folder we create a sub-folder domain1 or project1 or any other, it is up to you (c:vhostproject1)

Open httpd-vhosts.conf file C:XAMPPapacheconfextrahttpd-vhosts.conf Add following code in line depending on how many vhost you want to create:

Note: If you work on Laravel projects you can create unlimited Laravel projects as well as other frameworks like codeigniter, Yii, etc., the point is to
have your Laravel project/s on c:vhostlaravel1,c:vhostlaravel2 etc and make c:vhostlaravel1public as
DocumentRoot etc as showed before. Each Laravel project will have own
VirtualHost URL.

Save and close the file

Some additional information and notes:

If port is remain default 80 then the URL address will be localhost

If port is remain default 80 then the the VirtualHost tag should be changed to <VirtualHost *:80>

If port is changed to 8080, the URL address will be localhost:8080

And the vhost URL address could look like this project1.localhost:8080 etc

You can add unlimited projects and virtual host like this way.

We are not ready yet, read more.

Step 3. Edit Windows Host file

Stop Apache and MySQL services from XAMPP/WAMP.

Open hosts file in C:windowssystem32driversetc
you need Administrator privilege to edit the file.
I suggest to edit the file directly with Sublime text editor.

Add 127.0.0.1 project1.localhost at the end of the file, Save and close the file.