there is a very simple (and working) library that does everything you need, namshi/jose.
We wrote it and released it to the public months ago, and is the auth mechanism behind our architecture.
To use it it's a matter of 2 minutes:
$jws = new JWS('RS256');
$jws->setPayload(array(
'somedata' => $yourData,
));
$privateKey = openssl_pkey_get_private("file://path/to/private.key", 'YOUR_PASSPHRASE');
$jws->sign($privateKey)
$jws = $jws->getTokenString();
There you go, now you can do whatever you want with the jwt.
If you want some more details, I blogged about this a while ago.
Cheers!