我学Drupal已经6年多了,很早以前就知道Drush,但是由于不懂Linux,所以很少在实际的项目中使用Drush,曾经在windows下面安装过Drush,但是每次使用,总是报一大堆的警告信息,后来也就不用了。最近开始学习Linux,其实也是想学习一下Drush。
先说安装,我使用的是centos,所以找到了一篇文挡,https://drupal.org/node/2009426,按照里面的操作进行,先是第一步:
sudo wget --quiet -O - http://ftp.drupal.org/files/projects/drush-7.x-4.5.tar.gz |
sudo tar -zxf - -C /usr/local/share
在这里的时候,我先执行了:
cd /usr/local/share
sudo wget --quiet -O - http://ftp.drupal.org/files/projects/drush-7.x-5.9.tar.gz
我将drush的版本替换为了最新的。接着,我执行:
sudo tar -zxf - -C /usr/local/share
结果命令不动了,好像死机了。这个时候,我才发现,第一行命令后面有一个|,这是Linux里面的管道,这两个命令是放在一起的,第一个命令的执行结果,将会传递给第二个命令作为后者的输入。
我不得不关闭ssh窗口,重新打开,回到刚才的目录,然后执行:
tar zxvf drush-7.x-5.9.tar.gz
程序解压缩成功。
接下来是创建软链接,我按照文档中的命令输入:
ln -s /usr/local/share/drush/drush /usr/local/bin/drush
创建成功。
接下来,输入命令:
drush
下面显示了一大堆的信息:
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
--uri=<http://example.com:8888> needed in multisite 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
archive-backup, arb) file.
archive-restore Expand a site archive into a Drupal web site.
。。。。。。。
文档上面,到这里的时候,是不成功的,还需要执行以下操作:
打开bash_profile文件,将里面的:
=/hsphere/shared/bin:/hsphere/shared/sbin:/hsphere/local/var/vpopmail/bin:/usr/local/bin:/usr/local/sbin:$PATH:$HOME/bin
修改为:
PATH=/hsphere/shared/bin:/hsphere/shared/sbin:/hsphere/local/var/vpopmail/bin:/usr/local/bin:/usr/local/sbin:/hsphere/shared/php53/bin:$PATH:$HOME/bin
我对hsphere不是很熟悉,确切的说,是第一次听说。不知道现在是否安装成功了。所以,我又Google了一下,找到了另一篇文章,http://www.webmaster.net/how-install-drush-centos-6x,上面是基于PEAR安装的,安装过程更简单,上面说,只要drush,命令成功执行,就是安装成功了,这篇文章的最后,想要使用下面的命令:
pico /etc/drush/drush.ini
创建drush.ini文件,并在里面添加以下代码:
error_reporting = E_ALL | E_NOTICE | E_STRICT
我没有执行成功,因为pico这个命令不存在。不过还是有点收获的,觉得自己已经安装成功了。导航到一个Drupal的根目录下,执行命令:
drush dl zen
竟然成功了,得到以下信息:
Project zen (7.x-5.4) downloaded to [success]
/var/www/html/ebook/sites/all/themes/zen.
执行:
drush dl panels
也成功了,得到以下信息:
Project panels (7.x-3.3) downloaded to [success]
/var/www/html/ebook/sites/all/modules/panels.
Project panels contains 4 modules: panels_ipe, panels_mini, panels_node, panels.
还把里面子模块的机读名字都给列出来了,方便下面的操作。
执行命令:
drush en panels
在下面的提示信息中,输入y,表示同意。
The following extensions will be enabled: panels
Do you really want to continue? (y/n): y
panels was enabled successfully. [ok]
Panels模块安装成功。
自己检查了一下Drupal后台:也成功了。
当欧美的Drupal程序员,已经用上拖拉机的时候,我们还在刀耕火种的阶段。这是我经常说的。