Where is localhost folder located in Mac or Mac OS X?

Where is localhost folder located in Mac or Mac OS X?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Where is localhost folder located in Mac or Mac OS X?

When you start developing PHP projects on a Mac using an IDE like PDT, the immediate question is usually where your localhost data lives. Unlike Windows, which often defaults to a specific virtual directory structure that users might explicitly configure, macOS relies on a different default behavior for web servers. If you haven't changed any settings during installation, your browser likely sees a "Welcome" page or nothing at all when you navigate to http://localhost. This isn't because the path is missing; it's because the default server configuration points to a specific directory that might not be where your project files are.

The standard location for the default web root on macOS, particularly in older versions of OS X running Apache, is /Library/WebServer/Documents. If you access http://localhost, the browser connects to the Apache daemon running locally, and it serves files from this exact path. However, many developers expect their project folder—say, /Users/yourname/projects/myapp—to be accessible at localhost. To make that happen without editing the main Apache configuration file, you need to understand how the default virtual host is structured.

In a standard setup, the file responsible for defining this behavior is located at /etc/apache2/httpd.conf. Within this file, you will find a section dedicated to VirtualHosts. By default, there is an entry that looks something like this:

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents"
    <Directory "/Library/WebServer/Documents">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Deny from all
    </Directory>
</VirtualHost>

The DocumentRoot directive tells Apache which folder to serve when a request hits the server. The <Directory> block controls permissions for that folder. Notice the Deny from all directive in older configurations; this effectively blocks access even if the files exist, unless you modify the rules or change the root entirely.

To use your own project folder as localhost, you have two primary options. The first is to create a symbolic link. You can run a command in Terminal to point the default document root to your project directory:

ln -s /path/to/your/project /Library/WebServer/Documents

This approach is simple and requires no changes to the Apache configuration file, but it has a significant downside: if you work on multiple projects simultaneously, they will all share the same localhost address. You would need to stop and start Apache or change the symlink every time you switch contexts, which breaks your workflow.

The second approach is to add a new VirtualHost configuration that points specifically to your project folder while keeping the default root intact. You can create a new file in /etc/apache2/vhosts.d/ (creating the directory if it doesn't exist) and define a specific host for localhost. This allows you to run multiple projects on different ports or keep them isolated if you modify the hostname slightly.

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "/Users/yourname/projects/myapp/public"
    
    <Directory "/Users/yourname/projects/myapp/public">
        Options +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

After modifying the configuration, you must restart Apache for changes to take effect. On macOS, this is typically done via sudo apachectl restart. Modern versions of macOS (Catalina and later) actually removed Apache entirely by default due to security concerns, shifting towards Nginx or the lightweight PHP built-in server. If you are on a newer system and haven't installed Apache manually, your "localhost" might simply be pointing to nothing until you install a stack like MAMP or LAMP.

If you are building modern PHP applications, specifically those using Laravel, the concept of localhost becomes slightly more abstract. While the file location remains a server configuration issue, the application structure expects files in a public directory. Always ensure your DocumentRoot points to the public subfolder of your project, not the root of the project itself. This is a critical security distinction that prevents direct access to framework files like artisan or .env.

For more robust development environments where you want to avoid managing Apache configurations entirely, tools like Laravel Valet are designed specifically for macOS. They handle the symlink creation and SSL certificate management automatically, allowing you to map yoursite.test directly to your project folder without touching system files. However, if you are strictly adhering to the stock OS X installation with PDT, understanding the /Library/WebServer/Documents hierarchy is the key to unlocking your local development environment.

Our network