当我在我的机器上安装LAMP时,我安装了php 5.6.27。几天前我安装了php 5.3.29以及我以前的php版本。之后,当我尝试在symfony2项目上运行composer update时,出现错误:
Fatal error: Uncaught Error: Call to undefined function Composer\Console\json_decode() in /usr/share/php/Composer/Console/Application.php:145
Stack trace:
#0 /usr/share/php/Symfony/Component/Console/Application.php(120): Composer\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /usr/share/php/Composer/Console/Application.php(99): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 /usr/bin/composer(44): Composer\Console\Application->run()
#3 {main}
thrown in /usr/share/php/Composer/Console/Application.php on line 145
我目前使用sudo a2enmod php5.6
命令启用了php 5.6.27。在我的浏览器上,phpinfo()的输出显示php版本为' PHP版本5.6.27-1 + deb.sury.org~xenial + 1 '。此外,php-json模块已启用,如下面的屏幕截图所示
在终端中,php -v
的输出为:
PHP 5.6.27-1+deb.sury.org~xenial+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
正如此帖[{3}}上的回答中所建议的那样,我已尝试运行sudo apt-get install php5-json
,但它会输出:
sudo: unable to resolve host utkarsh
[sudo] password for lenovo:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'php5-common' instead of 'php5-json'
php5-common is already the newest version (5.3.2-1ubuntu4).
0 upgraded, 0 newly installed, 0 to remove and 50 not upgraded.
在此之后,我重新启动了apache2服务器,但在运行composer update
时,它仍然给我同样的错误。
感谢所有帮助。
答案 0 :(得分:0)
您的问题是因为没有为 cli 启用php json模块。 (php cli vs apache)
请注意,您的安装可能与php 5.6模块的位置不同。
这可能有所帮助:
Is there any command to enable/disable a php extension from command line?