Making your macbook pro or macpro a local webserver for web development

There are instances when having just a local instance available would be perfect. I have looked over the web and found several blogs that show how this is done and I crammed them together to make this document. I was tired of setting up a site on an external web server just to test something small. This is for Mac users, windows user have it pretty easy in this department.

I wanted to have this on my local laptop so that I could edit web templates for customers and upload them to their websites.
Below is one I have started working on for company:

Creating a local Web Server on your mac with High Sierra 10.13.4

Open a terminal window on your mac.
Type the following command, replacing with the user account short name:

sudo nano /etc/apache2/users/USERNAME.conf

Enter the admin password when requested, then paste the following into the nano text editor:

<Directory “/Users/USERNAME/Sites/”>
Options Indexes Multiviews
AllowOverride AuthConfig Limit
Order allow,deny
Allow from all
</Directory>

In the .conf file it will look like this:

Edit the Directory path to the appropriate username.
Now hit Control+O to save the changes to , then hit Control+X to quit out of nano
Next, you will start the Apache web server with the following command:
sudo apachectl start

Launch Safari, Chrome, or Firefox and navigate to “http://127.0.0.1” to verify the server is running, you will see an “It Works!” message
Now that you’ve started a successful Apache server in OS X, you can either modify the core ‘localhost’ files, or go further with the user files.

Apache Web Server Documents Location & User Sites Folders

Note, if you just want to use and modify ‘localhost’ root and not the user level Sites at localhost/~user, you can find the apache webserver files and ‘It Works!’ html in the following location:

/Library/WebServer/Documents/

You can now also visit http://127.0.0.1/~USERNAME/ to see the contents of whatever is stored in the directory – if anything is there per user – and you can add an index.html file or whatever else you’d like to the directory to serve it to the outside world or even just your LAN.

Using http://localhost/ is also fine, and by editing the hosts file you can set a local domain to whatever you want to create a local test environment with an otherwise live domain.

This whole process is quite fast, and can be completed in under a minute as demonstrated in the video walk through below:

Shutting Down Apache & Restarting Apache Server
To shut down the web server, go back to the command line and type the following:

                     sudo apachectl stop

If you make changes to the server and just want to restart it, that can be accomplished with the following command instead:

                    sudo apachectl restart

The default Apache server is barebones and does not have PHP, MySQL, or anything particularly fancy enabled. You can either install and configure those manually, or you can go the pre-configured route through an all-in-one server app like MAMP, which includes Apache, MySQL, and PHP in a simple to control app-based web server package. You can get MAMP free from here.

Glad to have been of help to you,
Arthur Poston Jr.