douhuang2218 2016-05-12 08: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 08: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!

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

报告相同问题?

悬赏问题

  • ¥100 二维码被拦截如何处理
  • ¥15 怎么解决LogIn.vue中多出来的div
  • ¥15 优博讯dt50巴枪怎么提取镜像
  • ¥30 在CodBlock上用c++语言运行
  • ¥15 求C6748 IIC EEPROM程序固化烧写算法
  • ¥50 关于#php#的问题,请各位专家解答!
  • ¥15 python 3.8.0版本,安装官方库ibm_db遇到问题,提示找不到ibm_db模块。如何解决?
  • ¥15 TMUXHS4412如何防止静电,
  • ¥30 Metashape软件中如何将建模后的图像中的植被与庄稼点云删除
  • ¥20 机械振动学课后习题求解答
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部