Skip to content

Instantly share code, notes, and snippets.

@mybigman
Forked from viezel/octane-on-forge.md
Created September 17, 2021 08:18
Show Gist options
  • Save mybigman/c2a32223f21ced568deed13a5511c889 to your computer and use it in GitHub Desktop.
Save mybigman/c2a32223f21ced568deed13a5511c889 to your computer and use it in GitHub Desktop.
Quickly get Octane running on Laravel Forge

Quickly get Octane running on Laravel Forge

  1. Spin up a new App server, choose PHP 8
  2. SSH into it and run sudo -i to become root
  3. Run pecl install swoole and enable what you need. (I disabled curl as it did not work for me)
  4. Add a new Site to your server and use git to pull in your Laravel project that has Octane installed.
  5. Point your DNS to your new site
  6. Enable SSL using Lets Encrypt
  7. Change your new Sites Nginx settings to (assuing your site is named octane.example.com):
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/octane.example.com/before/*;

upstream swoole-http {
    server 127.0.0.1:8000;
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name octane.example.com;
    server_tokens off;
    root /home/forge/octane.example.com/public;
    index index.php;
    charset utf-8;
    
    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/octane.example.com/server/*;

    location = /index.php {
        try_files /not_exists @swoole;
    }

    location / {
        try_files $uri $uri/ @swoole;
    }

    location @swoole {
        set $suffix "";

        if ($uri = /index.php) {
            set $suffix ?$query_string;
        }

        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        proxy_pass http://swoole-http$suffix;
    }
}


# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/octane.example.com/after/*;
  1. Change the deploy Script to:
cd /home/forge/octane.example.com
git pull origin master
$FORGE_COMPOSER install --no-interaction --prefer-dist --optimize-autoloader --no-dev
$FORGE_PHP artisan migrate --force
$FORGE_PHP artisan config:cache
$FORGE_PHP artisan route:cache
$FORGE_PHP artisan octane:reload
  1. Go to Daemons settings of the server
  • Command: php8.0 artisan octane:start --server=swoole --port=8000
  • User: forge
  • Directory: /home/forge/octane.example.com
  • Processes: 1
  • Start: 1

Now - go test out Octane and its speed 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment