Running caddy adapt -config <path>/Caddyfile = error

root@wordpress:/ # caddy
Caddy is an extensible server platform.

usage:
  caddy <command> [<args...>]

commands:
  adapt           Adapts a configuration to Caddy's native JSON
  build-info      Prints information about this build
  environ         Prints the environment
  file-server     Spins up a production-ready file server
  fmt             Formats a Caddyfile
  hash-password   Hashes a password and writes base64
  help            Shows help for a Caddy subcommand
  list-modules    Lists the installed Caddy modules
  reload          Changes the config of the running Caddy instance
  reverse-proxy   A quick and production-ready reverse proxy
  run             Starts the Caddy process and blocks indefinitely
  start           Starts the Caddy process in the background and then returns
  stop            Gracefully stops a started Caddy process
  trust           Installs a CA certificate into local trust stores
  untrust         Untrusts a locally-trusted CA certificate
  validate        Tests whether a configuration file is valid
  version         Prints the version

Use 'caddy help <command>' for more information about a command.

Full documentation is available at:
https://caddyserver.com/docs/command-line


root@wordpress:/ # caddy adapt /usr/local/www/Caddyfile
adapt: input file required when there is no Caddyfile in current directory (use --config flag)

root@wordpress:/ #
root@wordpress:/ # caddy adapt --config /usr/local/www/Caddyfile
adapt: /usr/local/www/Caddyfile:15: unrecognized directive: error

root@wordpress:/ # caddy adapt -config /usr/local/www/Caddyfile
adapt: /usr/local/www/Caddyfile:15: unrecognized directive: error
root@wordpress:/ #

I don’t understand why method won’t work

Did you try looking at your Caddyfile on line 15 like the error message says?

root@wordpress:/ # ls -al /usr/local/www
total 30257
drwxr-xr-x   4 root  wheel        11 May  5 07:59 .
drwxr-xr-x  14 root  wheel        14 May  1 05:33 ..
-rw-r--r--   1 root  wheel  11959088 May  5 00:56 caddy_2.0.0_freebsd_amd64.tar.gz
-rw-r--r--   1 root  wheel       447 May  1 14:33 caddy.conf.v2
-rw-r--r--   1 root  wheel      2365 May  5 07:35 caddy.v2.0504
-rw-r--r--   1 root  wheel       575 May  5 12:14 Caddyfile
-rwxr--r--   1 www   www    34332672 May  1 06:06 caddyv2
-rw-r--r--   1 1001  116       11358 May  5 00:47 LICENSE
drwxr-xr-x   2 root  wheel         3 Apr 28 22:55 nginx
-rw-r--r--   1 1001  116        8091 May  5 00:47 README.md
drwxr-sr-x   5 www   www          22 May  1 19:51 wordpress
root@wordpress:/ # caddy version
v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=
root@wordpress:/ # caddy adapt -config /usr/local/www/Caddyfile
adapt: /usr/local/www/Caddyfile:15: unrecognized directive: error
root@wordpress:/ # caddy adapt --config /usr/local/www/Caddyfile
adapt: /usr/local/www/Caddyfile:15: unrecognized directive: error
root@wordpress:/ #

I would say yes

edit: i think you mean, checking on the line 15 of my Caddyfile. ?
output should say something more humanlike

okay, yes, is the new line added to the Caddyfile
based on old v1 method

	root   /var/www/nextcloud
	log    /var/log/nextcloud_access.log
	errors /var/log/nextcloud_errors.log

One will safely assume that below should work.

test.petua.my {
        root *  /shop

        log {
            output file /var/log/caddy_log.log
            }

        error {
            output file /car/log/caddy_error.log
            }

        encode gzip
        php_fastcgi 127.0.0.1:9000

        # Prevent malicious PHP uploads from running
        @uploads {
          path_regexp path /uploads\/(.*)\.php
        }
        rewrite @uploads /

        @wp-admin {
          path  not ^\/wp-admin/*
        }
}

but that is not the story.
And nothing here : Upgrading to Caddy 2 — Caddy Documentation
Going to v2 is quite a frastration for alot of people given I have programming backgroup since DOS era where everything is commandline, I still have trouble with it.

This is the source of the error:

Caddy 2 does not have a directive called error, which is why you’re getting the error message unrecognized directive: error. You can review the list of supported directives here.

2 Likes

Sorry, but why do you assume this is the case?

You can find valid directives here: Caddyfile Directives — Caddy Documentation

No need to assume anything :slight_smile:

Why is it frustrating? Have you tried reading the documentation? The upgrade guide? The tutorials? You have a lot of experience in the command line, how did you learn how to use the command line? How can we improve?

1 Like

It took me whole day to get the above WordPress file going

  1. from gzip to encode gzip is straight forward
  2. took a while to get root * /shop
  3. in section “upgrade to v2” , v1 is : log access.log
    I took the example literally
log {
        output /var/log         access.log
        format string           yes
}

don’t laugh. I know the “format” is not integer or boolean, so string is my best guess. And you can figure the rest.

1 Like

My first OS is MS-DOS 3.3
I can maybe still remember the different of major release all the way until 7.1
Back then MS 7.1 is like WOW , and imagine running MS-WORD in non-GUI

1 Like

I have when through many times, and at one point I have two screen so I can compare v1 and v2.
adapt: /usr/local/www/Caddyfile:15: unrecognized directive: error

At first glance , from old school method, where error is identify by a number, and you have to look it up in the manual to find what does the number mean,

I read it : Adapt having unrecognized directive error : 15 , for file /usr/local/www/Caddyfile

:man_shrugging:

1 Like

Double check the syntax for this one - it needs to be output <writer_module> ... where <writer_module> is one of the modules listed here: https://caddyserver.com/docs/caddyfile/directives/log#output-modules

I’m assuming you want to put your logs in /var/log/access.log, so you want the file writer: log (Caddyfile directive) — Caddy Documentation

format here doesn’t refer to a variable type or anything like that. The format subdirective allows you to specify an encoder module. The encoder module determines the format of the output. Valid options at the time of this post include console, json, logfmt, and single_field. See: log (Caddyfile directive) — Caddy Documentation

1 Like

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