0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

wp-env にログ設定

Last updated at Posted at 2025-10-02

wp-env にログが出ているか?

  • wp-config.php で WordPress ログの確認

    .bash
    # Docker, WordPress が格納されるパスを確認
    wp-env install-path
    /home/xxx/wp-env/41b83dceb184cd5d6107ec2f7136b1b0
    ✔  (in 5s 658ms)
    cd /home/xxx/wp-env/41b83dceb184cd5d6107ec2f7136b1b0
    
    # WordPress の設定ファイルをさがす
    find . -path "*wp-config.php*"
    find . -path "*wp*"
    /home/xxx/wp-env/41b83dceb184cd5d6107ec2f7136b1b0
    /home/xxx/wp-env/41b83dceb184cd5d6107ec2f7136b1b0/wp-env-cache.json
    # ない
    
    # 何が入っているのか確認:wp-config.phpがありそうではない
    ls -al /home/xxx/wp-env/41b83dceb184cd5d6107ec2f7136b1b0
    total 12
    drwxr-xr-x 2 kosuke kosuke 4096 Oct  2 09:27 .
    drwxr-xr-x 4 kosuke kosuke 4096 Oct  2 09:27 ..
    -rw-r--r-- 1 kosuke kosuke   34 Oct  2 09:27 wp-env-cache.json
    
    
  • - うえのつづき

    • しかたないので VS Code の Dev Container で開く

スクリーンショット 2025-10-02 093941.png

スクリーンショット 2025-10-02 094710.png

おい、やっぱ何もねぇじゃねぇか。なんでやねん。

wp-env install-path

Get the path where all of the environment files are stored. This includes the Docker files, WordPress, PHPUnit files, and any sources that were downloaded.

Example:
$ wp-env install-path
/home/user/.wp-env/63263e6506becb7b8613b02d42280a49

https://www.npmjs.com/package/@wordpress/env

  • -
    • wp-env run で wp cli コマンドが使えるらしい。

      wp-env run [command..]

      Runs an arbitrary command in one of the underlying Docker containers. For
      example, it can be useful for running wp cli commands. You can also use it to
      open shell sessions like bash and the WordPress shell in the WordPress instance.
      For example, wp-env run cli bash will open bash in the development WordPress
      instance.

      Positionals:
      container The container to run the command on. [string] [required]
      command The command to run. [array] [default: []]

      .bash
      wp-env run cli tail -f wp-content/debug.log
      ℹ Starting 'tail -f wp-content/debug.log' on the cli container.
      
      open /home/kosuke/wp-env/41b83dceb184cd5d6107ec2f7136b1b0/docker-compose.yml: no such file or directory
      ✖ Command failed with exit code 1
      

      いやだからなんでやねん。

参考:

  • ↑のつづき
    • コンテナ内で find 実行。何やってもあかんやん。
    .bash
    wp-env run cli bash find . -path "*wp-content/debug.log*"
    ℹ Starting 'bash find . -path *wp-content/debug.log*' on the cli container.
    
    open /home/kosuke/wp-env/41b83dceb184cd5d6107ec2f7136b1b0/docker-compose.yml:    no such file or directory
    ✖ Command failed with exit code 1
    Command failed with exit code 1
    

- docker exec でコンテナID を指定してコンテナ内に入ります。やっと wp-config.php にありつけた。
.bash
docker ps -a
CONTAINER ID   IMAGE                                              COMMAND                   CREATED        STATUS                      PORTS                                                    NAMES
cd642bafd96e   4dcfe4ddb0fe8c597fcee5b64ee57bc7-cli               "docker-entrypoint.s…"    40 hours ago   Up 40 hours                                                                          4dcfe4ddb0fe8c597fcee5b64ee57bc7-cli-1
65763b0a28a3   4dcfe4ddb0fe8c597fcee5b64ee57bc7-tests-cli         "docker-entrypoint.s…"    40 hours ago   Up 40 hours                                                                          4dcfe4ddb0fe8c597fcee5b64ee57bc7-tests-cli-1
e6e7bd33cf4b   4dcfe4ddb0fe8c597fcee5b64ee57bc7-tests-wordpress   "docker-entrypoint.s…"    40 hours ago   Up 40 hours                 0.0.0.0:6662->80/tcp, [::]:6662->80/tcp                  4dcfe4ddb0fe8c597fcee5b64ee57bc7-tests-wordpress-1
f0c242aefd77   4dcfe4ddb0fe8c597fcee5b64ee57bc7-wordpress         "docker-entrypoint.s…"    40 hours ago   Up 40 hours                 0.0.0.0:6661->80/tcp, [::]:6661->80/tcp                  4dcfe4ddb0fe8c597fcee5b64ee57bc7-wordpress-1
de18ccd96df2   mariadb:lts                                        "docker-entrypoint.s…"    40 hours ago   Up 40 hours                 0.0.0.0:32770->3306/tcp, [::]:32770->3306/tcp            4dcfe4ddb0fe8c597fcee5b64ee57bc7-tests-mysql-1
c5d03f22ee2b   mariadb:lts                                        "docker-entrypoint.s…"    40 hours ago   Up 40 hours                 0.0.0.0:32769->3306/tcp, [::]:32769->3306/tcp            4dcfe4ddb0fe8c597fcee5b64ee57bc7-mysql-1

docker exec -it e6e7bd33cf4b bash
root@e6e7bd33cf4b:/var/www/html# find . -path "*wp-config.php*"
./wp-config.php

wp-config.php を cat.

root@e6e7bd33cf4b:/var/www/html#cat -n wp-config.php | grep WP_DEBUG
   108   * It is strongly recommended that plugin and theme developers use WP_DEBUG
   125  define( 'WP_DEBUG', false );

このままでは、ログが出ない。

  • vi が使えないので VS Code で wp-config.php を直接編集。上で開いた

    .devcontainer/docker-compose.yml
    version: '3.8'
    
    services: 
      app:
        build:
          context: .
          dockerfile: Dockerfile
    
        volumes:
          - ../..:/workspaces:cached
    

    をみると、volumes のところは書式が [ホスト側の相対Path]:コンテナの絶対Path であり、値は ../..:/workspaces になっていますから、root 親ディレクトリは /home/xxx/wp-env/.devcontainer、 そこからみたホストのディレクトリ= /home/xxx/wp-env/ に docker exec で みてた /var/www/html がありそうです。

    VS Code で/home/xxx/wp-env/ を開く。

スクリーンショット 2025-10-02 111244.png

ずっとみてたの ( wp-env install-path )、テスト用じゃなかった ( 41b...のほう ) みたいです。こっちはテスト用。(4dc...) テスト用のほうにソースいろいろあった。
wp-env install-path はゴミでした。使えない道具はゴミなんでね。 なんで実際動いていない方のパス返してんねん。

スクリーンショット 2025-10-02 111559.png

スクリーンショット 2025-10-02 111652.png

やっと編集できる。。。

スクリーンショット 2025-10-02 112931.png

4dcfe4ddb0fe8c597fcee5b64ee57bc7/tests-WordPress/wp-config.php
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

debug.log というファイルがないので、wp-content に作成しておく。

root@e6e7bd33cf4b:/var/www/html# ls -al ./wp-content/debug.log
ls: cannot access './wp-content/debug.log': No such file or directory
  • ログについて ( 参考 )

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?