How to Configuring a Xampp Web Server for Different Root Directory

how to configuring a xampp web server for different root directory

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">

How to change htdocs to different directory in XAMPP?

Find the xampp/conf/httpd.conf then change the 'DocumentRoot' to the new directory, also change the 'Directory' tag to the new directory then save the file and restart apache server.

how to change web server folder location in xampp

Edit the file /opt/lampp/etc/httpd.conf and change the lines containing current web directory path. It should start with DocumentRoot. Update all the places having the current path to the path you would like it to be.

Root path in XAMPP

An alternate way to handle this is with the use of Virtual Hosts.

A virtual host acts like a second version of localhost that works specifically for a subfolder. For example, you could set up Apache so that when you visit http://example (no .com or anything), it shows you the content from http://localhost/example/. All CSS and JavaScript and links would act as if they were operating from the root folder of a website, since the leading example folder has been trimmed out of the URL.

I can't find a walkthrough that I used to use for XAMPP, but here a similar one that covers all of the main points. It was written for Windows, but I imagine that there are similar mechanisms that you can use for LAMP:

To summarize, here's what the article tells you to do:

  • Enable Virtual Hosts within Apache
  • Set it up so that when you visit example, you are sent to 127.0.0.1
  • Configure Apache so that when someone visits 127.0.0.1 (but the name of the website is example), then it shows content from the example folder.

This is how your production site (which is a single server with multiple websites) has a different "root" for each website.

how to change root folder in xampp

You need to find the Document Root directive in the httpd.conf to change the root folder. For example:

# DocumentRoot "/xampp/htdocs"
DocumentRoot "/path/to/your/web/project"

Then find Directory and make the change there:

# <Directory "/xampp/htdocs">
<Directory /path/to/your/web/project">

Take my advice, always comment out the line you do not want so you can return to it later if need be or something gets screwed up.

Path to root in apache (XAMPP)

I have mine set like this. In xampp/apache/conf/http.conf:

DocumentRoot "C:/xampp/htdocs/drupal/"

You could set yours to something like:

DocumentRoot "C:/xampp/htdocs/mysite/"

If I do this, test.php in my drupal folder, running getcwd() returns

C:\xampp\htdocs\drupal


Related Topics



Leave a reply



Submit