Create Apache Alias in XAMPP for Mac

Apache is a web server software which explanation could be find here.

Usually you would like to build web applications using PHP and MYSQL. However many people don’t like the manual installation of apache, the php module for apache and the Mysql database. For those (like me) there are software that include all this programs in a package. I am using XAMPP for MAC.

When you install XAMPP you should place your applications in the httdoc folder inside the Xampp folder. However many times you would like to place a web application outside the default “htdocs” folder, for example you would like to use a web application located inside you /Users//Documents/.

To do that so, you would need to create an alias inside you httpd.conf file on xampp.

  • Open the file /Applications/xampp/etc/httpd.conf in a text editor.
  • Add these lines to the end of the files. (change the name of the alias for the web application that suits better for you)

[sourcecode language="bash"]
Alias /myapplication /Users/your_mac_username/Documents/your_web_application_path
<Directory "/Users/your_mac_username/Documents/your_web_application_path">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
[/sourcecode]

Alias Apache Mac

Then comes the tricky part:

Now if you try to use your website with the alias (http://localhost/myapplication)

You will get a message like this:

“You don’t have permission to access /xampp/index.php on this server.”

You need to tell apache to use your username to access the resources in your computer (This is not recommendable on production servers)

  • Open the file /Applications/xampp/etc/httpd.conf in a text editor.
  • Search after and change the next lines

[sourcecode language="bash"]
<IfModule !mpm_netware_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User nobody
Group admin
</IfModule>
[/sourcecode]

Change the user name to your Mac username (the one you user to login in you computer, so the code should look this this:

[sourcecode language="bash"]
<IfModule !mpm_netware_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User your_mac_username
Group admin
</IfModule>
[/sourcecode]

Restart the Xampp service (restart apache) and now you should be able to access your web application using http://localhost/myapplication.

I have to thanks to “Aaron Wolf” because his post about creating virtual host on Xampp using apache was very useful.

I hope this can be useful for some of you

Posted in Software suggestions
One comment on “Create Apache Alias in XAMPP for Mac
  1. Mauricio says:

    Funny! After a year of writing this, I used because I needed.
    Thank you to myself! :D