I am trying to install php-redis via pecl.
Running this:
php -i | grep API
gives this: PHP API => 20220829
I then run pecl install redis
and I get the message:
...
running: phpize
Configuring for:
PHP Api Version: 20220829
Zend Module Api No: 20220829
Zend Extension Api No: 420220829
...
Build process completed successfully
Installing '/usr/lib/php/20230831/redis.so'
install ok: channel://pecl.php.net/redis-6.0.2
Extension redis enabled in php.ini
As you can see, there is a mismatch between the apis.
When I inspect php with php -i | grep redis
, I get this error message:
PHP Warning: PHP Startup: redis: Unable to initialize module
Module compiled with module API=20230831
PHP compiled with module API=20220829
These options need to match
in Unknown on line 0
I am on php8.2, so api 20220829 is correct.
My question is, how can I install redis for api 20220829 to match my php version.
Your system is not just pulling 20230831
out of the air, so it appears that you have multiple versions of PHP installed. 20230831
is for PHP 8.3.
% php -v
PHP 8.3.10 (cli) (built: Aug 2 2024 15:31:39) (NTS)
Copyright (c) The PHP Group
% php -i | grep API
PHP API => 20230831
I'm guessing that you've likely got php
pointing to one version and php-config
pointing to another. You can verify this by running php-config
, to make sure it matches what php
outputs:
% php-config
Options:
--extension-dir [/usr/lib/php/20230831]
--phpapi [20230831]
--version [8.3.10]
To rectify, you'll have to run alternatives for all the php utilities, not just php itself. I simplify this with a few aliases in my .bashrc
:
alias php74='sudo -- sh -c "for P in php php-config phpize phar phar.phar; do update-alternatives --set \$P /usr/bin/\${P}7.4; done"'
alias php80='sudo -- sh -c "for P in php php-config phpize phar phar.phar; do update-alternatives --set \$P /usr/bin/\${P}8.0; done"'
alias php81='sudo -- sh -c "for P in php php-config phpize phar phar.phar; do update-alternatives --set \$P /usr/bin/\${P}8.1; done"'
alias php82='sudo -- sh -c "for P in php php-config phpize phar phar.phar; do update-alternatives --set \$P /usr/bin/\${P}8.2; done"'
alias php83='sudo -- sh -c "for P in php php-config phpize phar phar.phar; do update-alternatives --set \$P /usr/bin/\${P}8.3; done"'
alias php84='sudo -- sh -c "for P in php php-config phpize phar phar.phar; do update-alternatives --set \$P /usr/bin/\${P}8.4; done"'
Then I can just type php82
to switch everything to v8.2, etc.