How to Use FrankenPHP, the Powerful PHP Server Written in Go

Crafted by Frenchman Kévin Dunglas, a long-time contributor to the PHP ecosystem and member of the Symfony Core Team, FrankenPHP might just rejuvenate your old, tired LAMP server.

It is a modern PHP application server developed in Go, relying on the cutting-edge Caddy web server. According to its creator, all your PHP projects, including Laravel, Symfony, Drupal, WordPress, Sulu, and API Platform, will be optimized like never before thanks to the native integration of the worker mode.

Less slowness, more performance, and especially plenty of advanced features such as Early Hints for lightning-fast display, support for HTTP/2 and HTTP/3 for optimal browsing, Brotli, Zstandard, and Gzip compression, structured logs, Prometheus support for metrics, and even real-time with Mercure. Whether you’re addicted to Symfony, a fan of API Platform, or a die-hard Laravel enthusiast, FrankenPHP handles it all. According to benchmarks visible on the official site, it even boosts performance up to 3.5 times faster than FPM on API Platform-type applications.

Designed with simplicity in mind, this PHP server only needs a single service and a single binary. No need for PHP-FPM, it uses its own specially designed SAPI (Server API) for Go web servers. It can be easily deployed as a Cloud Native application via a Docker image and is compatible with Kubernetes and all modern Cloud platforms. You can even package your PHP application as a standalone, self-executable static binary.

If you want to test it, you can either run the binary or use Docker like this:

docker run -v $PWD:/app/public -p 80:80 -p 443:443 -p 443:443/udp dunglas/frankenphp

In no time at all, you’ll have a web server + PHP 8.2 all set up! Just put your PHP files in the Franken directory and ta-da…

If you opt for the binary, you can serve the contents of the current directory with the following command:

./frankenphp php-server

Or run your scripts from the command line like this:

./frankenphp php-cli /path/to/your/script.php

In short, you start your app once, and it stays in memory, ready to run your site. Caddy manages HTTPS automatically with certificate generation, renewal, and revocation. It also serves assets while PHP does what it does best: execute your code flawlessly. You can even integrate PHP into any Go application as a library.

And to start a production Caddy server with FrankenPHP without using Docker, you just need this super simple configuration:

    # Enable FrankenPHP
    order php_server before file_server

localhost {
    # Enable compression (optional)
    encode zstd br gzip  
    # Execute PHP files in the current directory and serve resources

It changes things up a bit!

Mohamed SAKHRI
Mohamed SAKHRI

I'm the creator and editor-in-chief of Tech To Geek. Through this little blog, I share with you my passion for technology. I specialize in various operating systems such as Windows, Linux, macOS, and Android, focusing on providing practical and valuable guides.

Articles: 1310

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *