douhuang2218 2016-05-12 16:08
浏览 48
已采纳

1and1服务器中的Laravel Artisan PHP版本错误

I have a server hosted on 1and1 and I am using Laravel. When I want to execute the Artisan command to schedule a tasks, I get this error:

$ php artisan schedule:run

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /htdocs/artisan on line 31

Parse error: syntax error, unexpected T_STRING in /htdocs/artisan on line 31

After a lot searches, nothing solved my issue (do an alias for PHP, call $ php5.5 instead $ php, etc.).

The main problem is that a call to php uses version 4.4.9 of PHP, instead 5.5 that Laravel needs.

$ php -v 
PHP 4.4.9 (cgi-fcgi) (built: Mar 31 2016 16:41:29)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

$ php5.5 -v 
PHP 5.5.35 (cgi-fcgi) (built: May  3 2016 07:09:03)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

I changed the call to php5.5 and altered the Artisan file, calling this on the first line:

#!/usr/local/bin/php5.5
<?php

But at the end I always get this from artisan module calls:

Running scheduled command: '/usr/local/bin/php' 'artisan' moneySaved:send >> './logs/log.log' 2>&1 &

So the problem must come from who generates those "Running scheduled command" lines.

  • 写回答

1条回答 默认 最新

  • dousi8237 2016-05-12 16:08
    关注

    After a research, the problem was in the way that Symfony internal scripts "locate" the php path to call it. Specifically those:

    epoc/vendor/symfony/process/PhpExecutableFinder.php epoc/vendor/laravel/framework/src/Illuminate/Console/Scheduling/Schedule.php

    The binary var holds the path to call PHP. In my case I forced it to use the 1and1 path for php5.5, and that's all.

    public function command($command, array $parameters = [])    {
        //$binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
        $binary = "/usr/local/bin/php5.5";​
        if (defined('HHVM_VERSION')) {
            $binary .= ' --php';
        }​
        if (defined('ARTISAN_BINARY')) {
            $artisan = ProcessUtils::escapeArgument(ARTISAN_BINARY);
        } else {
            $artisan = 'artisan';
        }​
        return $this->exec("{$binary} {$artisan} {$command}", $parameters);
    }
    

    Now it works!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题