Fixing Apache localhost/~username resolve on macOS Mojave

Edit /etc/apache2/httpd.conf

sudo vi /etc/apache2/httpd.conf

Uncomment the following lines:

#LoadModule vhost_alias_module libexec/apache2/
#Include /private/etc/apache2/extra/httpd-vhosts.conf
#LoadModule userdir_module libexec/apache2/
#Include /private/etc/apache2/extra/httpd-userdir.conf

Uncomment the following in /private/etc/apache2/extra/httpd-userdir.conf :

#Include /private/etc/apache2/users/*.conf

Create the file /private/etc/apache2/users/yourUserName.conf if it doesn’t exist:

sudo vi /private/etc/apache2/users/yourUserName.conf

Add the following in this file:

<Directory "/Users/yourUserName/Sites/">
  Options Indexes MultiViews
  AllowOverride None
  Require all granted

For running PHP, uncomment the following line in /etc/apache2/httpd.conf . The version of PHP in the module name may vary as per the currently installed version (7 in this case):

#LoadModule php7_module libexec/apache2/

Restart Apache server:

sudo apachectl restart

The local webserver should now be available at http://localhost/~yourUserName/ , referring to the location ~/yourUserName/Sites/

Leave a Reply

Your email address will not be published. Required fields are marked *