Composer installing: the json extension is missing

2020-04-08 18:56发布

I wrote in Linux Terminal: curl -s https://getcomposer.org/installer | php It said:

 #!/usr/bin/env php
Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The json extension is missing.
Install it or recompile php without --disable-json

I did this: apt-get install php5-json So, I think, it's installed. But the strange thing is, when I write php -m It gives me a list without json:

[PHP Modules]
bcmath
bz2
calendar
Core
ctype
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
libxml
mbstring
mhash
openssl
pcntl
pcre
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

And when I write php5-fpm -m It sends this:

[PHP Modules]
bcmath
bz2
calendar
cgi-fcgi
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mhash
mysqli
openssl
pcre
PDO
pdo_mysql
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

What am I doing wrong? I haven't found the solution at GitHub and Google

4条回答
爷、活的狠高调
2楼-- · 2020-04-08 19:34

On ubuntu 14.04 for me, I found that the default permissions for the php.ini file /etc/php5/cli/ restrict the file to Root user only, so if you run:

php -m

as non-root, you get far fewer modules than if you run sudo php -m

The fix for this was for me to perform:

sudo chmod a+rx /etc/php5/cli/* -R 

which grants read and execute permissions for that folder and it's contents to everyone.

查看更多
该账号已被封号
3楼-- · 2020-04-08 19:37

Bug php not load extension install

create file php.ini

# /etc/php/7.2/cli/conf.d/php.ini
extension=json.so
extension=phar.so
extension=iconv.so
查看更多
叛逆
4楼-- · 2020-04-08 19:43

On Centos 8 with PHP 7.2, after comprehensive research, I have concluded that the only solid way to fix it is reinstalling PHP with its newest version. (7.4 was the latest version for me) Here you can find others who share the same conclusion; laracasts

查看更多
够拽才男人
5楼-- · 2020-04-08 19:47

You probably need to enable the extension in your php.ini file. To find out where that is for command line PHP, do

php --ini

You should see a line like

Loaded Configuration File: /path/to/php.ini

Open that file and look for extension=json.so. If it's there, uncomment it. If not, add it in. Now you should see json listed when you do php -m and composer should work.

查看更多
登录 后发表回答