0% found this document useful (0 votes)
62 views

How To Set Up Apache Virtual Hosts On XAMPP (Windows) - Stack Overflow

This document provides a 4-step process to set up Apache virtual hosts on XAMPP (Windows): 1. Change the Apache port from 80 to another free port like 8080 in the httpd.conf file. 2. Set up virtual hosts by adding code to the httpd-vhosts.conf file to define the document root and server name for each virtual host. 3. Edit the Windows hosts file to map the virtual host names to 127.0.0.1. 4. Start or restart the Apache and MySQL services in XAMPP.

Uploaded by

David PONDA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

How To Set Up Apache Virtual Hosts On XAMPP (Windows) - Stack Overflow

This document provides a 4-step process to set up Apache virtual hosts on XAMPP (Windows): 1. Change the Apache port from 80 to another free port like 8080 in the httpd.conf file. 2. Set up virtual hosts by adding code to the httpd-vhosts.conf file to define the document root and server name for each virtual host. 3. Edit the Windows hosts file to map the virtual host names to 127.0.0.1. 4. Start or restart the Apache and MySQL services in XAMPP.

Uploaded by

David PONDA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

How To Set Up Apache Virtual Hosts on XAMPP

(Windows) [closed]
Asked 8 years, 10 months ago Modified 8 months ago Viewed 92k times

Closed. This question needs to be more focused. It is not currently accepting answers.

40 Want to improve this question? Update the question so it focuses on one problem only by editing
this post.
Closed 3 years ago.

The community reviewed whether to reopen this question 1 year ago and left it closed:

Original close reason(s) were not resolved

Improve this question

How To Set Up Apache Virtual Hosts on XAMPP (Windows)

xampp

Share Improve this question edited Dec 9, 2019 at 10:58 asked Jan 3, 2015 at 11:33
Follow user3949359

Awesome, looks like this is it. Do I just add the tag to the existing two or do I overwrite? – user3949359
Jan 3, 2015 at 11:54

I'd like to configure my vhosts for a project, if possible. As according to this CMS documentation:
nnb.geomash.com/documentation/1.6/basic-installation/… – user3949359 Jan 3, 2015 at 12:14

ok here is what I understand; you have XAMPP installed with apache webserver and you want to create
seperate virtual host to an application; let say your main webserver is locahost and your new
application is cms.localhsot? is that correct – Maytham Fahmi Jan 3, 2015 at 12:18

From my understanding, vhosts is used to run multiple domains on the same machine. This is what I
want to achieve. Plus, the documentation tutorials tells you to do it (which makes me think it'll come
handy at some point, even if I don't know it right now). – user3949359 Jan 3, 2015 at 12:21

4 Answers Sorted by: Highest score (default)

You need to follow some steps to create a virtual host in windows with apache.
116
Note: To start with, the only difference for this guideline, between XAMPP and WAMP
or other Apache packages for Windows, is a question about where those packages
are installed on your computer.

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

Project 1 is based on PHP and has the local URL address php.localhost

Project 2 is a Laravel project with URL laravel.localhost

Project 3 is a Codeigniter with URL codeigniter.localhost

Project 4 is a WordPress with URL 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 use port 80 as the default port, in some
situations if you have another web server installed like (Microsoft IIS), it uses port 80
as well OR in other cases, SKYPE does also sometimes 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 sometimes also give some problems)

OR Change your other 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, and Skype
will automatically get a new port.

I have chosen to change my Apache to port 8080.

Note:

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

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

Virtual hosts

Note: By default server documents are located on C:\XAMPP\htdocs or


C:\Bitnami\wampstack\apache2\htdocs 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 the virtual host, as mentioned earlier.

Step 2. Setting Virtual host

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

2. In c:\vhost folder we create a sub-folder domain1 or project1 or any other, it is up to you


( c:\vhost\project1 )
3. Open httpd-vhosts.conf file C:\XAMPP\apache\conf\extra\httpd-vhosts.conf Add the
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\laravel2 etc and make
c:\vhost\laravel1\public as DocumentRoot etc as shown before. Each Laravel
project will have own VirtualHost URL.

Save and close the file

Some additional information and notes:

If the port remains default 80 then the URL address will be localhost

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

If the 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 hosts this way.

We are not ready yet, read more.

Step 3. Edit Windows Host file

1. Stop Apache and MySQL services from XAMPP/WAMP.


2. Open the hosts file in C:\windows\system32\drivers\etc you need Administrator
privilege to edit the file. I suggest editing the file directly with the Sublime text editor.

3. Add 127.0.0.1 project1.localhost at the end of the file, and 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.

**Addition (Suggestion)**

Note: Under your development process you might face a problem having a cache on
because you can risk updating something in Laravel and it won't appear in your
browser. Therefore you might need to disable PHP cache under the 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, so I would suggest a virtual host
solution with port 80 as default.

It is possible to deploy a temporary Virtual Server without necessarily configuring


XAMPP/WAMP Virtual Host, start the CMD console, and run the following PHP command:

php -S localhost:8001 -t c:\vhost\Laravel-Project\public

Port 8001 can be changed to any available port number and be sure not to conflict with
other software ports.

c:\vhost\Laravel... path should be changed to whatever your project path.

It is possible to start multiple servers but should have different port numbers.

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 your site, you may need to add this
to your httpd.conf file:

<Directory path_to_dir>
AllowOverride none
Require all granted
</Directory>

Share Improve this answer edited Mar 6 at 6:50 answered Jan 3, 2015 at 12:45
Follow Maytham Fahmi
31.5k 16 118 139

2 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>
– Webucator Apr 19, 2016 at 20:29
is there any way to get rid of the :8001 from the url? i mean can i make http://local.xyz.com
point to http://localhost:8001/xyz/public ? – George Dec 20, 2018 at 9:47

@maytham-ɯɐɥʇʎɐɯ yes i followed the guide and it is so awesome worked from the first try, thank you
for that. my port 80 is also occupied by other stuff thats why i am using port 8989 so i was wondering
if its possible not to write it in the url, like forcing it from the vhost config or the host file – George Dec
20, 2018 at 10:04

@George as far as I know I do not think it is possible, that said I have never tried it before neither
research this possibility. I have cousily just made a quick search on google and found link you can read
webmasters.stackexchange.com/questions/55123/… and – Maytham Fahmi Dec 20, 2018 at 10:29

1 @maytham-ɯɐɥʇʎɐɯ i just read the link you provided, it seems that it is not possible currently, so i will
try to free port 80 since it will be easier than trying to achieve what i want, yes i am lazy :d, if i find more
information on this topic i will link it here. thank you so much for the help and have a good day
– George Dec 20, 2018 at 10:41

You can make your localhost to point to different folders on different port numbers. Follow
these simple steps:
2
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

Listen 80

Listen 8001

Listen 8002

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.

Share Improve this answer Follow answered Mar 8, 2016 at 8:41


Prakash Bhandari
549 8 16
A note for other people: remember to use <VirtualHost *:8001> and <VirtualHost *:8002>, respectively!
– kpollock Sep 22, 2016 at 6:49

Virtual Host create

1. C:\xampp\apache\conf\extra Open httpd-vhost file then Add


1
DocumentRoot "C:\xampp\htdocs\project\timegrid\public" ServerName
mytimegrid.me(ur choice)

2. C:\Windows\System32\drivers\etc Open hosts file then add 127.0.0.1


mytimegrid.me(Your Domain Name)

N.B. you first open your editor(notepad etc....) as Run As Administrator mode otherwise you
can not save these files. ok.

Share Improve this answer Follow answered Oct 22, 2017 at 9:46
Mituram Ray
11 1

First of all, open your Notepad as an Administrator and then click on file > open . Then go to
your window driver now search for system32 folder and then search for drivers folder and
0 then the etc folder.

Now you'll see a folder of empty files, so don't worry to see Text Documents ( *.txt ) at the
bottom. Change the view to all files and then you will see the vhost file.

Open and enjoy!

Share Improve this answer edited May 26, 2016 at 14:45 answered May 25, 2016 at 6:06
Follow zx485 Ameer Abbas
28.6k 28 50 60 11 4

You call this an answer? – user13944038 Oct 30, 2022 at 18:50

You might also like