Laravel Octane on Heroku

Craig Morris
2 min readApr 8, 2021

--

Laravel Octane is a new way of running Laravel applications at super high speeds:

“Laravel Octane supercharges your application’s performance by serving your application using high-powered application servers, including Swoole and RoadRunner. Octane boots your application once, keeps it in memory, and then feeds it requests at supersonic speeds.”

Swoole has a number of benefits over RoadRunner including Concurrent Tasks, Ticks / Intervals and The Octane Cache so we’ll concentrate on getting that up and running on Heroku.

These steps assume you have the following:

  • Laravel Installer
  • Heroku’s CLI installed and authenticated

Start off, by creating a new Laravel instance with Octane installed:

laravel new laravel-octane-heroku --git
composer require laravel/octane
php artisan octane:install
composer require "ext-swoole:*"
composer require "ext-pcntl:*"

Create a new Heroku app:

heroku create
heroku config:set APP_KEY=$(php artisan --no-ansi key:generate --show)

Let’s add a PHP Custom Platform Repo kindly provided by cachewerk/heroku-php-extensions which will allow us to install the Swoole extension

heroku config:set HEROKU_PHP_PLATFORM_REPOSITORIES="https://relaycache.com/heroku/"

Then let’s tell Heroku how to run our application via Octane, add the following Procfile

web: php artisan octane:start --server=swoole --host=0.0.0.0 --port=$PORT

Commit our files and push:

git commit --all
git push heroku main

Your Laravel app is now running via Heroku on Octane!

For more tips, check out my Ultimate Guide to running Laravel on Heroku.

--

--

Craig Morris
Craig Morris

Written by Craig Morris

Solutions Architect. Technical Lead. Full-stack Developer. http://craigmorris.io

No responses yet