10/7/2019 - 12:13 PM

Setup Vhost Config in OS X Mojave

Setup Vhost Config in OS X Mojave

Fix "403 Forbidden Error" on localhost after OS X Mojave Update


Avoid installing Homebrew's Apache side-by-side with OS X's native Apache


1. Edit httpd.conf file in /private/etc/apache2

  • Uncomment these modules:
LoadModule include_module libexec/apache2/mod_include.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php7_module libexec/apache2/libphp7.so
  • Set Username and Group
User <UserName>
Group staff
  • Add localhost as ServerName:
ServerName localhost
  • Include vhosts config by uncommenting:
Include /private/etc/apache2/extra/httpd-vhosts.conf

2. Edit httpd-vhosts.conf file in /private/etc/apache2/extra

  • Comment out VirtualHost examples
  • Add Directory Block:
<Directory "/Users/<UserName>/Development">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
    DirectoryIndex index.php
  • Add vhost entry for default web folder
<VirtualHost *:80>
    ServerName localhost
    ServerAlias www.localhost
    DocumentRoot "/Library/WebServer/Documents"
  • Add vhost entry for the web page
# example.com
<VirtualHost *:80>
    ServerName example.local
    ServerAlias www.example.local
    DocumentRoot "/Users/<UserName>/Development/example.com"

3. Edit hosts file in /private/etc/hosts

  • Add server Name and Alias from vhost entry   localhost   example.local   www.example.local broadcasthost
::1             localhost

4. Take the ownership of /Library/WebServer/Documents

(Fixes 403 Forbidden Error after OS X Mojave Update)

sudo chown -R `whoami` /Library/WebServer/Documents

5. Test Apache config

apachectl configtest

6. Restart Apache Server

sudo apachectl restart