Php_fastcgi env directive

1. The problem I’m having:

I would like to pass an environment var to php-fpm, namely to use a proper envelope sender per domain and play nicely with postfix-DKIM email signing.

However I might not be understanding the syntax from the documentation as I get a parsing error doing ‘caddy validate’.

2. Error messages and/or full log output:

Error: adapting config using caddyfile: parsing caddyfile tokens for 'php_fastcgi': /etc/caddy/Caddyfile.d/web.caddyfile:4 - Error during parsing: Unexpected token '{', expecting argument

3. Caddy version:

v2.6.4

4. How I installed and ran Caddy:

rpm package installation

a. System environment:

AlmaLinux 9, x86_64

b. Command:

caddy validate

d. My complete Caddy config:

MYSITE.com {
    tls MYEMAIL
    root * /var/www/MYSITE.com/
    php_fastcgi unix///run/php-fpm/www.sock {
      env PHP_VALUE {sendmail_path = /usr/sbin/sendmail -t -i -f postmaster@MYSITE.com -F postmaster}
    }
    file_server
    encode gzip

    log {
       output file /var/log/caddy/MYSITE-access.log {
           roll_size 10mb
           roll_keep 5
           roll_keep_for 720h
       }
    }

    @disallowed {
        path *.sql
        path /wp-content/uploads/*.php
        path /wp-content/wpvividbackups/*
    }

    rewrite @disallowed '/index.php'
}

5. Links to relevant resources:

Please use the latest version, v2.8.4.

The env here isn’t for php.ini type config, it’s for FastCGI variables passed to the PHP process, i.e. the stuff that appears in $_SERVER in PHP.

Also, you would need to wrap the value in quotes for it to be a single argument. Spaces in the Caddyfile separate arguments. See Caddyfile Concepts — Caddy Documentation

Single quotes are not valid in the Caddyfile. Either use double quotes, or no quotes at all.

2 Likes

Hi,

thanks for the reply. Indeed I botched completely the syntax by using the { } - I stumbled on this issue from GitHub and perniciously took inspiration from it.

And yes, I did want to add that to the $_SERVER array.

I updated to the COPR repository version as I was still experimenting with the EL9 repo package.

Oh, thanks for the tip on the rewrite directive as well.

The {} stuff is placeholders.

1 Like

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