Compile OpenSSH 6.7 with LibreSSL on OSX (10.10 / Yosemite)

Lets say you want to use the newest version of OpenSSH on your MacBook / OSX for reasons like:

  • your current version is too old for newer ciphers, key exchanges, etc.
  • you trust LibreSSL more than some OSSLShim
  • you are just some hipster that wants to have running

No worries, in this short tutorial I will show you how to compile OpenSSH 6.7p1 from source without replacing your current installed ssh implementation shipped by OSX.

We will be using LibreSSL instead of OpenSSL which is easier to compile and might be more secure than OpenSSL itself.

Some of the gists I took from here:

Get sources

$ wget

Compile LibreSSL

$ tar xvfz libressl-2.1.3.tar.gz
$ ./configure --prefix=/opt/libressl --with-openssldir=/System/Library/OpenSSL --with-enginesdir=/opt/libressl
$ make
$ sudo make install

Compile ldns

$ tar xvfz ldns-1.6.17.tar.gz
$ cd ldns-1.6.17.tar.gz
$ ./configure --with-ssl=/opt/libressl
$ make
$ sudo make install

Compile OpenSSH

$ tar xvfz openssh-6.7p1.tar.gz
$ cd openssh-6.7p1

$ wget

$ patch -p1 < 0002-Apple-keychain-integration-other-changes.patch
$ patch -p1 < patch-openssl-darwin-sandbox.diff
$ patch -p1 < launchd.patch

$ autoreconf -i
$ export LDFLAGS="-framework CoreFoundation -framework SecurityFoundation -framework Security"
$ ./configure
$ make
$ sudo make install

Use newly installed ssh-agent

$ sudo nano /System/Library/LaunchAgents/org.openbsd.ssh-agent.plist
/usr/bin/ssh-agent > /opt/openssh/bin/ssh-agent

$ sudo launchctl unload /System/Library/LaunchAgents/org.openbsd.ssh-agent.plist
$ sudo launchctl load /System/Library/LaunchAgents/org.openbsd.ssh-agent.plist

Set alias

$ echo "alias ssh=/opt/openssh/bin/ssh" >> ~/.bash_profile


(verify with “ssh -V”)

Hunspell spell checking under PHP with enchant

The spell checking that works perfectly on Google Chrome, OpenOffice and Mozilla Firefox is available to you and PHP as well – all thanks to open source software!

The above mentioned apps use the “Hunspell” library, which can be used directly under PHP without the usage of ugly (and unsecure) exec/system calls.

The following steps I did on my OSX MPB (10.10 / Yosemite) but they will be very similar on any Linux/Unix system (well, might even be easier on Ubuntu or Debian via their package system).
Just make sure you at least use libenchant 1.5

Compile and Install hunspell 

$ wget 
$ tar xvfz hunspell-1.3.3.tar.gz
$ cd hunspell-1.3.3
$ ./configure
$ make
$ sudo make install

Compile and Install libenchant 

$ wget 
$ tar xvfz enchant-1.6.0.tar.gz
$ cd enchant-1.6.0
$ ./
$ ./configure
$ make
$ sudo make install

Compile and Install php-enchant (in this case as shared lib)

(there is currently a bug in the configure file that will not recognize your libenchant version and thus not giving you some of the newer features, patch is here)

$ cd php-5.5.14/ext/enchant/
$ phpize
$ ./configure
$ make
$ sudo make install

Something something in your php.ini… Dictionaries

$ cd Dicts
$ sudo wget
$ sudo tar xvfz master.tar.gz

Sample usage 

Compile libffi under OSX (10.10 / Yosemite)

Sometimes when playing around and compiling stuff you can mess up your system badly.

In this case I was compiling libffi on my OSX 10.10 system without knowing that other Apps were linking to it – especially Adobe Acrobat Reader (but it seems as Skype is also depending on it). Unfortunately it is linking to a 32bit version of that library and thus crashing on startup (though the screenshot is actually from after I deleted the library out of frustration).

Libffi is distributed by Apple/OSX directly, so it won’t help to re-install Adobe Acrobat Reader or Skype, instead you will just have to recompile it!

I would not consider it a common problem as most MacBook Fanboys do not even know what a terminal is, but just in case, here are the steps to create a fat file (e.g. universal binary supporting 32bit and 64bit architecture) of libffi for your OSX 10.10 (Yosemite) system:


Download libffi and prepare

$ wget 
$ tar xvfz libffi-3.1.tar.gz
$ cd libffi-3.1
$ rm -rf ~/libffi
$ mkdir -p ~/libffi/32 ~/libffi/64

Compile libffi as 32bit

$ make clean
$ CXXFLAGS=-m32 CFLAGS=-m32 LDFLAGS=-m32 ./configure --prefix=/usr --build=i386-apple-darwin14.0.0
$ make
$ cp i386-apple-darwin14.0.0/.libs/* ~/libffi/32

Compile libffi as 64bit

$ make clean
$ CXXFLAGS=-m64 CFLAGS=-m64 LDFLAGS=-m64 ./configure --prefix=/usr --build=x86_64-apple-darwin14.0.0
$ make
$ cp x86_64-apple-darwin14.0.0/.libs/* ~/libffi/64

Create Fat File/Lib aka “Universal Binary” and Install (poor mans version)

$ lipo -create ~/libffi/{32,64}/libffi.a -output /usr/lib/libffi.a
$ lipo -create ~/libffi/{32,64}/libffi.6.dylib -output /usr/lib/libffi.6.dylib
$ ln -s /usr/lib/libffi.6.dylib /usr/lib/libffi.dylib

All done! Now go enjoy your working system again… oh of course you could also use macports, I guess..

Compile Lighttpd with LibreSSL

As LibreSSL is gaining popularity you might want to switch your compiled Lighttpd version with one that uses LibreSSL for your https.

Tested on Debian Squeeze, but should work on Wheezy/Ubuntu in a similar way.


$ sudo apt-get install make gcc libev-dev libpcre3-dev zlib1g-dev libbz2-dev gamin libgamin-dev liblua5.1-0-dev
$ wget
$ tar xvfz libressl-2.0.5.tar.gz && tar xvfz lighttpd-1.4.35.tar.gz

Compile & Install LibreSSL

We are installing it in a non-standard path so it won’t interfer with your existing openssl/libssl(-dev)

$ cd libressl-2.0.5
$ ./configure --prefix=/opt/libressl
$ make
$ sudo make install

Verify the LibreSSL Installation

$ /opt/libressl/bin/openssl version
LibreSSL 2.0

Compile Lighttpd with LibreSSL

$ cd ../lighttpd-1.4.35
$ wget
$ patch -p1 < lighttpd-libressl.patch
$ ./configure
$ make
$ sudo make install

Verify the Lighttpd Installation

$ lighttpd -v
lighttpd/1.4.35 (ssl) - a light and fast webserver
Build-Date: Aug 11 2014 12:54:04

Please have a look at the following URLs for further Documentation on configuring Lighttpd + SSL:

Parallel/Asynchronous DNS resolving in PHP

In PHP one key for a scalable and performant web application is parallelism, whenever and wherever possible, even if you use queues. The most popular usage of parallelism in PHP is probably curl_multi_*.
In this post I will show you how to do multiple DNS requests lightning fast with two different approaches / PHP extensions.

In both cases the DNS requests are done asynchronously, meaning even with multiple requests the whole process will only take as long as the longest request takes (in theory).

PHP’s internal DNS functions rely on resolv.conf and in most cases it is not heavily optimized, defaulting to a rather long timeout of 5 seconds.
So even if you are only needing single DNS lookups both extensions might still be interesting as you can dynamically change the behavior of that, which what PHP is all about, or?


pecl-ares offers PHP bindings for the c-ares library (affiliated with cURL).
I was happy that Michael Wallner (you might know him for pecl-http) offered help to revive the code, as it has not had a release since 4 years. So to get it running with the current c-ares version and a modern system, you should have a look at its git.
pecl-ares also allows the usage of callbacks which might be useful for certain scenarios.

Installation (assuming php-fpm)

$ sudo apt-get install libc-ares-dev php5-dev
$ git clone php-ares
$ cd php-ares
$ phpize
$ ./configure
$ make
$ sudo make install
$ sudo echo "" > /etc/php5/mods-available/ares.ini
$ sudo php5enmod ares


It does not offer yet any documentation, but the source code is easy to understand, so anyways here is an example:


$ares = ares_init([
'timeoutms' => 2000,
'tries' => 1,
//'udp_port' => 53,
//'tcp_port' => 53,
'servers' => [''],

$q = [];
$q[] = ares_query($ares, null, '', ARES_T_A);
$q[] = ares_query($ares, null, '', ARES_T_A);

do {
$n = ares_fds($ares, $r, $w);
ares_select($r, $w, 100);
ares_process($ares, $r, $w);
} while ($n);

foreach ($q as $query) {
var_dump(ares_result($query, $errno, $errstr));



php-rdns offers OOP PHP bindings for librdns (same guy behind rspamd) and uses libev for event looping. “We” recently developed it for a client of ours and released it as open source. It is highly simplified and some things might not yet be implemented or working correctly, but if you are interested we are always happy to see a pull request. Initial development was done by Alexander Solovets and later bug-fixing by Eduardo Silva (lead dev/founder of monkey webserver).

Installation (assuming php-fpm)

$ sudo apt-get install libev-dev php5-dev
$ wget
$ tar xvfz rdns-0.1.1.tgz
$ cd rdns-0.1.1/
$ phpize
$ ./configure
$ make
$ sudo make install
$ sudo echo "" >> /etc/php5/mods-available/rdns.ini
$ sudo php5enmod rdns
$ /etc/init.d/php-fpm restart


(full  documentation on GitHub)


$rdns = new RDNS;

$rdns->addRequest('', RDNS_A, 2);
$rdns->addRequest('', RDNS_A, 2);
$replies = $rdns->getReplies();


You might also be interested in ReactPHP or swoole, which are event-driven solutions to this problem.