116

The web directory is the home of all of your application's public and static files. Including images, stylesheets and JavaScript files. It is also where the front controllers live.

So the question is when i install and set up xampp my web directory is:

xampp\htdocs

and I want to set it up for:

xampp\htdocs\myproject\web

How to do it? Now when I type in my browser the address: http://localhost/
I enter xampp\htdocs directory
and I want to type in my browser the address: http://localhost/
and enter xampp\htdocs\myproject\web directory

3
  • 2
    You can use my answer over here stackoverflow.com/questions/18862739/… by creating a separated virtualhost you can define different root directories for different projects and by using the hosts file you can make new local domains.
    – Prix
    Commented Sep 19, 2013 at 19:06
  • what about that virtualhost file ? its virtualhost.file or what type it is ?
    – vardius
    Commented Sep 19, 2013 at 19:23
  • that is usually placed inside the file named vhosts.conf but in some cases can also be placed at the end of httpd.conf
    – Prix
    Commented Sep 19, 2013 at 19:29

10 Answers 10

191

You can change Apaches httpd.conf by clicking (in xampp control panel) apache/conf/httpd.conf and adjust the entries for DocumentRoot and the corresponding Directory entry. Just Ctrl+F for "htdocs" and change the entries to your new path.

See screenshot:

XAMPP config

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
2
  • 3
    Can it be any arbitrary directory? Even on a different partition?
    – posfan12
    Commented Jan 23, 2021 at 1:47
  • 1
    @posfan12, I'm a little late to the game here, but since it uses a fully qualified path, you can put it on a different drive entirely. Or might even be able to put it on a mapped network drive, too, depending on your network speed. Commented Jul 17, 2023 at 23:31
57
  • Go to C:\xampp\apache\conf\httpd.conf
  • Open httpd.conf
  • Find tag : DocumentRoot "C:/xampp/htdocs"
  • Edit tag to : DocumentRoot "C:/xampp/htdocs/myproject/web"
  • Now find tag and change it to < Directory "C:/xampp/htdocs/myproject/web" >

  • Restart Your Apache

2
  • 2
    It does works for a single project but what for multiple ones ?
    – Moeez
    Commented Mar 12, 2022 at 10:11
  • I'm a little late to the game here, but I would suggest against setting DocumentRoot to a specific folder inside "htdocs". If you simply have a folder inside "htdocs", you can point your browser to "localhost/myproject/web" or "localhost/mysecondproject" (or whatever folder you created) to have it work for multiple websites. Commented Jul 17, 2023 at 23:38
27

In case, if anyone prefers a simpler solution, especially on Linux (e.g. Ubuntu), a very easy way out is to create a symbolic link to the intended folder in the htdocs folder. For example, if I want to be able to serve files from a folder called "/home/some/projects/testserver/" and my htdocs is located in "/opt/lampp/htdocs/". Just create a symbolic link like so:

ln -s /home/some/projects/testserver /opt/lampp/htdocs/testserver

The command for symbolic link works like so: ln -s target source where,

target - The existing file/directory you would like to link TO.
source - The file/folder to be created, copying the contents of the target. The LINK itself.

For more help see ln --help Source: Create Symbolic Links in Ubuntu

And that's done. just visit http://localhost/testserver/ In fact, you don't even need to restart your server.

3
  • This is the best! Easy and completely flexible. Thanks.
    – WahhabB
    Commented Feb 4, 2019 at 23:00
  • 8
    This is great, and on Windows it would be mklink /J source target Commented Oct 11, 2020 at 10:22
  • Perfect, easiest solution. Thanks! Commented Apr 6, 2021 at 19:22
16

I moved my htdocs folder from C:\xampp\htdocs to D:\htdocs without editing the Apache config file (httpd.conf).

Step 1) Move C:\xampp\htdocs folder to D:\htdocs Step 2) Create a symbolic link in C:\xampp\htdocs linked to D:\htdocs using mklink command.

D:\>mklink /J C:\xampp\htdocs D:\htdocs
Junction created for C:\xampp\htdocs <<===>> D:\htdocs

D:\>

Step 3) Done!

0
9

ok guys you are not going to believe me how easy it is, so i putted a video on YouTube to show you that [ click here ]

now , steps :

  1. run your xampp control panel
  2. click the button saying config
  3. select apache( httpd.conf )
  4. find document root
  5. replace

DocumentRoot "C:/xampp/htdocs" <Directory "C:/xampp/htdocs">

those 2 lines || C:/xampp/htdocs == current location for root || change C:/xampp/htdocs with any location you want

  1. save it DONE: start apache and go to the localhost see in action [ watch video click here ]
0
7

You can also put in a new virtual Host entry in the

c:\xampp\apache\conf\httpd-vhosts.conf

like:

<VirtualHost *:80>
  ServerAdmin [email protected]
  DocumentRoot "C:/xampp/htdocs/myproject/web"
  ServerName localhost
  ErrorLog "logs/dummy-host2.example.com-error.log"
  CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
1
  • When used httpd-vhosts.conf make sure it's included (uncommented) in the XAMPP/xamppfiles/etc/httpd.conf file Commented Nov 23, 2022 at 15:44
4

# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#
Require all granted

Write above code inside following tags < Directory "c:\projects" > < / Directory > c:(you can add any directory d: e:) is drive where you have created your project folder.

Alias /projects "c:\projects"

Now you can access the pr0jects directory on your browser :

localhost/projects/

2

If you are running xampp on linux based image, to change root directory open:

/opt/lampp/etc/httpd.conf

Change default document root: DocumentRoot "/opt/lampp/htdocs" and <Directory "/opt/lampp/htdocs"

to your folder DocumentRoot "/opt/lampp/htdocs/myFolder" and <Directory "/opt/lampp/htdocs/myFolder">

2

For XAMMP versions >=7.5.9-0 also change the DocumentRoot in file "/opt/lampp/etc/extra/httpd-ssl.conf" accordingly.

-1

You can change the port while you open your XAMP control panel, follow the steps:

  1. click on config net to the start button, and
  2. select httpd.conf, a text file will open
  3. check the file and file listen:80,
  4. once got listen:80 replace with listen:8080 and
  5. save in the same folder.

Once done that, you will be able to start your local server.

1
  • this is not about changing the port. Commented Jul 16, 2023 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.