Laravel Octane: Compiling RoadRunner from Source
Tags: go, php, laravel, roadrunner
Published: 2021-08-20 13:31:46

---
title: Laravel Octane: Compiling RoadRunner from Source
published: true
date: 2021-07-25 15:01:07 UTC
tags: go,php,laravel,roadrunner
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/1024/0*bCkW1s4_DfpuR_DE)<figcaption>Photo by <a href="https://unsplash.com/@the_gerbs1?utm_source=medium&amp;utm_medium=referral">Jean Gerber</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

[_RoadRunner_](https://roadrunner.dev/) is one of the two options available for use with [_Laravel Octane_](https://laravel.com/docs/8.x/octane) a new package released during 2021 as a way to speed up requests significantly.

_RoadRunner_ itself is an open source _PHP_ application server written in the language [_Go_](https://golang.org/) (or known as _Golang_ should you wish to get decent search results from google). Much like _Apache_ or _Nginx_ & _PHP-FPM_, HTTP requests can be sent to _RoadRunner_ to execute _PHP_ code and then send a response back in returned. The difference in _RoadRunner_ is that it can keep aspects of the _PHP_ application in memory for far better speed after the booting of the application. For _Laravel_ this is fairly beneficial.

Normally when you install Octane and pick RoadRunner, the rr binary will be downloaded for you which is executable for the server.

### Why compile your own version?

_RoadRunner_ itself is built in a reasonably modular way with it’s own service container and plugin mechanism that provides a lot of potential for expansion. The first example of this is in exposing _Go_ services to the _PHP_ code via a built in _RPC_ server which can act similarly to a _PHP_ extension. The second is the ability to apply middleware to Requests in much the same way _Laravel_ can. With _Go_ itself being a fairly easy language to pick up and write performant code in this all makes for a winning combination.

### Getting Started

The first thing you’ll need to do is make sure you have _Go_ installed and that it’s version is greater than 1.13. At the time of writing the latest version is 1.16. If you have _Go_ installed but don’t know the version you have, you can check with go version. If it’s not installed already you can download it from the [_Golang_ site](https://golang.org/dl/) or as a Mac user I prefer to install it via _brew_. Also for good measure you should have a git client to use for cloning repos from _GitHub_.

For the sake of this article and testing something with the final end product you should set up a [_Laravel Octane_ project](https://laravel.com/docs/8.x/octane#installation) with _RoadRunner_ and test it’s all working as you would expect before continuing. If you want a short cut, I’ve made a [demo repo](https://github.com/peterfox/octane-custom-roadrunner-demo) with _Octane_ already install that you can clone.

Then to get starting with _RoadRunner_ itself what we’ll need to do is clone the _RoadRunner_ binary source code. The easier way to do this is with _git_ but there’s no reason you can’t download the source code as a zip file.

```
git clone [https://github.com/spiral/roadrunner-binary](https://github.com/spiral/roadrunner-binary)
```

Once we’ve done that we need to download all the dependencies required to compile the binary. This is fairly similar to how we use composer for _PHP_ packages. We do this via the go mod commands.

```
go mod download
```

This should then give you all the dependencies for doing a simple complication of _RoadRunner_.

The build command itself will be needed to run on the platform you intend to be using. For instance if you’re developing on a _Mac_ and deploying to a _Linux_ server the binary file generated won’t work. You’ll need to have a _Linux_ environment to compile _RoadRunner_ in.

The command to build _RoadRunner_ is:

```
go build -trimpath -ldflags “-s” -o ./rr ./cmd/rr
```

This should leave you with a rr file in the director that is the self contained application server binary. We can then copy this to our Laravel application (with _Octane_ already installed and set up for _RoadRunner_ of course) and then you can execute the artisan octane:start command and everything should run as normal. You will notice a remark at the start of the command though, _“Unable to determine the current RoadRunner binary version. Please report this issue:_ [_https://github.com/laravel/octane/issues/new._](https://github.com/laravel/octane/issues/new.)_”_. This is to be expected though as we’re no longer using a release version but our own custom binary.

Now obviously we haven’t achieved anything huge here, the binary compiled is practically the same one that _Laravel Octane_ itself installs into your application for the purpose of running with _Octane_ but now we have this process down we can start looking at customising the code ourselves and implementing our own plugins.

I hope to cover getting started with _RoadRunner_ plugins very soon so please do follow me on social media for the next installments.

I’m Peter Fox, a software developer in the UK who works with Laravel among other things. Thank you for reading my article, I’ve got several more on both medium and dev.to. If you want to know more about me, head over to [https://www.peterfox.me](https://www.peterfox.me/). Also feel free to follow me @[SlyFireFox](https://twitter.com/SlyFireFox) on twitter for more Laravel tips and tutorials in the future.