Drush

Drush モジュール

概要

DrushはDrupalのためのコマンドラインシェルスクリプトインターフェースです。 さまざま使い方が可能で、Drushを組み込んださまざまDrupalモジュールがあります。

Drush はDrupalのバージョンには依存しません。 どのバージョンでも使用可能です。

 
インストール

Linux Mac UNIX の場合

ソースをOSのログインユーザーのホームディレクトリに解凍します。 その後、 drush コマンドが実行できるようにパーミッションを変更します。

# chmod -R u+x  (インストールしたディレクトリの)drush/drush 

上記の方法以外にPHPのPEARを使ってインストールもできます。 まず、PEARがインストールされているか確認します。PEARが実行できる環境であれば、以下のコマンドを実行します。

pear channel-discover pear.drush.org
pear install drush/drush

もし上記のPEARコマンドでchannel-discoverで失敗する場合(パーミッションは除く)は、以下のコマンドを実行します。

pear upgrade --force Console_Getopt
pear upgrade --force pear
pear upgrade-all

アップデイトするために pear upgrade drush/drush を実行します。

 

Drushコマンドの実行はDrupalのルートディレクトリで # drush  を実行し、動作を確認します。

 

Windowsの場合

gnuwin32をインストールします。 その後ソースを解凍し、 drush.bat コマンドを実行します。

詳細は次のサイトで確認します  drupal.org/node/594744

 

GitHubの場合

GitHubのDrushのサイト https://github.com/drush-ops/drush 

2015年1月24日のDebian 7 Linuxでの動作テストです。以下のURLで、インストール手順を確認します

http://docs.drush.org/en/master/install/

composerのインストール(curlが必要になります。)

もしインストールする場合は # apt-get install php5-curl

以下のURLでインストール手順を確認します。

https://getcomposer.org/doc/00-intro.md#system-requirementstever version you want.

Globalの場合でインストールします。

curl -sS https://getcomposer.org/installer | php

mv composer.phar /usr/local/bin/composer
source $HOME/.bashrc
composerコマンドを実行して起動確認します。

Composerの global bin ディレクトリにシステムパスを追加します(推奨):

sed -i '1i export PATH="$HOME/.composer/vendor/bin:$PATH"' $HOME/.bashrc

source $HOME/.bashrc

Druah 6 をインストールする場合

composer global require drush/drush:6.*

Druah 7 をインストールする場合(Drupal 8 は必須です)

composer global require drush/drush:dev-master

Drushコマンドの環境を確認する場合

drush status

composer のアップデイト (最新のDrushバージョンに更新する)

composer global update

Drush 7.0.0-rc2 のインストールの場合(2015年6月20日)

curlのインストールもしくは確認  apt-get install curl

もしGitコマンドがインストールされていない場合は、apt-get install git  でインストールします。

  • To install for all users on the server:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
ln -s /usr/local/bin/composer /usr/bin/composer

git clone https://github.com/drush-ops/drush.git /usr/local/src/drush
cd /usr/local/src/drush
git checkout 7.0.0-rc2   # or whatever version you want.
ln -s /usr/local/src/drush/drush /usr/bin/drush
/usr/bin/composer install
drush --version   # Drushバージョン確認

Drupal 8 の場合

GitHubの説明で、Composer - One Drush per Projectのところを参考にします。

ただし、drushソースのコードステータスで build が失敗している場合はダウンロードできませ。

 

Drush 8.1.12 のインストールの場合(2017年6月28日)

curlのインストールもしくは確認  apt-get install curl

もしGitコマンドがインストールされていない場合は、apt-get install git  でインストールします。

  • To install or update for all users on the server

wget http://files.drush.org/drush.phar

php drush.phar core-status

chmod +x drush.phar
sudo mv drush.phar /usr/local/bin/drush

drush init

drush --version   # Drushバージョン確認

詳細は http://docs.drush.org/en/8.x/install/

 

基本設定

drushコマンド

キャッシュのクリア drush cache-clear  又は drush cc

module/themeのダウンロード drush pm-download モジュール名 又は drush dl モジュール名

module/themeのインストール drush pm-enable モジュール名 又は drush en モジュール名

module/themeの削除 drush pm-disable モジュール名 又は drush dls モジュール名

備考

Drushヘルプにより drush version 5.7

Execute a drush command. Run `drush help [command]` to view command-specific help.  Run `drush
topic` to read even more documentation.

Global options (see `drush topic core-global-options` for the full list):


-d, --debug                               Display even more information, including internal
                                           messages.
-h, --help                                This help system.
-ia, --interactive                        Force interactive mode for commands run on multiple
                                           targets (e.g. `drush @site1,@site2 cc --ia`).
-n, --no                                  Assume 'no' as answer to all prompts.
--php=</path/to/file>                     The absolute path to your PHP intepreter, if not 'php'
                                           in the path.
-p, --pipe                                Emit a compact representation of the command for
                                           scripting.
-r <path>, --root=<path>                  Drupal root directory to use (default: current
                                           directory).
-s, --simulate                            Simulate all relevant actions (don't actually change the
                                           system).
-l <http://example.com:8888>,             URI of the drupal site to use (only needed in multisite
--uri=<http://example.com:8888>           environments or when running on an alternate port).
-v, --verbose                             Display extra information about the command.
--version                                 Show drush version.
-y, --yes                                 Assume 'yes' as answer to all prompts.

 

Core drush commands: (core)

 

archive-dump (ard,    Backup your code, files, and database into a single file.
archive-backup, arb)
archive-restore       Expand a site archive into a Drupal web site.
(arr)
cache-clear (cc)      Clear a specific cache, or all drupal caches.
cache-get (cg)        Fetch a cached object and display it.
cache-set (cs)        Cache an object expressed in JSON or var_export() format.
core-config (conf,    Edit drushrc, site alias, and Drupal settings.php files.
config)
core-cron (cron)      Run all cron hooks in all active modules for specified site.
core-execute (exec,   Execute a shell command. Usually used with a site alias.
execute)
core-quick-drupal     Download, install, serve and login to Drupal with minimal configuration and
(qd)                  dependencies.
core-requirements     Provides information about things that may be wrong in your Drupal
(status-report, rq)   installation, if any.
core-rsync (rsync)    Rsync the Drupal tree to/from another server using ssh.
core-status (status,  Provides a birds-eye view of the current Drupal installation, if any.
st)
core-topic (topic)    Read detailed documentation on a given topic.
drupal-directory      Return path to a given module/theme directory.
(dd)
help                  Print this help message. See `drush help help` for more options.
image-flush           Flush all derived images for a given style.
php-eval (eval, ev)   Evaluate arbitrary php code after bootstrapping Drupal (if available).
php-script (scr)      Run php script(s).
queue-list            Returns a list of all defined queues
queue-run             Run a specific queue by name
search-index          Index the remaining search items without wiping the index.
search-reindex        Force the search index to be rebuilt.
search-status         Show how many items remain to be indexed out of the total.
self-update           Check to see if there is a newer Drush release available.
(selfupdate)
shell-alias (sha)     Print all known shell alias records.
site-alias (sa)       Print site alias records for all known site aliases and local sites.
site-install (si)     Install Drupal along with modules/themes/configuration using the specified
                       install profile.
site-reset            Reset a persistently set site.
site-set (use)        Set a site alias to work on that will persist for the current session.
site-ssh (ssh)        Connect to a Drupal site's server via SSH for an interactive session or to
                       run a shell command
test-clean            Clean temporary tables and files.
test-run              Run tests. Note that you must use the --uri option.
updatedb (updb)       Apply any database updates required (as with running update.php).
usage-send (usend)    Send anonymous Drush usage information to statistics logging site.  Usage
                       statistics contain the Drush command name and the Drush option names, but no
                       arguments or option values.
usage-show (ushow)    Show Drush usage information that has been logged but not sent.  Usage
                       statistics contain the Drush command name and the Drush option names, but no
                       arguments or option values.
variable-delete       Delete a variable.
(vdel)
variable-get (vget)   Get a list of some or all site variables and values.
variable-set (vset)   Set a variable.
version               Show drush version.
watchdog-delete       Delete watchdog messages.
(wd-del, wd-delete)
watchdog-list         Show available message types and severity levels. A prompt will ask for a
(wd-list)             choice to show watchdog messages.
watchdog-show         Show watchdog messages.
(wd-show, ws)

Runserver commands: (runserver)

runserver (rs)        Runs a lightweight built in http server for development.

Field commands: (field)

field-clone           Clone a field and all its instances.
field-create          Create fields and instances. Returns urls for field editing.
field-delete          Delete a field and its instances.
field-info            View information about fields, field_types, and widgets.
field-update          Return URL for field editing web page.

Project manager commands: (pm)

pm-disable (dis)      Disable one or more extensions (modules or themes).
pm-download (dl)      Download projects from drupal.org or other sources.
pm-enable (en)        Enable one or more extensions (modules or themes).
pm-info (pmi)         Show detailed info for one or more extensions (modules or themes).
pm-list (pml)         Show a list of available extensions (modules and themes).
pm-refresh (rf)       Refresh update status information.
pm-releasenotes       Print release notes for given projects.
(rln)
pm-releases (rl)      Print release information for given projects.
pm-uninstall          Uninstall one or more modules.
pm-update (up)        Update Drupal core and contrib projects and apply any pending database
                       updates (Same as pm-updatecode + updatedb).
pm-updatecode (upc)   Update Drupal core and contrib projects to latest recommended releases.

SQL commands: (sql)

sql-cli (sqlc)        Open a SQL command-line interface using Drupal's credentials.
sql-connect           A string for connecting to the DB.
sql-create            Create a database.
sql-drop              Drop all tables in a given database.
sql-dump              Exports the Drupal DB as SQL using mysqldump or equivalent.
sql-query (sqlq)      Execute a query against the site database.
sql-sync              Copy and import source database to target database. Transfers via rsync.

User commands: (user)

user-add-role (urol)  Add a role to the specified user accounts.
user-block (ublk)     Block the specified user(s).
user-cancel (ucan)    Cancel a user account with the specified name.
user-create (ucrt)    Create a user account with the specified name.
user-information      Print information about the specified user(s).
(uinf)
user-login (uli)      Display a one time login link for the given user account (defaults to uid
                       1).
user-password (upwd)  (Re)Set the password for the user account with the specified name.
user-remove-role      Remove a role from the specified user accounts.
(urrol)
user-unblock (uublk)  Unblock the specified user(s).

Other commands: (make)

make                  Turns a makefile into a working Drupal codebase.
make-generate         Generate a makefile from the current Drupal site.
(generate-makefile)

 

Drushコマンドの使い方

coreとmodule,themeなどをアップデイトする方法

既存のファイルをやDBをバックアップします。sitesディレクトリをバックアップします。

drush pm-updatecore

バックアップが /root/drush-backup/ 以下に作成されます。 

データベースのアップデイト drush updatedb

coreだけをアップデイトさせたい場合

drush pm-update projects drupal-7.xx(最新版)

アップデイト時に更新したくないモジュールやテーマがある場合

drush pm-update --lock モジュール名

更新作業中や更新後にlockしたモジュールを解除するとき

drush pm---unlock モジュール名

モジュールの導入インスト-ル 

drush pm-download モジュール名

drush pm-enable モジュール名

必要に応じてモジュールファイルのパーミッションを設定する

モジュールのダウンロードでバージョンを選択したい場合は

drush pm-download モジュール名 --select

モジュールの更新(バージョンアップおよびアップグレード)

drush pm-update モジュール名

drush pm-updatestatus  Coreとモジュールなどの更新情報を表示 

モジュールの情報(既にインストールされている)

drush pm-info    すべてのモジュールの情報を表示

drush pm-info モジュール名 

drush pm-list モジュール名  モジュール名とステータス、バージョンなどの簡単なリスト表示

モジュールの削除

drush pm-uninstall モジュール名

必要に応じてモジュールファイルを削除

キャッシュのクリア

drush cc --select

サイトのCRON実行

drush core-cron

メンテナンスモードの設定

drush vset maintenance_mode 1  <--- メンテナンスモードに設定

 drush sset system.maintenance_mode 1  <--- Drupal 8 の場合

drush vset maintenance_mode 0  <--- メンテナンスモードの解除

 drush sset system.maintenance_mode 0  <--- Drupal 8 の場合

ユーザの追加と権限(role)設定

drush user-create ユーザ名 --mail="メールアドレス" --password="パスワード"

drush user-add-role "administrator" ユーザ名

例えば、Add the "power user" role to the accounts with name, id, or email 5 or user3, uids 2 and 3, names someguy and somegal, and email address of billgates@microsoft.com

drush user-add-role "power user" 5,user3 --uid=2,3 --name=someguy,somegal --mail=billgates@microsoft.com

 

アドミニストレータのログインパスワードを忘れた場合

いくつかの方法がありますが、詳細は ここから

ワンタイムログインのリンクを再作成する場合  drush uli

パスワードをリセットする場合 drush upwd --password="givememypasswordback" admin (adminにユーザ名)

Drupal 7 のコアからデータベースとコアを一緒にインストール

まず、Drupal7の最新コアをダウンロード

drush dl drupal-7.38

drupal-7.38 ディレクトリ名を、たとえば、drupal に変更します。 mv drupal-7.38 drupal

drupalディレクトリのパーミッションのオーナー権をApache2の標準オーナー権(Debianの場合 www-data)に変更します。 chown -R www-data:www-data drupal

drupalのディレクトリに移動し、以下のDrushコマンドを実行します。

管理者アカウント名を admin  パスワードを admin データベースのユーザ名を MySQLUser そのユーザのパスワードを Password 作成するデータベース名を MySQLDatabase という条件で作成するDrushコマンド

drush site-install standard --account-name=admin --account-pass=admin --db-url=mysql://MySQLUser:Password@localhost/MySQLDatabase

drupalのインストールとデータベースの作成が終了し、インストール過程で作成されたディレクトリなどのパーミッションを、再度、Apache2の標準オーナー権限で設定します。

chown -R www-data:www-data ../drupal

日本語環境と日本語の言語ファイルの設定

localモジュールを有効にする  drush pm-enable local

Drush Lanagaugeコマンドのインストール drush dl dursh_language

日本語の設定 drush language-add ja   drush language-enable ja  drush language-default ja 

Localization updateモジュールのインストール drush pm-download l10n_update   drush pm-enable l10n_update

複数のdrushコマンドを連続で実行させたい場合

drush pm-update; drush cc all; drush cron

Drushコマンド実行時に詳細な内容を表示させる

--verbose  オプションをつける  たとえば、 drush cron --verbose

マルチサイトの場合、drupalルートでDrushコマンド実行時に実行するとき

drush --uri=http://example.com pm-updatecode

もしdrupalルート以外で実行させる場合は、--root, --uri を使います

drush --root=/var/www/html/demo1 --uri=http://example.com pm-updatecode

 

データベースに接続エラーでDrupalが起動しない場合

以下のコマンドで接続エラーの内容を確認できます

drush -v -d sql-cli

 

役立つ情報

Drushプロジェクトのホームページ  www.drush.ws    コマンドの一覧や使い方が記載されております。

使い方の英文説明 Managing a site from the command line using Drush 

PDF資料: Drush(5.11)コマンド一覧  Drush Guide 2012  drush cheat sheet

備考1) 

もしテーマやモジュールを更新しないでDrupalのコアと更新しても良いモジュールだけdrushコマンドアップデイトしたい場合

まず、メンテナンスモードにして、更新しないテーマやモジュールを非アクティブ(drush pm-disable)してからdrushコマンドでアップデイト、その後、更新しないテーマやモジュールをアクティブにして、動作確認後、メンテナンスモードも解除します。 念のために必ずバックアップを取ってから実行します。

 

FAQ

Q. drushコマンド drush cron を実行したときに、The following module is missing from the file system: <em   [warning]  class="placeholder">モジュール名</em>. For information about how to fix this, see <a
href="https://www.drupal.org/node/2487215">....... が表示されて場合は

A. 機能拡張モジュールをデータベースから削除します。例えば、 drush vset install_profile standard     drush sql-query "DELETE from system WHERE name='モジュール名' AND type = 'module';" 詳しくは https://www.drupal.org/node/2487215

 

 

 

オープンソースソフトウェア: 

CMS: