Cannot Find Redio.so on CentOS7 with PHP7
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.
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.
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.
- Remove extension=redis.so from php.ini file. (To stop the error msg)
- Locate your php.d location and create redis.ini with extension=redis.so in it.
- 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
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.
At this moment, you will have another warning saying json is double loaded.
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!
php-json之undefined symbol: php_json_decode_ex