AltisでWP CLIやシェルコマンドを実行したり、ログを確認する方法
カスタマイズやプラグインを追加したりするとき、WP CLIでの操作やエラーログの確認などでターミナルを使いたくなります。 Altisの場合、composer経由でコンテナ内に入ることなどができる様子でした。 compos […]
広告ここから
広告ここまで
目次
カスタマイズやプラグインを追加したりするとき、WP CLIでの操作やエラーログの確認などでターミナルを使いたくなります。
Altisの場合、composer経由でコンテナ内に入ることなどができる様子でした。
composer server cli -- <command>
: WP CLIを実行する
WP CLIコマンドを使いたい場合、composer server cli
を利用します。
% composer server cli -- post get 1
+-----------------------+---------------------------------------------------------+
| Field | Value |
+-----------------------+---------------------------------------------------------+
| ID | 1 |
| post_author | 1 |
| post_date | 2022-12-04 10:05:44 |
| post_date_gmt | 2022-12-04 10:05:44 |
| post_content | <!-- wp:paragraph --> <p>Welcome to WordPress. This is |
| | your first post. Edit or delete it, then start writing! |
| | </p> <!-- /wp:paragraph --> |
| post_title | Hello world! |
| post_excerpt | |
| post_status | publish |
| comment_status | open |
| ping_status | open |
| post_password | |
| post_name | hello-world |
| to_ping | |
| pinged | |
| post_modified | 2022-12-04 10:05:44 |
| post_modified_gmt | 2022-12-04 10:05:44 |
| post_content_filtered | |
| post_parent | 0 |
| guid | https://first-altis.altis.dev/?p=1 |
| menu_order | 0 |
| post_type | post |
| post_mime_type | |
| comment_count | 1 |
+-----------------------+---------------------------------------------------------+
help
コマンドを見る限り、独自のコマンドがいろいろを入っているみたいで、ここも深掘りし甲斐がありそうです。
SUBCOMMANDS
altis Altis WP CLI Command class.
aws-rekognition
cache Adds, removes, fetches, and flushes the WP Object Cache
object.
cap Adds, removes, and lists capabilities of a user role.
cavalcade
cli Reviews current WP-CLI info, checks for updates, or
views defined aliases.
comment Creates, updates, deletes, and moderates comments.
config Generates and reads the wp-config.php file.
core Downloads, installs, updates, and manages a WordPress
installation.
cron Tests, runs, and deletes WP-Cron events; manages
WP-Cron schedules.
db Performs basic database operations using credentials
stored in wp-config.php.
elasticpress CLI Commands for ElasticPress
embed Inspects oEmbed providers, clears embed cache, and
more.
eval Executes arbitrary PHP code.
eval-file Loads and executes a PHP file.
export Exports WordPress content to a WXR file.
gaussholder
healthcheck CLI COmmand to run Altis Healthchecks.
help Gets help on WP-CLI, or on a specific command.
hm-redirects Handles redirects in a scalable manner.
i18n Provides internationalization tools for WordPress
projects.
import Imports content from a given WXR file.
language Installs, activates, and manages language packs.
maintenance-mode Activates, deactivates or checks the status of the
maintenance mode of a site.
media Imports files as attachments, regenerates thumbnails,
or lists registered image sizes.
menu Lists, creates, assigns, and deletes the active theme's
navigation menus.
network Perform network-wide operations.
option Retrieves and sets site options, including plugin and
WordPress settings.
package Lists, installs, and removes WP-CLI packages.
plugin Manages plugins, including installs, activations, and
updates.
post Manages posts, content, and meta.
post-type Retrieves details on the site's registered post types.
qm
redis Various WP Redis utility commands.
rewrite Lists or flushes the site's rewrite rules, updates the
permalink structure.
role Manages user roles, including creating new roles and
resetting to defaults.
--More--
composer server shell
: PHPコンテナにはいる
PHPコンテナに入る場合は、composer server shell
を使います。
WP CLIも実行可能です。
% composer server shell
www-data@e99f2d60e2de:/usr/src/app$ wp post get 1 --url=first-altis.altis.dev
+-----------------------+---------------------------------------------------------+
| Field | Value |
+-----------------------+---------------------------------------------------------+
| ID | 1 |
| post_author | 1 |
| post_date | 2022-12-04 10:05:44 |
| post_date_gmt | 2022-12-04 10:05:44 |
| post_content | <!-- wp:paragraph --> <p>Welcome to WordPress. This is |
| | your first post. Edit or delete it, then start writing! |
| | </p> <!-- /wp:paragraph --> |
composer server logs <service>
: PHPやnginxのログを見る
トラブルが起きた時、ログの確認は必須です。
Altisではcomposer server logs
コマンドで調査ができます。
Nginxのログを見る
% composer server logs nginx
first-altis-nginx | 2022/12/25 09:45:10 [info] 31#31: *2336 client 172.19.0.2 closed keepalive connection
first-altis-nginx | 2022/12/25 13:45:58 [info] 30#30: *2339 client 172.19.0.2 closed keepalive connection
first-altis-nginx | 2022/12/25 13:46:29 [info] 31#31: *2344 epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while reading upstream, client: 172.19.0.11, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/www.socket:", host: "first-altis.altis.dev", referrer: "https://first-altis.altis.dev/"
PHPのログを見る
% composer server logs php
first-altis-php | #9 /usr/src/app/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
first-altis-php | #10 /usr/src/app/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
first-altis-php | #11 /usr/src/app/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
first-altis-php | #12 /usr/src/app/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
first-altis-php | #13 /usr/src/app/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
composer server db
: MySQLデータベースにログインする
DBの情報を確認する場合は、composer server db
コマンドを利用します。
% composer server db
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 67775
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| wordpress |
+--------------------+
5 rows in set (0.01 sec)
mysql>
ドキュメントなど
もし自分がAltisを案件や個人開発で使う場合に使いそうなコマンドのメモでした。
その他のコマンドは、ドキュメントをご確認ください。
それでは、よい年を