10

My server configurations:

[root@server ~]# php -v 
PHP 7.0.22 (cli) (built: Aug 7 2017 16:18:27) ( NTS ) 

[root@server ~]# nginx -v 
nginx version: nginx/1.10.2

OS: CentOS 7.3.1611 (Core)

Details of my YUM installation:

[root@server ~]# yum list installed | grep php
php70u-cli.x86_64                       7.0.22-2.ius.centos7           @ius     
php70u-common.x86_64                    7.0.22-2.ius.centos7           @ius     
php70u-fpm.x86_64                       7.0.22-2.ius.centos7           @ius     
php70u-fpm-nginx.noarch                 7.0.22-2.ius.centos7           @ius     
php70u-mysqlnd.x86_64                   7.0.22-2.ius.centos7           @ius     
php70u-pdo.x86_64                       7.0.22-2.ius.centos7           @ius  

Here is the details of the investigation: I tried executing following code in test.php:

Here are my system details: PHP Version => 7.0.22 OS: I am trying to execute following code in test2.php:

<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
?>

And, getting the following error:

[root@server ~]# php /tmp/test2.php
**PHP Fatal error:  Uncaught Error: Call to undefined function json_encode() in /tmp/test2.php:3**

How to resolve this?

3 Answers 3

15

I run the following command to install json for php7 and it worked perfectly fine.

[root@server dbs]# sudo yum install php70u-json
Sign up to request clarification or add additional context in comments.

1 Comment

If you're a Fedora 22+ user, the command line is: #sudo dnf install php-json
5

For me was enough with:

 yum install php-json

I'm using php7.2

Comments

2

Install:

  php70u-json.x86_64 0:7.0.32-1.ius.centos7

Result:

Complete!
[root@server1 ~]# systemctl restart httpd

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.