How to php.ini with frankenphp via systemd and PHP_INI_SCAN_DIR on a VPS?

1. The problem I’m having:

I’m trying to work with frankenphp. Specifically I need to be able to load php.d files for configuration. According to phpinfo() no php.ini file is being loaded. The docs FrankenPHP: the modern PHP app server say " To load additional PHP configuration files, the PHP_INI_SCAN_DIR environment variable can be used. When set, PHP will load all the file with the .ini extension present in the given directories."

… but doesn’t explain how to actually do that. I looked at the Caddy documentation on Environment Variables and I couldn’t understand how that would relate.

2. Error messages and/or full log output:

N/A

3. Caddy version:

4. How I installed and ran Caddy:

frankenphp

a. System environment:

Alma Linux 9

b. Command:

systemctl start frankenphp

c. Service/unit/compose file:

[Unit]
Description=FrankenPHP Server
After=network.target network-online.target
Requires=network-online.target

[Service]
Restart=on-failure
Type=notify
User=frankenphp
Group=frankenphp
ExecStartPre=/usr/bin/frankenphp validate --config /etc/frankenphp/Caddyfile
ExecStart=/usr/bin/frankenphp run --environ --config /etc/frankenphp/Caddyfile
ExecReload=/usr/bin/frankenphp reload --config /etc/frankenphp/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddy config:

{
    # Enable FrankenPHP
    frankenphp

    # Logging
    log {
        output stderr
        level DEBUG
    }
}

dev.sportch.co.uk {
    # Enable compression (optional)
    encode zstd br gzip

    root * /var/www/html/app

    # Define a route for handling requests
    route {

        # Security: Hide specific paths
        @hide path /.env *.sql *.template /gtscripts/* *.txt *.md /random /support vapi/ var/ /support /system.* /lib
        respond @hide 404

        # Execute PHP files
        php_server

        # Rewrite subfolder requests for screenscrapers
        rewrite /ladder/* /ladder/index.php
        rewrite /manager/* /manager/index.php

         # Add WebSocket support
        @websocket {
            header Connection *Upgrade*
            header Upgrade websocket
        }
        reverse_proxy @websocket localhost:5502
    }
}

5. Links to relevant resources:

I don’t understand. I don’t think FrankenPHP is an installation method for Caddy. It’s a plugin for Caddy. Is it possible to get some more detail here?

Your unit file isn’t “N/A” if you’re using systemctl to run Caddy.

How to do it depends on how you installed and run Caddy.

If you installed Caddy via a distribution with systemd unit files included, or if you created your own unit file, you should be able to specify environment variables in there.

In Docker it’d be different but it seems like you’re running it natively.

1 Like

Frankenphp is a Caddy distribution. It is a plugin for Caddy but the way it works is that on installation it installs a version of Caddy that has the plugin available. So you end up with a /etc/frankenphp/Caddyfile and a frankenphp service, which is the caddy service.

Ok. Updated.

But how did you install it?

2 Likes

I figured it out. Just add this to the service unit file:

Environment=PHP_INI_SCAN_DIR=/etc/php.d/
1 Like

I followed these instructions: Install FrankenPHP on Linux | Daniel Gorbe | G⌬RBE

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.