Where does this tag go?
Where do I find the vhosts file?
I couldn't find it in the documentation.
SetEnv NS_ENV variable_value
Full guideline to make VHOST (Virtual Host) on XAMPP/WAMP
The only different between XAMPP and WAMP is you need to locate the equivalent folders in WAMP instead.
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 php has local url address
Project 2 is a Laravel project with url
Project 3 is a Codeigniter with url
You are expected to have installed the latest version of XAMPP/WAMP. Btw, in XAMPP I have only selected Apache and MySQL installation.
*Note: By default, most web servers will use
port 80as default port, in some situation if you have another web server like (IIS) that uses port 80 OR in other cases SKYPE does also some times use port 80 like it is the case for some in Windows 10, in that case you can do two thing's
81or some other free ports (8080 can some times also give some problems)
port 80in case of Skype just quit Skype and start it after you finish the installation it will automatically get new port.
I have chosen to change my XAMPP/WAMP to
Note: For next section, we need to use text editor like notepad or regular IDE. I used sublime text editor.
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:\Bitnami\wampstack\apache2\conf\httpd.conf or similar location.
Change the line with
To 8080 or other, free ports.
While we have
httpd.conf file open we need to ensure that
httpd-vhosts.conf is included:
By default server documents are locate on
C:\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.
Step 2. Setting Virtual host
Informative notes before you start:
1- Create a folder for your projects; I have create one in
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:\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 project1.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>
Note: If you work on Laravel projects you can create unlimited Laravel projects as well as other frameworks like Yii, the point is to have your Laravel project/s on
c:\vhost\laravel2etc and make
c:\vhost\laravel1\publicas DocumentRoot etc as showed before. Each Laravel project will have own VirtualHost URL.
Save and close the file
We are not ready yet, read more.
Step 3. Edit Windows Host file
1- Stop Apache and MySQL services from XAMPP/WAMP.
2- Open hosts file in
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 project1.localhost 127.0.0.1 project2.localhost 127.0.0.1 laravel.localhost
save the file
Final Step. Start/Re-start your Apache and MySQL again.
Note: You might need to delete your cache in your browser and also it is good to disable php cache under development process.
php.iniunder php folder in your XAMPP or WAMP folder and change
[opcache] zend_extension=php_opcache.dll ; Determines if Zend OPCache is enabled opcache.enable=0
Addition (Alternative solution)
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 what ever your project path.
In your browser you need only to right
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>