Just getting my feet wet (setting up a dev environment) with a php:fpm container and using caddy fastcgi directive.
I’ve got it working but the directive is not rewriting a relative url and thus it’s not loading index.php. Looking at the docs it looks like that directive is supposed to do that so wondering what i am missing here?
caddy is not running in a container. It’s running directly on my dev box as a systemd service that runs a script as I said.
if I use root * /path/per/container/volume/pwd/src in caddy it can’t find anything
if I use root * /app/data the directory inside the fpm container then at least it “kinda” works.
ok on the template but sometimes filling out “everything” just clouds this issue. I have this script and service running on multiple machines with dozens of stanzas without issues.
# caddy@.service
# For using Caddy2 and a caddyfile.
# Using caddy repository at @d see @d/README.md
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target
[Service]
# base directory must be hard coded
User=caddy
Group=caddy
WorkingDirectory=@d
ExecStart=@d/scripts/caddy %i
ExecReload=@d/scripts/caddy %i reload
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
#!/bin/bash
SDIR=$(dirname "$(readlink -f "$0")") || exit
DIR=$(dirname "$SDIR") || exit
INSTANCE=${1:-default}
source $SDIR/library
echo $SDIR
get-caddy-bin # this sets $CADDY_BIN
CONF_DIR=$DIR/conf/$INSTANCE
CONF_SHARED_DIR=$DIR/conf/_shared
CONF=$CONF_DIR/caddy.conf
SCRIPT=$CONF_DIR/script
BIN=$DIR/bin/$CADDY_BIN
echo running caddy $BIN
[ ! -f "$BIN" ] && echo binary file $BIN does not exist && exit 1
[ ! -x "$BIN" ] && echo binary file $BIN is not executable && exit 1
[ ! -f "$CONF" ] && echo no configuration file $CONF && exit 1
if [ -f "$SCRIPT" ]; then
source $SCRIPT
fi
if [ ! $INVOCATION_ID ]; then
CAP="cap_net_bind_service+eip"
ISSET=$(getcap $BIN | grep $CAP )
if [ ! "$ISSET" ]; then
echo binary $BIN not set for binding port 80 by non-root users, attempting to set
sudo setcap $CAP $BIN
ISSET=$(getcap $BIN | grep $CAP)
echo after $ISSET
[ ! "$ISSET" ] && echo unable to set port binding && exit 1
fi
echo running caddy from commandline, enter caddy user password
su -c "$BIN run --config $CONF --adapter caddyfile" caddy
else
echo running caddy via systemd service
$BIN run --config $CONF --adapter caddyfile
fi
That solved it. Didn’t realize that I could have two roots like that (and why). Now I know.
For anyone reading this (per other posts I read) inside the container and out I used www-data for owner and group for the /src directory and then added caddy user to www-data group on my dev box. I did set write permissions for the group on that directory. Don’t know if that is necessary or if read is sufficient.
Nice! now I have a quick way to spin up a php dev or production environment with a particular fpm version. Thx yet again @francislavoie and @matt