Setting Up XAMPP on macOS Sonoma With Local User Folder

I wanted to write a compelling introduction to this post, but the truth is: I want to write down the steps for myself for future reference. If you’re interested in setting up XAMPP on macOS so that you can serve files from your user folder, follow along.

Disclaimer: I am only using XAMPP for local testing, so this guide might have some bad security advice in it. If you read this and have security concerns, let’s talk!

Prerequisites

Before you begin, ensure you have the following:

Steps

1. Install XAMPP

My version is the 8.2.4. The app is called “manager-osx” for some weird reason.

2. Disable Pre-Installed Apache

macOS Sonoma has its own Apache Server which we need to disable so it does not conflict with XAMPP. Open Terminal and run the following command to stop the existing Apache processes:

sudo killall httpd

Next, start the XAMPP Apache server:

sudo /Applications/XAMPP/xamppfiles/bin/apachectl start

3. Set Up public_html Folder and Test File

Create a public_html folder inside your user home directory, and add an index.html file to it. This will help us test the setup later. A folder called public_html directly inside your user folder is the default foldername for Apache userDir folders. It can be changed, but it is way easier if you stick to it.

Run the following commands in Terminal:

mkdir ~/public_html/ &&
touch ~/public_html/index.html &&
echo '<h1>YAY!</h1>' >> ~/public_html/index.html

4. Open Config file from XAMPP

Open XAMPP and navigate to Manage Servers -> Configure -> Open Conf File. This will open the main configuration file for Apache.

5. Activate userDir (folders) in httpd.conf

Find the line that says # User home directories and uncomment the following line to enable user directories. It should look like this:

# User home directories
Include etc/extra/httpd-userdir.conf

6. Change User Apache Runs Under Your User

Find the section that defines the user Apache runs with:

<IfModule unixd_module>
…
User daemon
Group daemon

Change the User to your macOS username to allow Apache to access files in your user directory:

User yourUserName

⚠️ Note: This step may pose security risks. If you know of a more secure method, please use that instead.

7. Restart Apache

Finally, restart the Apache server to apply the changes:

sudo /Applications/XAMPP/xamppfiles/bin/apachectl restart

After restarting Apache, you should be able to open http://localhost/~yourUsername/ and the page should show “YAY!“.

Yay.

Portrait of Moritz Glantz

👋 Moritz Glantz is my name…

…and I am an Specialist for Web Accessibility and UX-Engineer with over 20 years of experience, by day and a podcaster by night.

I help organizations build accessible websites by offering talks about accessibility, workshops & trainings, accessibility reviews and developing strategies for developers and management.

If that sounds like you could use my help, let’s talk! 💬