Not sure how to proceed with moving WordPress installation between hosts

1. Caddy version (caddy version):

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

2. How I run Caddy:

a. System environment:

Ubuntu 20.04, systemd script (default one apt provided me with)

b. Command:

sudo systemctl restart caddy
#Or
sudo systemctl reload caddy

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

#Old host
www.mysite.eu mysite.eu {
    root /var/www/wordpress
    gzip
    tls someone@domain.tld
    fastcgi / /run/php/php7.0-fpm.sock php
    rewrite {
        if {path} not_match ^\/wp-admin
        to {path} {path}/ /index.php?_url={uri}
    }
}
#New host
http://www.mysite.eu, http://mysite.eu, https://www.mysite.eu {
        redir https://mysite.eu{uri} permanent
}

https://mysite.eu {
        root * /var/www/wordpress
        encode gzip
        file_server
        php_fastcgi unix//var/run/php/php7.4-fpm.sock
        log {
                level DEBUG
                output file /data/log/caddy_test.log {
                        roll_size 10MiB
                        roll_keep 10
                        roll_keep_for 336h
                }
        }

        @disallowed {
                path /xmlrpc.php
                path *.sql
                path /wp-content/uploads/*.php
        }
        rewrite @disallowed '/index.php'
}

3. The problem I’m having:

I have been trying to move my WordPress installation from an old host to a new host, where there is one significant difference: Old host was running caddyv1.0.4. I have also included that Caddy file up above.
I seem to get 404’s with wget, and a blank white screen using a regular browser.

4. Error messages and/or full log output:

Pastebin of error log (new host, since old host works fine): {"level":"error","ts":1612365608.4176836,"logger":"http.log.access.log0","msg":" - Pastebin.com

5. What I already tried:

A buddy helped me update my Cadddyfile to the newer way of doing things,
I have added the log directive to find out what was going on, that did not help me much hence I am asking here.
I followed this blog post, Serving WordPress with Caddy 2 - Thomas Bensmann, to no avail.

6. Links to relevant resources:

' is not a valid string delimiter in Caddy. Just remove the ' there. Caddy supports either " or ` (backtick)

But what you actually want is probably respond @disallowed 403 instead.

Caddy enables HTTP->HTTPS redirects automatically, so all you need is this:

www.mysite.eu {
	redir https://mysite.eu{uri} permanent
}

mysite.eu {
	...
}

Setting level DEBUG doesn’t really do anything useful here. What you want is to set the debug global option at the top of your Caddyfile:

{
	debug
}

Then run this command to see your logs:

journalctl -u caddy --no-pager | less

The log directive only gives you access logs, but not the rest. The rest is written to stdout, which you can see by looking at the journal, since you’re running as a systemd service.

I’m not sure what the source of the 404 is. It could be from the file_server handler, but I think more likely is from the wordpress app itself. The error logs may reveal more relevant info.

After reading, Primary script unknown I decided to try and run the old host’s config on the new host using the same caddy version (1.0.4), which pointed to the error described in that link. So I have now tried to edit the PHP-FPM configuration to allow Caddy to run with its own unix socket. Including setting up caddy to use its own socket, making sure that the socket is run under that users name, etc. That did not work, 404. Then I tried changing the user under which caddy runs when using systemctl start caddy to be www-data, which also did not work - again a 404. So I am at a loss now.
This leads to several questions, why can’t I run the same caddy version with the same config as the old host on the new host? Why won’t this setup run on the new host with its own unix socket/etc?
Is there anything else I can do to try and get it to work?

I think you also want to lose the / here, since that proxies ONLY / to PHP.

Because running very outdated software is a terrible idea. Caddy v1 is EOL. So is PHP 7.0. For that matter, PHP 7.3 is nearing EOL at the end of the year PHP: Supported Versions

Did you try what I suggested, to look at your logs?

That was from my old host. Which definitely is working. Thanks for the reply though :slight_smile:

1 Like

I agree that running outdated software is a bad idea, which is why I figured to update my set up when I am moving to a new host.

journalctl -u caddy --no-pager | less did not show anything useful, only old errors which are already resolved.

This is my current Caddyfile:

{
        debug
}

www.mysite.eu {
        redir https://mysite.eu{uri} permanent
}

mysite.eu {
        root * /var/www/wordpress
        encode gzip
        file_server
        php_fastcgi unix//var/run/php/php7.4-fpm.sock

        @disallowed {
                path /xmlrpc.php
                path *.sql
                path /wp-content/uploads/*.php
        }
        rewrite @disallowed '/index.php'
}

My bad. Am mobile today…

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