0

I had installed php 5.6.27 when I installed LAMP on my machine. A few days back I installed php 5.3.29 alongside my previous php version. After that when I tried running composer update on a symfony2 project, I get an error:

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

I have currently enabled php 5.6.27 using sudo a2enmod php5.6 command. On my browser the output of phpinfo() displays php version as 'PHP Version 5.6.27-1+deb.sury.org~xenial+1'. Also the php-json module is enabled as shown in the screenshot below

enter image description here

In the terminal the output of php -v is:

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

As suggested in the answer on this post PHP Fatal error: Call to undefined function json_decode(), I've tried running sudo apt-get install php5-json, but it outputs:

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.

After this I've restarted the apache2 server but on running composer update it still gives me same error.

All help is appreciated.

Community
  • 1
  • 1
utkarsh2k2
  • 1,046
  • 3
  • 19
  • 42

1 Answers1

1

Your issue is due to the fact that php json module is not enabled for cli. (php cli vs apache)

  • Try php --ini to find your php ini paths.
  • Look into /etc/php/5.6/mods-available for json.ini.
  • Check /etc/php/5.6/cli/conf.d whether there is a symbolic link to to the above file.
  • If not, create a symbolic link to json.ini named eg. 20-json.ini.

Note that maybe the location for php 5.6 modules is different on your installation.

This may help:

Is there any command to enable/disable a php extension from command line?

Jannes Botis
  • 11,154
  • 3
  • 21
  • 39