MacOS – How to set up OS X server for serving static files over HTTP

macosserver.appwebserver

I have OS X Server(.app) installed (because I'm a registered developer, so I got it for free). I figured it would be an easy way to flip a switch and get a web server for some static files, for my own local testing, but I can't seem to make it work.

There's a default website with location Default (/Library/Server/Web/Data/Sites/Default), and going to localhost in my browser shows a "Welcome to Lion Server" page, so it's definitely running.

I clicked the "+" button, changed the Domain Name to "*" (I assume that means "any", since it's what the default used), changed the port to 8000 (so it wouldn't collide with the default), changed the location to /Users/ken/Sites (which has a demo index.html file already), and clicked OK. It spins for a few seconds, the window goes away, and I'm back at the list of sites, and my new site isn't there.

I'm sure it'd be easier to install my own Apache or nginx through Homebrew at this point, but I'm invested. How do I make this thing work?

Update: I found /etc/apache2/sites/0000_any_8000_.conf, which appears to be exactly the website I created. I assumed it didn't work since it didn't appear in the Server list of web sites, but going to localhost:8000 actually works! Something is truly weird.

Best Answer

You do not need OS X Server to serve basic files. The non "server" version of OS X comes with a fully functional apache environment pre-installed. OS X Server is only for more advanced server features which are generally only useful if you're a sysadmin for small business.

To enable the pre-installed apache you just go into system preferences -> sharing and tick the box for "web sharing". Now apache is running on port 80, available to anyone who can access the mac.

You can configure it by editing httpd.conf (for example PHP is installed but disabled - just search for "php" in the config file and un-comment it, then restart apache. htaccess files are also disabled by default). Server Fault is the best place to ask questions about editing httpd.conf.

Since you installed OS X server I suspect you now have two separate copies of apache installed. One configured to run on port 80 (the one in system preferences) and one on port 8000 (the one in os x server).