Creating a local web-server on MacOS Big Sur

Start the builtin Apache server

				
				
					sudo apachectl start				
			

You should now be able to direct your browser to ‘localhost’ or ‘127.0.0.1’ and see in the browser ‘ it works!’. The default Apache configuration reads from

				
				
					/Library/WebServer/Documents/index.html.en				
			

Apple recommends to create a directory ‘Sites’ in your home account and run your local user website from there. First, create the directory for the website in your home directory

				
				
					mkdir  ~/Sites
echo '

It works locally too!

' > ~/Sites/index.html

Next, navigate to the apache user configuration directory

				
				
					cd /etc/apache2/users				
			

where you should see a file with your user name ending with ‘.conf’.

				
				
					<Directory "/Users/developer/Sites/">
        Options Indexes MultiViews
        Require all granted
</Directory>				
			

Modify it to

				
				
					<Directory "/Users/developer/Sites/">
        AllowOverride All
        Options Indexes MultiViews FollowSymLinks
        Require all granted
</Directory>				
			

Navigate to the parent directory, and make a backup of the original ‘https.conf’ file.

				
				
					cd /etc/apache2
sudo cp httpd.conf httpd.conf.bak
cd /etc/apache2/extra
sudo cp httpd-userdir.conf httpd-userdir.conf.bak				
			

Edit the file

				
				
					/etc/apache2/extra/httpd-userdir.conf				
			

and uncomment line 16

				
				
					# Settings for user home directories
# 
# Required module: mod_authz_core, mod_authz_host, mod_userdir

#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.  Note that you must also set
# the default access control for these directories, as in the example below.
#
UserDir Sites

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
#Include /private/etc/apache2/users/*.conf
<IfModule bonjour_module>
       RegisterUserSite customized-users
</IfModule>				
			

Next, edit the file

				
				
					/etc/apache2/httpd.conf				
			

and uncomment line 113

				
				
					#LoadModule include_module libexec/apache2/mod_include.so				
			

lines 186 and 187

				
				
					#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
#LoadModule php7_module libexec/apache2/libphp7.so				
			

lines 524

				
				
					#Include /private/etc/apache2/extra/httpd-userdir.conf				
			

and line 555 (the last line)

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

Make sure the following lines are also uncommented

				
				
					LoadModule authn_core_module libexec/apache2/mod_authn_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so				
			

Finally, restart the apache server

				
				
					sudo apachectl restart				
			

Test the configuration by pointing the browser to you local user site

				
				
					http://localhost/~username				
			

where ‘username’ is your account name. The account name can found by the command

				
				
					whoami				
			

Leave a Reply

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

Scroll to Top
X