Cannot Find Redio.so on CentOS7 with PHP7

CentOS7 PHP redis.so extension

I encountered this problem couple days ago while supporting pre-sales team to build up an environment. They need redis in the environment and the platform is running with PHP7, so I need to install redis package/extension so that PHP7 can communicate with redis.

There are a lot of CentOS repositories, you can refer here. As far as I understand, if you installed the packages from particular repository, then you will not encounter the issue that PHP cannot load/locate redis.so. In my case, I installed redis using pecl.

pecl install redis

Right after installation, it says php.ini could not be found, so I need to add extension=redis.so to php.ini myself and that’s where the problem begins.

CentOS7 PHP redis.so extension

Problem

It took me a while to solve this problem mainly cause I really did not know what’s the problem. I could only tell that PHP was yelling it could not load redis.so but I was so certain that redis.so was at where it was supposed to be.

After turning to google and tried all kinds of possible solutions and in the end, I found the root cause and the solution was so easy that I almost drop my jaw.

Take a closer look

In the error message, there is a section saying undefined symbol: php_json_decode_ex and it turns out that this is the root cause. In simple words, json.so NEEDS to be loaded before redis.so and I did not configured PHP that way. Once the order was adjusted, the problem was solved.

Solution

There are two ways to solve this problem. The easiest and fastest way is to create a redis.ini at the location of your php.d folder with content extension=redis.so. I am not going to explain PHP in depth in this post, probably next time. Note that different PHP version and Linux distribution varies but the idea is the same.

  1. Remove extension=redis.so from php.ini file. (To stop the error msg)
  2. Locate your php.d location and create redis.ini with extension=redis.so in it.
  3. That’s it, now your PHP loads redis extension successfully!

php -m | grep redis
php -i | grep “.ini files”
echo “extension=redis.so” > /etc/opt/rh/rh-php72/php.d/redis.ini

CentOS7 PHP redis.so extension

As I mentioned before, there are two ways to solve this problem. The second way is first add extension=json.so into php.ini too. Make sure this line is before/above extension=redis.so.

CentOS7 PHP redis.so extension

At this moment, you will have another warning saying json is double loaded.

CentOS7 PHP redis.so extension

That’s cause json extension already has a .ini file in your php.d directory, so either mark it or delete it from php.d folder. Once done, warning will go away and everything is settle!

CentOS7 PHP redis.so extension

Reference

php7使用與安裝redis(作業系統centos7)
php-json之undefined symbol: php_json_decode_ex

--

--

AWS Certified SA, SysOps & Developer Associate, Alibaba Cloud certified SA. Focusing on Azure, Prometheus w/ Grafana, ELK and K8S now.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yst@IT

AWS Certified SA, SysOps & Developer Associate, Alibaba Cloud certified SA. Focusing on Azure, Prometheus w/ Grafana, ELK and K8S now.