[DOCKER] Run Laravel-admin on Golang PHP application server RoadRunner

New trends in application servers

In the PHP area these days, there are a few HTTP servers or application servers for PHP that have different execution methods from the conventional configuration by common Apache + mod_php and PHP-FPM, as represented by Swoole. It is getting more and more attention.

RoadRunner

RoadRunner is one such emerging application server, written in Go language. The HTTP request is handled by Go's HTTP handler in the previous stage, and the load balancer/process manager allocates the request to the PHP Worker.

In addition to the regular HTTP server, the implementation of gRPC server by RoadRunner is also open to the public, showing new possibilities for PHP.

Try RoadRunner

RoadRunner also supports Laravel, and packages for Laravel have also been developed.

This time, I would like to implement RoadRunner based on this.

RoadRunner installation

First, install the package with the following command.

# roadrunner
composer require spiral/roadrunner "^1.8"
# roadrunner-laravel
composer require spiral/roadrunner-laravel "^3.4"

Next, execute the following command to create a package configuration file (./config/roadrunner.php).

php artisan vendor:publish --provider='Spiral\RoadRunnerLaravel\ServiceProvider' --tag=config

Create .rr.yml

Write a roadrunner configuration yml file.

Set to start on port 80.

env:
  APP_REFRESH: true
http:
  address: 0.0.0.0:80
  http2:
    enabled: true
    h2c: true
    maxConcurrentStreams: 128
  workers:
    command: 'php ./vendor/bin/rr-worker'
static:
  dir: public
reload:
  interval: 1s
  patterns: [ '.php' ]
  services:
    http:
      dirs: [ '' ]
      recursive: true

Various minor corrections

logging.php

'stdout' => [
    'driver' => 'monolog',
    'handler' => StreamHandler::class,
    'with' => [
        //php://If you set it to stdout, an error will occur and it will be moss, so php://Change to stderr
        'stream' => 'php://stderr',
     ],
     'level' => 'debug',
],

Add script to composer.json.

"scripts": {
        "roadrunner:dev": [
            "composer dump-autoload",
            "./rr serve -v -d"
        ],
        "roadrunner:prod": [
            "./rr serve"
        ],
        "roadrunner:setup": [
            "rr get-binary"
        ],
    }

Put the startup command in startup.sh

# roadrunner
composer roadrunner:setup
chmod +x rr
composer roadrunner:dev

This completes most of the settings.

Try to start

Follow the steps below to start it.

cp docker-compose.example.yml docker-compose.yml

docker-compose up -d

I was able to start it safely.

スクリーンショット 2020-11-27 12.59.30.png (168.6 kB)

Summary

This time, I used PHP web / application server made by Golang. I made a sample. It's interesting, but it's unstable, so I don't recommend using it in a production environment.

References

https://nextat.co.jp/staff/archives/235

Recommended Posts

Run Laravel-admin on Golang PHP application server RoadRunner
Run a Linux server on GCP
Run TensorFlow2 on a VPS server
Run Jupyter notebook on a remote server
Run python wsgi server on NGINX Unit
Run the task in the background on the sshed server
Golang on jupyter
Run CGI written in python on Sakura's rental server
How to run Django on IIS on a Windows server