|

Deploying a Symfony project on Scaleway Functions

I’ve mentioned it several times on this blog: I care about using and hosting my tools on French or European infrastructure. For simple static sites, I usually use Alwaysdata hosting, and I run VPS servers on Scaleway infrastructure.

I recently wanted to deploy a small, low-traffic Symfony application. For my own reasons, I didn’t want to host it on an existing VPS: I’d rather isolate it on its own machine. But since it sits idle about 95% of the time, spinning up yet another VPS felt like overkill.

Given these constraints, serverless looks like a great fit and Scaleway offers Serverless Functions.

In the Symfony ecosystem, the Symfony Runtime decouples the bootstrapping logic from any global state to make sure the application can run with runtimes like PHP-PM, ReactPHP, Swoole, FrankenPHP and more, without any changes.

So, I’ve created the jdecool/scaleway-runtime project.

Installing it is very easy:

composer require jdecool/scaleway-runtime
vendor/bin/scaleway-init

The first command doesn’t need any explanation: it installs the runtime in your project. The second one generates a handler.php file at the project root. It’s the entry point of the function.

<?php

require __DIR__.'/vendor/autoload.php';

function handle(array $event, mixed $context): array
{
    return JDecool\ScalewayRuntime\Handler::handle($event, $context);
}

And that’s it! You’re ready to run your Symfony application on Scaleway Serverless Functions. You just need to deploy it.

How does it work? When an HTTP request is received, it’s turned into a Symfony Request and passed to the project’s Kernel, which returns a Response. This Response is then converted into the expected platform format.

The library also handles assets. They can be served directly by the runtime itself, even if it’s not the best choice. But it lets your project work without any extras. An Object Storage solution is still a better option.

Beyond that, there are a few extra tools provided:

  • scaleway-package builds the ZIP archive to deploy,
  • scaleway-doctor checks, before deploying, if your dependencies are compatible with the target Serverless Functions runtime (PHP version and loaded extensions),
  • scaleway-serve runs a local emulator. It builds events identical to the platform’s and keeps the kernel alive between requests, just like a Scaleway process would.

If you want to see an example, I’ve built a demo application that’s ready to deploy: https://github.com/jdecool/scaleway-functions-whois.

Jérémy DECOOL

Jérémy DECOOL

As a software architect, I share my thoughts on best practices in software development, software architecture and team organization for maintainable and scalable projects.