[Solved] phpMyAdmin as subdirectory of localhost

1. Caddy version (caddy version):


2. How I run Caddy:

As systemd service, with caddy as user

a. System environment:

Fedora 34, systemd

b. Command:

/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile

c. Service/unit/compose file:

# caddy.service
# For using Caddy with a config file.
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

Description=Caddy web server

ExecStartPre=/usr/bin/caddy validate --config /etc/caddy/Caddyfile
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile


d. My complete Caddyfile or JSON config:

# The Caddyfile is an easy way to configure your Caddy web server.
# https://caddyserver.com/docs/caddyfile

# The configuration below serves a welcome page over HTTP on port 80.  To use
# your own domain name with automatic HTTPS, ensure your A/AAAA DNS record is
# pointing to this machine's public IP, then replace `http://` with your domain
# name.  Refer to the documentation for full instructions on the address
# specification.
# https://caddyserver.com/docs/caddyfile/concepts#addresses
http:// {

    # Set this path to your site's directory.
    root * /usr/share/caddy

    # Enable the static file server.

    # Another common task is to set up a reverse proxy:
    # reverse_proxy localhost:8080

    # Or serve a PHP site through php-fpm:
    # php_fastcgi localhost:9000

    # Refer to the directive documentation for more options.
    # https://caddyserver.com/docs/caddyfile/directives


# As an alternative to editing the above site block, you can add your own site
# block files in the Caddyfile.d directory, and they will be included as long
# as they use the .caddyfile extension.
import Caddyfile.d/*.caddyfile

3. The problem I’m having:

Not able to achieve serving phpMyAdmin as subdirectory of localhost with php-fpm. That is access phpMyAdmin with URL like http://localhost/phpmyadmin

Have my phpmyadmin folder in /var/www/html/phpmyadmin

4. Error messages and/or full log output:


5. What I already tried:

Have tried already mentioned solutions in this forum and many other google searches, but nothing relevant for my use case.

I have already tried something like

http://localhost/phpmyadmin {
        root * /var/www/html/phpmyadmin/
        php_fastcgi unix//run/php-fpm/www.sock

I get a blank page. With some modifications I get 502 bad gateway.

Need your help. Thanks!

6. Links to relevant resources:


Path matching in Caddy is exact, so /phpmyadmin will only match exactly /phpmyadmin and nothing else.

But I don’t recommend using path matchers in site addresses, it more complicated than necessary. Best to use handle blocks, which reduce ambiguity in the config.

You’ll also need file_server so that Caddy serves the static files (like HTML, JS, CSS) that it’ll serve.

Also, I generally recommend using subdomains rather than subpaths. Many apps don’t behave well when proxied under a subpath (I know that phpmyadmin generally works well though). Explained here:

You can instead use a subdomain like phpmyadmin.localhost which will automatically resolve to on most Linux systems.

http://phpmyadmin.localhost {
	root * /var/www/html/phpmyadmin
	php_fastcgi unix//run/php-fpm/www.sock
1 Like

Hi @francislavoie, thank you for your explanation, this indeed works now. I had issues with php-fpm configs too. New to Caddy, but I must say I am liking it so far!

For anyone else who are facing same issues on Fedora 33 and above, please add caddy user to the below line in /etc/php-fpm.d/www.conf

listen.acl_users = apache,nginx

This block of Caddyfile config should now work

http://phpmyadmin.localhost {
	root * /var/www/html/phpmyadmin
	php_fastcgi unix//run/php-fpm/www.sock
1 Like

In Fedora the php-fpm daemon socket is owned by apache:apache, with these additional filesystem acls set for both the apache and nginx users. Have you considered filing a php bug to request an acl for the caddy user as well? That would allow this to work as soon as the packages are installed.

Alternatively, one could just add the caddy user to the apache group to solve the issue.


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