Phpmyadmin is not working

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

a. System environment:

I just downloaded and installed it on my VPS in /usr/share/phpMyAdmin/.

b. Command:

sudo systemctl restart caddy

c. Service/unit/compose file:

[yves@sd-163808 phpMyAdmin]$ cat /usr/lib/systemd/system/caddy.service
# caddy.service
# For using Caddy with a config file.
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
# See for instructions.
# 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.


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

[yves@sd-163808 phpMyAdmin]$

d. My complete Caddyfile or JSON config:

[yves@sd-163808 phpMyAdmin]$ cat /etc/caddy/Caddyfile

log {
  output file /var/log/caddy/access.log {
    roll_keep_for 8760h

root * /opt/tabulos

php_fastcgi /phpmyadmin/* unix//run/php-fpm/www.sock  {
  root /usr/share/phpMyAdmin/

php_fastcgi unix//run/php-fpm/www.sock 
[yves@sd-163808 phpMyAdmin]$

3. The problem I’m having:

I am trying to have phpmyadmin working on my machine. I though it would be a good idea to implement it as a specific route on my domain name: Bienvenue sur Tabulos for instance. So I added the following directive in my caddy file:

php_fastcgi /phpmyadmin/* unix//run/php-fpm/www.sock  {
  root /usr/share/phpMyAdmin/

Then I pointed to from my browser, and as a result the page remains all blank. What is surprising is that I get a lot of error in the javascript console.

Actually, from what I see, I have an error for each css ressource, like this one:

Did not parse stylesheet at '' because non CSS MIME types are not allowed in strict mode.

And for each javascript file, I have an error message looking like that:

Refused to execute as script because "X-Content-Type-Options: nosniff" was given and its Content-Type is not a script MIME type.

Moreover, if I look into the response header, I can see that the Content-Type is set to:

Content-Type: text/html; charset=utf-8

for each of those two files, and for any file I am trying to look at. There’s even four files (logo images) who all four see their Content-Type set to text/html. So I guess that every response set its Content-Type to text/html.

Even though I am not a web developper, I guess it’s not the correct value… So I guess there’s an issue with the correct Content-Type answered by Caddy. (Am I wrong or right?)

4. Error messages and/or full log output:

There’s a lot of lines in the caddy log file. If you ask for it specifically, I can make the effort to copy/paste it here. For instance for the file printview.css, if you ask for it.

5. What I already tried:

I’ve tried to solve my issue by rewriting the Content-Type header at the fly with some directives. I’ve wrote that in my configuration file:

header /phpmyadmin/*.js {
  Content-Type 'text/javascript'

But it did not worked. (I think I am far from mastering the CaddyFile) How would you do to make Caddy specify the correct Content-Type?

6. Links to relevant resources:

The problem is that file_server ends up not having the right root when serving phpmydmin requests. Instead of using a matcher on php_fastcgi, you should use one on root so that you set the root for both php_fastcgi and file_server on each request rather than just for one of them.

root /phpmyadmin/* /usr/share/phpMyAdmin/
root * /opt/tabulos

uri /phpmyadmin/* strip_prefix /phpmyadmin

php_fastcgi unix//run/php-fpm/www.sock 

You also need the strip_prefix because otherwise the path would be appended to the root and you would end up with /usr/share/phpMyAdmin/phpmyadmin as your base filepath.

1 Like

Indeed the page is loading gracefully. The login form is displaying correctly. There’s no longer any errors in the console log. Everything is fine.

But I will need to understand this whole machinery… Because I copied/pasted your solution blindly…

1 Like


  • On requests to /phpmyadmin/*, the root is set to /usr/share/phpMyAdmin/
  • On requests to anything else, the root is set to /opt/tabulos.
  • Since file_server assembles the file path it looks for on disk by taking root and appending the request path to it, then a request to /phpmyadmin/foo.js would look on disk for /usr/share/phpMyAdmin/phpmyadmin/foo.js, which will not work because that’s not a path that exists on disk.
  • To solve this, uri strip_prefix is used to remove the extra /phpmyadmin from the front of the path. The root is already decided and that’s the only part that matters, so it’s okay to do this.
  • The php_fastcgi directive will then do its thing, including looking on disk for PHP files or falling back to an index.php. If it’s a PHP file, it’ll send it to php-fpm to execute it. Otherwise the request falls through
  • The file_server will handle any requests to things that aren’t PHP files, like .js and .css, etc, and serve them appropriately.

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