Month: September 2025

  • Fixing Loopback Request Issue in WordPress in Docker

    If Site Health shows “Your site could not complete a loopback request” (or The REST API encountered an error) when running WordPress in Docker behind a reverse proxy (e.g., Caddy), the culprit is often that extra_hosts entry pointing to a container IP that changes on restart. Which is always as a solution to solve the loopback issue.

    The fix (use a Docker network alias)

    Let Docker’s built-in DNS keep things in sync by giving your proxy container a network alias that matches your site’s domain. Then all other containers resolve the alias to the current IP automatically. Would be a better solution than specifying the internal IP for PHP container:

    services:
      caddy:
        # ...your existing caddy config...
        networks:
          default:
            aliases:
              - example.com

    Now remove any extra_hosts lines you previously added to other services (like php).

    Apply & verify

    # Recreate containers
    docker compose up -d
    
    # From the php container, confirm the alias resolves
    docker compose exec php getent hosts example.com
    
    # (Optional) Hit wp-cron directly
    docker compose exec php curl -I https://example.com/wp-cron.php?doing_wp_cron=1

    Return to Tools → Site Health and re-check: loopback should pass, and scheduled tasks will run normally.

  • Logto Database Migration

    Create database and role BEFORE db restoration

    docker exec -i docker-logto-db-1 psql -U postgres <<EOF
    -- Create the database
    CREATE DATABASE logto;
    
    -- Create the missing role
    CREATE ROLE logto_tenant_logto WITH LOGIN PASSWORD 'your_secure_password';
    
    -- Grant connection privilege
    GRANT CONNECT ON DATABASE logto TO logto_tenant_logto;
    
    -- Connect to logto database for schema permissions
    \c logto
    
    -- Grant schema permissions
    GRANT USAGE ON SCHEMA public TO logto_tenant_logto;
    GRANT CREATE ON SCHEMA public TO logto_tenant_logto;
    
    -- Grant default privileges for future objects
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO logto_tenant_logto;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO logto_tenant_logto;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO logto_tenant_logto;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TYPES TO logto_tenant_logto;
    EOF

    Then restore the backup

    gunzip < logto.sql.gz | docker exec -i docker-logto-db-1 psql -d logto -U postgres

    This can help you avoid ERROR: role "logto_tenant_logto" does not exist errors