Laravel Octane on Heroku

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.

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store