Running Grocy with Caddy

I am playing around with this web application Grocy (https://github.com/grocy/grocy) and currently trying to get it to work with Caddy.

I have a clean install of Manjaro Linux running in a VM and I have run the following commands to setup everything so far:

sudo pacman -Syu --noconfirm yay wget unzip
yay -Syu --noconfirm caddy sqlite php php-fpm php-sqlite

sudo sed -i 's/;extension=pdo_sqlite/extension=pdo_sqlite/g' /etc/php/php.ini
sudo sed -i 's/;extension=sqlite3/extension=sqlite3/g' /etc/php/php.ini

sudo systemctl start php-fpm
sudo systemctl enable php-fpm
sudo systemctl status php-fpm

wget -O grocy_latest.zip https://releases.grocy.info/latest

sudo unzip grocy_latest.zip -d /usr/share/grocy

sudo rm grocy_latest.zip

sudo cp /usr/share/grocy/config-dist.php /usr/share/grocy/data/config.php

sudo chown http:http /usr/share/grocy/data -R

Below is my caddyfile so far:

:9283 {
        gzip
        errors /var/log/caddy/grocy_error.log
        root /usr/share/grocy/public

        fastcgi / unix:/run/php-fpm/php-fpm.sock php {
                index index.php
        }

        rewrite {
                r .*
                ext /
                to /index.php?{query}
        }
}

This seem to work just fine with the default Grocy data/config.php file. Although any suggestion on how to improve it would be appreciated.

however, I would like to change the base url to /grocy so it will work with my existing reverse proxy. In the Grocy data/config.php file I have changed

Setting(‘BASE_URL’, ‘/’);

to

Setting(‘BASE_URL’, ‘/grocy’);

And restated caddy. This however did not work. Now when I go to http://ipaddress:9293/grocy I get
“Page Not Found”. Do I also have to make changes to the Caddyfile to make this work? Or there something else going on I am not understanding?

Thank you

When the web root is set to /usr/share/grocy/public, and Caddy receives a request for /grocy, Caddy will be looking in /usr/share/grocy/public/grocy. Have you tried moving the site files there?

The index index.php subdirective you have for fastcgi is redundant. You can remove it - the php preset sets this. https://caddyserver.com/docs/fastcgi#presets

Also, your rewrite - remove the regex. It matches literally everything, and you’re not using it for any captures. All this does is spin up the regex matcher, needlessly wasting CPU cycles. ext / is doing all the work here.

Thank you

Got it working

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