运行时出现Drush PHP语法错误


9

我正在遵循此页面上列出的Drush安装说明:https : //github.com/drush-ops/drush/blob/master/docs/install.md

我似乎在代码内收到语法错误:

[user@localhost ~]$ wget https://github.com/drush-ops/drush/releases/download/8.0.0-rc4/drush.phar
--2015-11-16 16:23:02--  https://github.com/drush-ops/drush/releases/download/8.0.0-rc4/drush.phar
Resolving github.com (github.com)... 192.30.252.131
Connecting to github.com (github.com)|192.30.252.131|:443... connected.
HTTP request sent, awaiting response... 302 Found
2015-11-16 16:23:05 (1.47 MB/s) - drush.phar saved [3496991/3496991]

[user@localhost ~]$ php drush.phar core-status

Parse error: syntax error, unexpected '[' in phar:///home/user/drush.phar/includes/output.inc on line 188

我没有在Google上看到此错误。知道如何解决吗?


您正在使用哪个版本的PHP?
kiamlaluno

您是否在Drupal目录中运行drush?
没有Sssweat

PHP 5.3.29 (cli) (built: Nov 3 2015 15:43:40) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies
艾塞克斯(Essex)的理查德(Richard of Essex),2015年

当我在Drupal目录中运行时会发生这种情况,而当我不在目录中时会发生这种情况。无论如何,我认为这不是Drush通常对找不到安装的反应。其他版本已正常退出。
艾塞克斯(Essex)的理查德(Richard of Essex)

1
我将添加以确保您检查是否DRUSH_PHP设置了环境变量。我花了太长时间试图弄清楚为什么drush不使用php 5.6,即使那是我在路径中配置的。原来我DRUSH_PHP很早以前就设置了我的php 5.3路径。unset DRUSH_PHP为我解决了这个问题。
用户

Answers:


17

您正在使用Drush 8,它要求最低PHP版本为5.4.5(http://docs.drush.org/en/master/install/)。

您当前的版本(5.3)无法理解短数组语法,因此您会看到此错误。

要解决此问题,请升级PHP或切换到Drush的较早分支。


我有相同的问题。我有PHP 5.3.29,Drupal 6(在Ubuntu 14.04上使用phpbrew安装php,然后切换到5.3.29版本)。当我运行命令时,drush status我得到:警告:模块'json'已经加载到第0行PHP的Unknown中,语法错误,语法错误,意外的'['在phar:/// usr / local / bin / drush / includes / startup中。 inc在第63行上解析错误:语法错误,在第63行的phar:///usr/local/bin/drush/includes/startup.inc中出现意外的[[]
Niladri Sarkar,

0

如果您的系统安装了多个php版本,则可以在.bashrc.bash_profile/etc/profile.d/global_aliases.sh中定义别名(或系统中可以定义别名的任何部分)。别名将使用适当的php版本运行drush。

例如,在plesk系统中,您可能可以执行以下操作

alias drush='/opt/plesk/php/5.6/bin/php /usr/local/drush'
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.