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:
#
# 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 to127.0.0.1
- Configure Apache so that when someone visits
127.0.0.1
(but the name of the website isexample
), then it shows content from theexample
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
Is There Any Sort of "Pre Login" Event or Similar
PHP and Microsoft Access Database - Connection and Crud
PHP Function Imagettftext() and Unicode
Stored Procedures, MySQL and PHP
Remove Trailing Slash from String PHP
Increase PHP Script Execution Time
Pass a Percent (%) Sign in a Url and Get Exact Value of It Using PHP
Laravel 5.1: Keep Uploaded File as Old Input
Mysqli + Xdebug Breakpoint After Closing Statement Result in Many Warnings
Domxpath - Get Href Attribute and Text Value of an a Element
Does the Order of Class Definition Matter in PHP
Mysqli_Select_Db() Expects Parameter 1 to Be MySQLi, String Given
PHP Files Are Downloaded by Browser Instead of Processed by Local Dev Server (Mamp)
How Come Checkbox State Is Not Always Passed Along to PHP Script
Having Two Different Sessions in Same Domain
What Is the Maximum Size of an Array in PHP