Caddy-W.P-GRAV

Open webmin, go to desired domain, upload wordpress.zip and extract wordpress.zip. OR

$ cd /tmp
$ wget https://wordpress.org/latest.zip
$ sudo mkdir /usr/share/caddy/domain
$ sudo unzip /tmp/latest.zip   //it will unzip in the directory wordpress.
$ sudo mv /tmp/wordpress/* /usr/share/caddy/domain  //it will transfer all the files to domain.
$ cd /usr/share/caddy/domain
$ ls //see if all the files there
$ sudo chown -R $USER:$USER /usr/share/caddy/domain

mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL ON wordpress.* TO 'user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON *.* TO 'user'@'localhost';
FLUSH PRIVILEGES;
exit;

$ nano /etc/caddy/Caddyfile
domain:80 {    
    tls your@email.com
        log {
        output file /var/log/caddy/your.domain
        format console
    }
    root * /usr/share/caddy/domain
    encode gzip
    file_server
    php_fastcgi unix//run/php/php8.2-fpm.sock
      @disallowed {
        path /xmlrpc.php
        path *.sql
        path /wp-content/uploads/*.php
                  }
     rewrite @disallowed '/index.php'

        if {path} not_match ^\/wp-admin
        to {path} {path}/ /index.php?_url={uri}
}
$ sudo systemctl restart caddy
$ cd /usr/share/caddy/domain
  rename wp-config-sample.php to wp-config.php
$ mv wp-config-sample.php wp-config.php
$ sudo nano /usr/share/caddy/domain/wp-config.php
define('DB_NAME', 'wp_site');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'StrongPassword');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
Go to https://Domain, it will setup Wordpress.

GRAV with CADDY, Debian 12

Install, PHP, DB, Caddy first.

$ adduser caddy
$ adduser caddy sudo
$ su - caddy
$ exit

$ cd /usr/share/caddy
$ sudo wget https://getgrav.org/download/core/grav-admin/1.7.48
$ sudo unzip 1.7.48
$ sudo mv grav-admin grav
$ sudo chown -R $USER:$USER /usr/share/caddy/grav

$ nano /etc/caddy/Caddyfile

your_domain:80 {
    tls xxx@xxx.com
    root * /usr/share/caddy/grav
    file_server
    encode zstd gzip
    php_fastcgi unix//run/php/php8.2-fpm.sock 

    # Begin - Security
    # deny all direct access for these folders
    rewrite /(\.git|cache|bin|logs|backups|tests)/.* /403

    # deny running scripts inside core system folders
    rewrite /(system|vendor)/.*\.(txt|xml|md|html|htm|shtml|shtm|yaml|yml|php|php2|php3|php4|php5|phar|phtml|pl|py|cgi|twig|sh|bat)$ /403

    # deny running scripts inside user folder
    rewrite /user/.*\.(txt|md|yaml|yml|php|php2|php3|php4|php5|phar|phtml|pl|py|cgi|twig|sh|bat)$ /403

    # deny access to specific files in the root folder
    rewrite /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) /403

    respond /403 403
    ## End - Security

    # global rewrite should come last.
    try_files {path} {path}/ /index.php?_url={uri}&{query}

    log {
        output file /var/log/caddy/access.log
        format console
    }
}

$ sudo systemctl restart caddy


Posted : Monday 15th of September 2025 @ 12:41 AM— Tags : caddy-wordpress-grav