Install json extension of php in CentOS

Source: Internet
Author: User
Tags centos server

After a new program is uploaded to a CentOS server today, it is found that some pages cannot be displayed or are incomplete. When viewing Apache error logs, a large number of PHP error messages are displayed:

PHP Fatal error: Call to undefined function json_decode ()

This is a typical prompt that PHP components are not installed. The error message means that a function XXX cannot be found. After investigation, this function is included in the json extension of PHP. The next step is simple. You only need to install the json extension to eliminate this error and restore the webpage to normal.

First, try the simplest method. Enter the yum command to install: yum install php-json. The result shows that the extension package does not exist. If you try to input yum install json again, no more. Enter yum search php-to list all PHP extension packages for search. The extension package related to json is still not found.

Since yum does not bring it, you have to compile the killer tool in Linux. I searched related articles on the Internet and operated them on my own. In fact, it is not very difficult to compile a json file. As a result, I learned the following:

1. Switch to the tmp directory to download the json source package. It is a good habit to enter the tmp directory during temporary download operations, because the Linux system will automatically clear the tmp directory during startup, so as to keep the hard disk files clean and tidy. Of course, if you want to keep this source package, you can download it to your favorite directory.

# Cd/tmp

# Wget http://www.aurore.net/projects/php-json/php-json-ext-1.2.1.tar.bz2

2. decompress the downloaded file:

# Tar xvjf php-json-ext-1.2.1.tar.bz2

3. Go to the source code directory:

# Cd php-json-ext-1.2.1

4. Prepare the compiling environment. In this step, you do not directly perform Step 1. If you encounter any problems, this step does not matter. To avoid unnecessary troubles, check whether the compiling environment is ready!

# Yum install php-devel automake autoconf libtool gcc

5. Prepare the compiling environment for the PHP module:

# Phpize

6. start compiling the json module:

#./Configure

# Make

# Make install

7. Configure php. ini. First open the php. ini file:

# Vim/etc/php. ini

Note: Here, my php. ini is under the/etc directory. If your php. ini is not here, modify the path to your php. ini path.

Add the following line to the last line:

Extension = json. so

Enter: wq to save and exit.

8. Restart the Apache service:

#/Etc/init. d/httpd restart

After successful restart, you can use phpinfo () to check whether json information exists. I tried to open the page with the previous error and it was completely normal. Everything is OK.

Reference: http://hi.baidu.com/zhujinyu/blog/item/3d2915121ed51659f919b852.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.