Start an Apache Web Server in Mac OS X Mavericks & Mountain Lion
The Sharing preference panel options were changed a bit in OS X Mountain Lion and again in Mavericks, and while things like Internet Sharing remain, the Web Sharing preference panel was removed. The Apache web server remains bundled with Mac OS X though, but you’ll need to turn to the command line to enable the web server. Additionally, you’ll want edit a user configuration file for each user account on the Mac to have the personal web sharing feature active. If any of this sounds intimidating or complex, it’s really not, just follow along and you’ll have a simple web server running on your Mac in no time.
Setting Up and Starting the Apache Web Server in OS X
Versions of OS X prior to Mountain Lion and Mavericks can simply turn on “Web Sharing”, but from 10.8 and 10.9 onward you’ll need to do the following to use a local web server:
- Launch Terminal, located in /Applications/Utilities/
- Type the following command, replacing USERNAME with the user account short name:
- Enter the admin password when requested, then paste the following into the nano text editor:
- Edit the Directory path USERNAME to the appropriate username
- Now hit Control+O to save the changes to USERNAME.conf, then hit Control+X to quit out of nano
- Next, you will start the Apache web server with the following command:
- 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
Options Indexes Multiviews
AllowOverride AuthConfig Limit
Allow from all
In the .conf file it will look like this:
sudo apachectl start
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:
You can now also visit http://127.0.0.1/~USERNAME/ to see the contents of whatever is stored in the user ~/Sites/ 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.
This whole process is quite fast, and can be completed in under a minute as demonstrated in the video walkthrough 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.
Thanks to Ben for the tip idea