Code, Computers & Random Junk

My Server Setup in OS X - Part 1: Intro

I’ve said before that I’m going to talk a little bit about my server in OS X. I guess I need to start somewhere, so here’s a first post on it. It won’t be an instruction turorial or a “HowTo” with exact instructions on how to do it… More an conceptual overview, what I’ve done, folder and file layouts etc. And as I’m about to move on to Linux (as my main OS), I’d like to have this done before. Hopefully it’s helpful to someone.

OS X bundled server

Every OS X is coming with a bundled server. It’s a compete MAMP exept MySQL which you have to install manually. From 10.8 the ability to start/stop the Apache server in Systempreferences is gone, but there’s a 3’rd party pref-pane doing that. However, with that gone it’s quite easy to learn how to do things in Terminal instead.

With OS X 10.10 Yosemite. Apache is now upgraded to the 2.4 series, which is good. Other than that, OS X always seems to be a bit behind the updates, so it’s good to run your own server/installation to get the latest and more secure software installed.


There are a few different ways to install a server. XAMPP, MAMP etc, and of course you can install everything yourself, from scratch. Either by installing the different part with Homebrew, MacPorts etc, or compiling everything manually.

In my case, I’ve done my own setup, using my own layout and compiled everything manually from source. Yes, it’s a bit of PITA, but the benefits are great.

  • You get everything the way you like
  • you learn a lot during the process
  • upgrades and settings are easier when you can set and put stuff where you want
  • that feeling you get when your done, the “journey” is over and all is working

My Server Setup - Overview

When installing your own server and in this case, in OS X, where another server is already installed. We don’t want to use any part of the bundled server, because if you install anything in addition to it… then OS X comes with an update and might break your setup into their default. So, it’s a good thing to keep everything in /usr/local. Then you know where everything sits, and OS X can’t mess with it.

In my case… I also use/run Linux. And I really like the layout my Arch Linux have, especially the Apache layout. So, I’ve more or less been trying to make a version of that one, except where it lives. I have made a “halfway solution” for it - meaning, it sits halfway between /usr and /usr/local - eg /usr/httpd.

My PHP installation. I run 2 versions. One “older” version: 5.4, and latest stable 5.6. The older one I have to run/test older scripts in case I need that, and it’s compiled as a Apache module (mod_php). PHP 5.6 I’ve compiled to run as “FPM/FastCGI” (se picture below).

The MPM module in the Apache server is “event”, and it’s amazing how small the memory footprint is. Previous I only used PHP as a module using “prefork” in an Apache 2.2 environment. The difference is really great, booth in speed and memory.

MySQL… Since I still use OS X 10.7.5 there are no more installers on the MySQL site. I did try to manually compile MariaDB, but it failed. So, when I compiled my own MySQL I used mysql-5.7.5-m15.

I use the latest phpMyAdmin, but also have Adminer installed and I’m planning to move over to that one instead. Works great for the development environment.

For all my own scripts and testing I use the ~/Sites folder, and projects are going in to /srv/www. Default site is /srv/http. Website folders are using a /srv/fooBar/public_html/ structure to keep all related files in “fooBar” (sub)folders without going into the webfolder. The folder /srv is standard in Arch Linux (and many other distributions), while others keep them in the /var folder, like in Fedora. But I’ve changed that to use /srv instead (httpd.conf). OS X is using /Library/WebServer/Documents, but with /srv it’s also possible to mount/use it on a separate disk/partition. That is great for backups. You can just clone or back up the partition/disk instead &/or use it with another setup.

For Apache I’ve installed a few xtra modules, like mod_fastcgi and mod_geoip. FastCGI needs to be anotherversion with a patch to work in Apache 2.4. The reasons to use that one instead of Apache’s own cgid is many but one of them is I like to be able to use other extensions in PHP. And it’s way easier instead of using the proxy version.

Xtras in PHP are: GeoIP, ACPCu, Suhosin, Imagick and in 5.4 - Opcache (bundled in 5.6). I also use a patched version of the OpenSSL extension. I had a pull request that was added, but it’s not been added to 5.4 or 5.6 versions. Likely to come in PHP7 later… But it’s just a simple way to check for both SSLv2 and SSLv3 - if not compiled in OpenSSL they don show up in PHP.

Other than that… You’ll need to compile/install a few libraries - like the dependencies for GD and Imagick. But more on that later.

Here’s a picture/screenshot after an older update. Click to open the full sized image in a new window.

All Parts

Here are the links to the other parts. This was (still is) part 1.

The post was updated: 2015-12-23, with the links.