Explain Like I’m 5 PHP Developers
Roadrunner works by creating a HTTP server with Golang’s excellent net/http package, and using Goridge as a bridge to pass PSR7 Request and Responses between PHP and Go. The PHP application is then a long-running, already bootstrapped PSR7-capable application that received the already parsed PSR7 request, dispatches it, and collects the response to give back into Go. 
Roadrunner offloads unnecessary operations from PHP to a more optimized server, and effectively swaps out the classic setup of Nginx+FPM with a PHP/Golang application that boosts flexibility and performance. 
Roadrunner can serve static files without the presence of Nginx, therefore, simplifying the creation of Docker containers. 
Spiral is a PHP Framework with a customized Roadrunner server. The main difference is that, when you use Spiral’s version of Roadrunner, it comes with more out-of-the-box solutions for PHP developers, Ie.
- Spiral: spiral/framework/blob/master/main.go
- Roadrunner: spiral/roadrunner/blob/master/cmd/rr/main.go
It’s possible to download the server pre-compiled, but that takes away our power of writing Go code. In this tutorial we start from scratch.
The instructions are for Mac, and assume you already have Docker Desktop installed, but the same concepts should work for Linux, and probably Windows.
Create a directory for your project.
(If you want, replace hello-spiral with some other name.)
Create a subdirectory called ./server/ and copy these files into it:
cd ~/hello-spiral mkdir server cd server wget https://raw.githubusercontent.com/spiral/framework/master/main.go wget https://raw.githubusercontent.com/spiral/framework/master/go.mod
Download this Dockerfile into the root dir of ~/hello-spiral
The first stage compiles the app server, the second stage installs the Spiral skeleton app.
Your file tree should look like this:
Build a new Docker image:
cd ~/hello-spiral docker build -t hello-spiral .
Run the new Docker image:
docker run -it -p 8080:8080 -p 2112:2112 hello-spiral
Go to http://localhost:8080 and verify that it works.
Tada! It runs, but how do we develop?
Let’s copy all the PHP files that were successfully installed in the container to our host, then mount them.
While the container is still running from Step 5, in another shell, do:
cd ~/hello-spiral docker ps
This command will output your container ID:
Use your ID in the next command (replace 1f057ae4e473 with your own id):
docker cp 1f057ae4e473:/var/www/app/. src
In the shell tab that is still running the server, stop the server (ctrl-c), then restart with a slight variation of the command from Step 5:
docker run -it -p 8080:8080 -p 2112:2112 -v "$(pwd)"/src:/var/www/app:cached hello-spiral
Your local PHP files are now mounted in ~/hello-spiral/src, start developing! Change your Dockerfile:
# Setup Spiral # RUN composer create-project spiral/app . --no-scripts # Or comment above, uncomment below, and copy Spiral COPY ./src/ .
If you make changes in ~/hello-spiral/server, rebuild!