Tags:

Running Magento on FrankenPHP Webserver

FrankenPHP is the new star in webserver heaven and as Magento developer of course I wanted to try this out with Magento 1 / OpenMage. It turned out that it was very easy to setup and the results were really promising in local development environment. I have never seen a faster Magento on localhost!

Chris / / last updated on

FrankenPHP describes itself as

The Modern PHP App Server written in Go
It combines simple deployment (only 1 binary) with lightning fast performance. Under the hood it uses the Caddy webserver.
Some highlight features are e.g. HTTP/3, Early Hints and automatic HTTPS.

In order to make Magento 1 / OpenMage run on the new FrankenPHP webserver 2 steps are required:

  1. Patch Magento software to make it compatible
  2. Setup Docker container

Patch Magento / OpenMage

The following patch is required to make Magento work with FrankenPHP. It adds the frankenphp binary as allowed PHP SAPI name.

--- a/app/code/core/Mage/Core/Model/App.php	2023-10-02 09:56:26
+++ b/app/code/core/Mage/Core/Model/App.php	2023-08-28 09:58:22
@@ -359,7 +359,7 @@
         }
 
         // Finish the request explicitly, no output allowed beyond this point
-        if (php_sapi_name() == 'fpm-fcgi' && function_exists('fastcgi_finish_request')) {
+        if (\in_array(php_sapi_name(), ['fpm-fcgi', 'frankenphp']) && function_exists('fastcgi_finish_request')) {
             fastcgi_finish_request();
         } else {
             flush();
    

FrankenPHP + Magento Docker Setup

Next step is to create the Docker environment. For this we use the official Docker image dunglas/frankenphp:latest-php8.2-alpine.

Most important part here is the Caddyfile config which can look like this:

{
        {$CADDY_GLOBAL_OPTIONS}
        default_sni {$SERVER_NAME:localhost}
        debug

        frankenphp {
                {$FRANKENPHP_CONFIG}
        }
}

{$SERVER_NAME:localhost} {
    root * pub/default/
    
    route {
        @indexFiles file {
            try_files {path} {path}/index.php index.php
            split_path .php
        }
        rewrite @indexFiles {http.matchers.file.relative}

        @phpFiles path *.php
        php @phpFiles
        file_server

        respond 404
    }
}

I will publish the complete FrankenPHP setup on Github within the next days.


Post Comments to "Running Magento on FrankenPHP Webserver"

Submit Comment

With the use of this comment form you agree to the saving and processing of your data by this website. More information about the processing of your data can be found in our privacy statement.
Your data will be transmitted securely via SSL.

Meine Magento Extension Bestseller