23

I want to change XAMPP's htdocs directory. I followed the instructions to create a virtual host from this question:

Make XAMPP/Apache serve file outside of htdocs

this works fine on Windows 7, however when I try it on OSX, going to mysite.local just loads the xampp splash screen (mysite.local/xampp/index.html). I have restarted the web server. My virtual host declared in httpd-vhosts.conf is:

<VirtualHost *:80>

DocumentRoot Users/username/Documents/sitename.com

ServerName sitename.localhost

<Directory Users/username/Documents/sitename.com>

Order allow,deny 
Allow from all

</Directory>
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
jela
  • 1,449
  • 3
  • 23
  • 30

5 Answers5

22

Open the following file in a text editor.

/Applications/XAMPP/xamppfiles/etc/httpd.conf

Search for "DocumentRoot", if the line below has a # in front of it than it's commented remove it and change the path between the quote

DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"

Now search for the line below and change the path between the quotes to your needs.

<Directory "/Applications/XAMPP/xamppfiles/htdocs">

NOTICE: Paths similar to ~/ won't work use the absolute path.

Dani G.
  • 577
  • 8
  • 21
Antonio Max
  • 8,627
  • 6
  • 43
  • 42
  • 1
    If you only change these two setting it won't work. I am trying to change document root my self, but without success for now. Followed above edit, but didn't work for me either. – Primoz Rome Mar 23 '13 at 13:33
  • 1
    i can solve that problem with this answer. You also have to uncomment the first line to make it work. Mine is using XAMPP Osx 1.8.2-2 – risnandar Nov 27 '13 at 06:58
  • 1
    You will lose the phpMyAdmin in that case ! – Mahmoud Fayez Dec 29 '13 at 20:47
  • Make sure that your new root folder exists because if it doesn't, Apache won't start. – Daniel Harris Dec 30 '13 at 16:35
  • 1
    Im using MacOS Sierra and this causes an Access Forbidden thing to show... – SumNeuron Feb 25 '17 at 19:35
  • 1
    @SumNeuron search for the "User deamon" within your httpd.conf and change it to your os user. you can get the os user with help of the whoami command. (I guess you figured that out by now but I hope it helps others) – Robin F. Mar 10 '17 at 21:52
  • use this to make it work. replace user name - https://stackoverflow.com/a/32963665/2444716 – Harish Kumar Jun 27 '20 at 03:09
2

I would like to expand this answer for 2022.

You will have to change 3 files if you want to keep web root in another directory. Let's say that you have installed XAMPP regularly, but your httpd directory is on another volume. Let's say in work/xampp/

Open /Applications/XAMPP/xamppfiles/apache2/conf/httpd.conf and change it to the following

Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"

DocumentRoot "/Applications/XAMPP/xamppfiles/apache2/htdocs" 
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

DocumentRoot "/Volumes/work/xampp"
<Directory "/Volumes/work/xampp">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

We have added

DocumentRoot "/Applications/XAMPP/xamppfiles/apache2/htdocs"

and the block

DocumentRoot "/Volumes/work/xampp"
<Directory "/Volumes/work/xampp">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Open file /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf and change it to the following

<VirtualHost *:80>
    DocumentRoot "/Volumes/work/xampp"
</VirtualHost>

<VirtualHost yoursite.mac:80>
    ServerName yoursite.mac
    ServerAlias www.yoursite.mac
    ServerAdmin webmaster@yoursite.mac
    DocumentRoot "/Volumes/work/xampp/yoursite.mac/webroot"
    ErrorLog "/Volumes/work/xampp/yoursite.mac/logs/oll.mac-error_log"
    CustomLog "/Volumes/work/xampp/yoursite.mac/logs/oll.mac-access_log" common

    <Directory "/Volumes/work/xampp">
        Require all granted
    </Directory>
</VirtualHost>

Open /etc/hosts as a sudo and add your new site to it

127.0.0.1 yoursite.mac
Vladimir Jovanović
  • 3,288
  • 1
  • 20
  • 27
1

If you forward to a directory in your user root, then:

DocumentRoot "/Users/<your username here>/Sites"
<Directory "/Users/<your username here>/Sites">
Josephus87
  • 1,126
  • 9
  • 19
1

Other than the answers mentioned above, I also had to change the line in XAMPP/xampfiles/etc/httpd.conf where it mentions username. the default was set to daemon and I changed it to my username; so there was no permission problem.

Milad
  • 1,239
  • 3
  • 19
  • 37
0

solved by editing httpd.conf

I have got this working. As per http://www.acwolf.com/blog/2009/February/xampp-virtual-hosts-mac, in OSX it is necessary to make two changes to httpd.conf, first, uncomment

#Include /Applications/xampp/etc/extra/httpd-vhosts.conf

and second, change the user from nobody to the username you use to log into OSX. You may also need to delete your browser's cache.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
jela
  • 1,449
  • 3
  • 23
  • 30