This file is located at C:\MAMP\bin\apache\conf\extra\httpd-vhosts. conf .
##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:
php.localhost
laravel.localhost
codeigniter.localhost
wordpress.localhost
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
8080, 8081 etc. or some other free ports (note: 8080 can some times also give some problems)I have chosen to change my Apache to port 8080.
Note:
Change XAMPP/WAMP port (only if necessary) if left default, then jump to Setting virtual host
Step 1. Edit httpd.conf
Click on Config -> Apache (httpd.conf)
Or you find the file here C:\XAMPP\apache\conf\httpd.conf, C:\XAMPP\apache2\conf\httpd.conf, C:\Bitnami\wampstack\apache\conf\httpd.conf or C:\Bitnami\wampstack\apache2\conf\httpd.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
Note: By default server documents are locate on
C:\XAMPP\htdocsorC:\Bitnami\wampstack\apache2\htdocsthat’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
c:\vhost you can call it projects etc.c:\vhost folder we create a sub-folder domain1 or project1 or any other, it is up to you (c:\vhost\project1)httpd-vhosts.conf file C:\XAMPP\apache\conf\extra\httpd-vhosts.conf Add following code in line depending on how many vhost you want to create:<Directory C:/vhost>
AllowOverride All
Require all granted
</Directory>
#this is the default address of XAMPP
<VirtualHost *:8080>
DocumentRoot "C:/XAMPP/htdocs/"
ServerName localhost
</VirtualHost>
#this is the first vhost address in XAMPP
<VirtualHost *:8080>
DocumentRoot "C:/vhost/project1/"
ServerName php.localhost
SetEnv NS_ENV variable_value
</VirtualHost>
#this is the second vhost address in XAMPP for project like Laravel
<VirtualHost *:8080>
DocumentRoot "C:/vhost/Laravel-Blog/public"
ServerName laravel.localhost
</VirtualHost>
etc
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:\vhost\laravel1,c:\vhost\laravel2etc and makec:\vhost\laravel1\publicas DocumentRoot etc as showed before. Each Laravel project will have own VirtualHost URL.
Save and close the file
Some additional information and notes:
localhost
<VirtualHost *:80>
8080, the URL address will be localhost:8080
project1.localhost:8080 etcWe are not ready yet, read more.
Step 3. Edit Windows Host file
C:\windows\system32\drivers\etc
you need Administrator privilege to edit the file.
I suggest to edit the file directly with Sublime text editor.127.0.0.1 project1.localhost at the end of the file, Save and close the file.127.0.0.1 localhost
127.0.0.1 php.localhost
127.0.0.1 laravel.localhost
127.0.0.1 codeigniter.localhost
127.0.0.1 wordpress.localhost
127.0.0.1 laravel2.localhost
etc. those are just examples
save the file
Final Step. Start/Re-start your Apache and MySQL again.
Note: Under you development process you might face problem having cache on, because you can risk updating some thing in Laravel and it won't appear in your browser. Therefore you might need to disable php cache under development process in your local environment.
Open file php.ini under php folder in your Apache (XAMPP or WAMP) folder and
change opcache.enable to 0 so it looks like this:
[opcache]
zend_extension=php_opcache.dll
; Determines if Zend OPCache is enabled
opcache.enable=0
Addition (Alternative solution)
Important: The following solution is not suitable to test Restful Api, canvas, heavy solutions, etc.it might give you some headaches, I would suggest virtual host solution with port 80 as default.
It is possible to deploy temporary Virtual Server with out necessarily configuring XAMPP/WAMP Virtual Host, start CMD console and run following php command:
php -S localhost:8001 -t c:\vhost\Laravel-Project\public
c:\vhost\Laravel... path should be changed to whatever your project path.In your browser you need only to write
http://localhost:8001/
Note on 403 Access forbidden error
If you get a 403 Access forbidden error when you browse to your site, you may need to add this to your httpd.conf file:
<Directory path_to_dir>
AllowOverride none
Require all granted
</Directory>
You can make your localhost to point to different folders on different port numbers. Follow these simple steps:
Step 1: Make your apache to listen to multiple ports. Go to C:\xampp\apache\conf\httpd.conf and search for the key word Listen you can see something like this Listen 80. Now tell your apache to listen to multiple ports, replace that with below content
Step 2: Now go to “C:\xampp\apache\conf\extra\httpd-vhosts.conf”, this is the actual player. At the end of the file you can specify something like this below:
DocumentRoot "C:/xampp/htdocs/project1" ServerName localhost:8001
DocumentRoot "C:/xampp/htdocs/project2" ServerName localhost:8002
Which tells your apache to take different folders on hitting different port numbers. That is when you hit localhost:8001/ it will take the contents from project1, similarly localhost:8002/ will point to your project2 folder.
By doing this we and run 2 different sites on our local machine.
Note: You need to restart your apache whenever you change something in httpd.conf or httpd-vhosts.conf.
Virtual Host create
N.B. you first open your editor(notepad etc....) as Run As Administrator mode otherwise you can not save these files. ok.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With