PHP redis error - php

I installed the php redis extension. But when I run the test code, I got the following error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/redio.so' - /usr/lib/php5/20090626+lfs/redio.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Fatal error: Class 'Redis' not found in /var/www/test/redisTest.php on line 2
My php version is 5.3.10, I installed the new version of phpredis.
May I get your help?
THANKS!
The install steps are:
git clone https://github.com/nicolasff/phpredis.git
cd phpredis
phpize
make
make install
Then add a config file in /etc/php5/fpm/confi.d to load redis.so

I use PHP 5.3 and installing PHP-Redis using below steps worked just fine for me:
Install pecl extensionsudo pecl install redis
In php.ini, you may need set extension_dir to correct value. (can be usr/lib64/php/modules as above command placed the redis.so in this directory). In my case, I didn't set this.
Add below line to php.ini:extension=redis.so
Restart Apache/PHP-FPM

To verify if you have got redis installed you can do this
php -m | grep redis

Create a file PHP with echo phpinfo(); in it and see if the module is showing up. If you do not see the module then it is not being loaded correctly.

In the PHP5.3 and Amazon Linux AMI (Same as Centos OS 5)
install libs
yum install php-pear php-devel make gcc wget
install redis
cd /opt/
mkdir /opt/redis
wget https://redis.googlecode.com/files/redis-2.6.14.tar.gz "or last version"
tar -zxvf redis-2.6.14.tar.gz
cd redis-2.6.14
make
make install
install php-redis by pecl
pecl install redis
configuration option "php_ini" is not set to php.ini location
You should add "extension=redis.so" to php.ini
reload the web service httpd
service httpd reload
verify that the extension has been installed
php -m
[PHP Modules]
bz2
...
**redis**
...
[Zend Modules]

Download the proper library file according to your server environment( ex. x86). also, check for your PHP is thread-safe or not and download the Redis library accordingly. then place the library file inside the extension folder. you need to mention the library inside your php.ini as given below.
extension=redis.dll
then restart the server once, and check it's working properly or not.
if you have command line PHP, you can check it in the command line PHP as,
php r("print_r(get_loaded_extensions());")

Related

Mac OS: Intl extension is not loaded

macOS Mojave 10.14.3
PHP 7.1.23
Prestashop 1.7.5.1
I tried to install PHP intl extension on my local server in order to use Prestashop.
I added extension=php_intl.so to etc/php.ini
When I try to install Prestashop I get Intl extension is not loaded.
$ php -m | grep intl
When I do $ php -m | grep intl, I get:
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/pecl/20160303/php_intl.so' - d
lopen(/usr/local/lib/php/pecl/20160303/php_intl.so, 9): image not found in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/pecl/20160303/php_intl.so' - dlopen
(/usr/local/lib/php/pecl/20160303/php_intl.so, 9): image not found in Unknown on line 0
intl
It seems that the file php_intl.so doesn't exist.
$ sudo pecl install intl
I also tried $ sudo pecl install intland I get:
make: *** [php_intl.lo] Error 1
ERROR:make' failed`
$ curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1
I also tried $ curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1 and it doesn't create the intl.so file.
How can I solve this problem?
Brew's PHP 7.1, 7.2 and 7.3 all have INTL enabled by default.
Most probably, you're just using your Mac OS' bundles version of PHP.
Run
ls -l $(which php)
to find out where the current PHP binary is located and whether it is symlinked to a Brew installation or not. In my case, for example:
lrwxr-xr-x 1 27 May 23 16:30 /usr/local/bin/php -> ../Cellar/php/7.3.5/bin/php
Meaning that my php is linked to Brew's 7.3.5 version.
If you are NOT using Brew's PHP, you'll see something like
-rwxr-xr-x 1 11169664 Mar 21 07:09 /usr/bin/php
Installing PHP through Brew
Find out whether you've already installed PHP:
brew list | grep php
If there is any output, and your version of PHP is present, go to step 2, or use step 1 to update PHP to the latest version.
1. Install Homebrew's PHP
brew install php#7.3
(or 7.2, 7.1). If Brew complains about not being able to find a formula, you might have messed with taps. Instead of php#7.3, you could try to supply the full path to the current php formula:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/php.rb
Still not working, check whether you are running a recent version of Homebrew brew --version.
Homebrew 2.1.3-31-geaf2370
Homebrew/homebrew-core (git revision fd1ef; last commit 2019-05-25)
Homebrew/homebrew-cask (git revision 16d50; last commit 2019-05-26)
2. Link Homebrew's PHP
Now, to have php 'in your path', there are two options.
a) Either homebrew's version must be linked from its install location (/usr/local/bin/Cellar/php....) to a directory in your path (e.g., /usr/local/bin). To do this, run:
brew link --force php#7.3
If you are not able to link, this is typically caused by set permissions or System Integrity Protection. In the first case, try sudo chown "$USER":admin /usr/local/bin/php.
b) Or, add the /usr/local/opt/php#7.3 directory (opt-prefix) to your $PATH variable. E.g., for Bash:
echo 'export PATH="/usr/local/opt/php#7.3/bin:/usr/local/opt/php#7.3/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
3. Validate installation
ls -l $(which php)
should show that php is linked to a Homebrew PHP installation in /usr/local/bin/Cellar.
php -v
should show the recently installed version of PHP. Try to restart your terminal if that's not the case.
php -i | grep -i intl
should show some information about the current install of intl.
If you're using webservers and/or PHP FPM, this is the time to restart those services. (Or restart your system, if you don't know how to do that and cannot figure out).
Possible issues
If you still get warnings about missing extensions (Unable to load dynamic library, etc.), then your php.ini is messed up.
Find the current location of php's ini
$ php -i | grep \.ini
Configuration File (php.ini) Path => /usr/local/etc/php/7.3
Loaded Configuration File => /usr/local/etc/php/7.3/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed => /usr/local/etc/php/7.3/conf.d/ext-opcache.ini
....
Edit /usr/local/etc/php/7.3/php.ini and find the offending extension load (e.g., extension="myext.so"). Comment out those that cannot be found.
Homebrew permissions
Some argue that it's a good idea to chown /usr/local.
sudo chown -R "$USER":admin /usr/local
This will make installing things here, by hand and through Homebrew, a lot easier, but also a bit less secure too, since non-root processes are now allowed to write here too.
Your web-application is using a different version of PHP.
Make sure that it doesn't... The configuration of this depends on the used webserver. A first step would be to output the current PHP configuration in your web-application with <?php phpinfo();.
This explains steps for Apache.
Another way to get a webserver + PHP stack running quicly is using Laravel Valet.
Installing additional extensions
To install additional PHP extensions, use PEAR.
pear -V
should output the current PEAR and PHP version.
PEAR Version: 1.10.9
PHP Version: 7.3.5
Zend Engine Version: 3.3.5
Now, to install an extension, for example, PHP's yaml extension:
pear install yaml
I have seen a lot of answers about this problem and anyone helped me, but the last (of course). This is for XAMPP´s use.
Xcode is needed.
Download the version of php you use in xampp from php.net.
Extract it and open the extracted folder in a terminal using cd.
Change to subfolder ext/intl.
Run these commands to build the extension:
/Applications/XAMPP/bin/phpize
./configure --enable-intl --with-php-config=/Applications/XAMPP/bin/php-config --with-icu-dir=/Applications/XAMPP/xamppfiles/
make
sudo make install (password required)
Delete all files you downloaded and also the extracted folders.
Add to php.ini file in xampp/etc folder line
extension="intl.so"
Original link: https://community.apachefriends.org/viewtopic.php?p=255061&sid=27afc55649dfe6ea7b0824cb0bb8486b
Since php 7 it's not necessary load the extension php_intl.so, what do you need to do?, edit your php.ini and delete or comment the line that is loading the extension php_intl.so, after this reload your apache and try again.
There might be an issue with brew
You could try to use this as mentioned there:
brew tap kyslik/homebrew-php
brew install kyslik/php/php71-intl
i tried all but intl not working in mac so please uninstall xampp and install mamp it will work
So, on Pecl Official site ( https://pecl.php.net/package/intl ), it's clear that Intl package is not maintained anymore and has been superseded. Since PHP 5.3.0 you don't need to use Pecl to install intl extension, it's bundled with PHP.
But, it's missing on native instalation of PHP 7.1.24 on Mac OS Mojave.
if you wanna use only native apache and php pre-installed instead of using homebrew, do this:
Download PHP 7.1 from php.net, install XCode Command Line Tools, ICU (http://site.icu-project.org/), Autoconf, reinstall the developer tools header files, and finally install Intl extension using phpize.
Important: you'll have to disable SIP.

Install phpredis MAC OSX

Can anyone help me install php-redis in MAC OSX .
brew install php-redis
not working.
pecl install php-redis
also not working getting -
invalid package name/package file "php-redis".
Homebrew Error:
homebrew_error
git clone https://www.github.com/phpredis/phpredis.git
cd phpredis
phpize && ./configure && make && sudo make install
Add extension=redis.so in your php.ini
brew services restart php#7.2
make test
You can check working or not
php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"
As of 2019, with homebrew php7.2 and up, pecl is now installed by default alongside the php binaries.
To see this for yourself type which pecl.
Steps to install
Check your version of redis, then find a suitable version of the extension here.
If unfamiliar with pecl, type pecl to see the options.
Issue pecl install redis-5.0.2. (or your version). Enter no to each question asked if you're not sure.
If that succeeds check the new file it created at: /usr/local/lib/php/pecl/20180731/redis.so
The install will have added extension="redis.so" to top of your php ini.
Check that by opening the file /usr/local/etc/php/7.3/php.ini.
(assuming you're on 7.3 there)
brew services restart php.
php -i | grep Redis
Redis Support => enabled
Redis Version => 5.0.2
This is what I just did in September 2019 and it works for me.
If what mwal wrote above doesn't work (please try his/her answer first),
first, try to uninstall first (if you have it but broken):
sudo pecl uninstall redis
and after that run:
sudo pecl install redis
After that, ini the php.ini, use full path for the extension.
Mine was /usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so (assuming you are using php#7.3)
so at the top of my php.ini file is like this:
extension="/usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so"
Here are steps to use pickle, for PHP >= 7.3 (tested with 8.1):
brew install pickle
pickle install redis
Find your php.ini location via php -i|grep php.ini
Edit the php.ini, insert extension=redis. Preferable at Dynamic Extensions section.
No restart of Apache httpd service is required. You may test your PHP code with Redis
Bonus
If you use VS Code, to enable intellisense / auto complete, at Preference -> paste intelephense.stubs at Search setting box -> Add Item -> select redis.
If you got the following error,
Please make sure the PHP Redis extension is installed and enabled
despite doing everything in the verified answer above, try valet restart . It worked for me
I have tried all these solutions but didn't work for me for a while so I tried this link https://developer.redis.com/develop/php/ from the original docs and it works as charm
If someone gets an error during sudo pecl install redis
Warning: mkdir(): File exists in System.php on line 294
PHP Warning: mkdir(): File exists in /opt/homebrew/Cellar/-----/pear/System.php on line 294
that means you need to create the broken directory manually.
Try to create the directory...
pecl config-get ext_dir | pbcopy
mkdir -p {paste clipboard value}
# in my case, it was
mkdir -p /opt/homebrew/lib/php/pecl/20200930
Now try to install any pecl extensions.
sudo pecl install redis
After installing any extension, restart php
brew services restart php
Happy coding :)

Install PHP modules on CentOS

I'm trying to install PHP 5.5.21 on CentOS 7.0.
When I execute php -v
I get about 10 modules errors like this one:
PHP Warning: PHP Startup: curl: Unable to initialize module
Module compiled with module API=20100525
PHP compiled with module API=20121212
I tryed to install or update package with pecl install curl and pecl upgrade curl
But pecl always responds :
No releases available for package "pecl.php.net/curl"
And yum install php-curl says:
Package php-common-5.4.16-23.el7_0.3.x86_64 already installed and latest version
Nothing to do
How can I do to fix modules error?
Try running: find / -name curl.so
Then copy the directory it finds curl.so in and create a symbolic link to it where the rest of your working .so files are stored:
cd <where your working .so files are>
ln -s <where curl.so is> curl.so
Then edit your php.ini file and enable the extension:
extension=curl.so
Restart apache:
service httpd restart
service apache2 restart `#If the service is named apache2 rather than httpd`
This resolved my problem when I had a similar issue.
I finally solved my problem removing the custom PHP installation and using this tutorial to install PHP 5.5

unable to load mongo extension for php

After trying for two days to get this to run;
sudo pecl install mongo
I finally got it done and added the extension to php.ini only to find out that it will not work for me.
This is what the install output was at the end;
Libraries have been installed in:
/tmp/pear/temp/pear-build-rootVYRzXc/mongo-1.5.8/modules
running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootVYRzXc/install-mongo-1.5.8" install
Installing shared extensions: /tmp/pear/temp/pear-build-rootVYRzXc/install-mongo-1.5.8/usr/lib/php5/20090626/
Installing '/usr/lib/php5/20090626/mongo.so'
install ok: channel://pecl.php.net/mongo-1.5.8
# I edited etc/php54/php.ini here
sudo service apache2 restart
php --ri mongo
Extension 'mongo' not present.
But when I did mongo --version I get MongoDB shell version: 1.4.4 which may be from my modulus installation. Could that cause mongo not to load?
When trying;
$mongoConn = new MongoClient("mongodb://<user>:<pass>#proximus.modulusmongo.net:27017");
I get;
Fatal error: Class 'MongoClient' not found
Verify that mongo.so is found on in extension_dir:
php -i | grep extension_dir
Then cd to that folder and check for presence of mongo.so.
If present, make sure you have this in php.ini
extension=mongo.so
If this does not work: In certain virtual systems, such as those based on Docker, you may need to install your extension as the user associated with the "domain" or instance. A global (root user) installation may not work.

Can't phpize or configure an extension in OS X 10.9 Mavericks

I am trying to build the memcached extension on OS X 10.9 Mavericks for use with the built in PHP 5.4, initially I tried pecl install memcached but that threw the following.
checking for zlib location... configure: error: memcached support requires ZLIB. Use --with-zlib-dir=<DIR> to specify the prefix where ZLIB headers and library are located
ERROR: `/private/tmp/pear/install/memcached/configure' failed
So I created a tmp directory and executed pecl download memcached, unzipped the code and cd'd to the appropriate directory.
Trying to phpize it returned the following:
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
I had brew installed zlib a while ago and pointed ./configure at my installation.
./configure --with-zlib-dir=/usr/local/Cellar/zlib/1.2.8 I was greeted with the following error message:
checking for session includes... configure: error: Cannot find php_session.h
So now I'm wondering the best course of action here... /usr/include/ doesn't exist at all... is this a Mavericks thing? I don't remember having this problem in 10.8 at all.
I could try brew installing php-devel but I presume that isn't going to be the right version of what I need? Any help would be greatly appreciated here
Update
locate php_session.h reveals
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/php/ext/session/php_session.h
should I just ln -s this to the expected location or is there some way to do this via XCode? I have the command line tools installed...
run xcode-select --install to install the XCode5 Command Line Tools, then sudo pecl install memcache. You should be good to go.
After install XCode5 Command Line Tools as afessler sugest (xcode-select --install) I couldn't do the "sudo pecl install memcache" because pecl was missing.
I had to install PEAR and PECL following this guide: http://techtastico.com/post/como-instalar-pear-y-pecl-en-os-x-mavericks/.
Then all worked good. Thanks!
I had this problem and it was due to MAMP not having all the PHP sources.
I found this really helpful solution that explains how to download and configure them:
https://stackoverflow.com/a/11175197/369326
Note that the MAMP components doesn't include the extras for any versions of PHP higher than php 5.4.10 but you can download the extras from http://php.net/releases.
As said above but not using xcode install
Try installing pecl manually:
curl -O http://pear.php.net/go-pear.phar
sudo php -d detect_unicode=0 go-pear.phar
and then:
sudo pecl install memcache
See more at: http://jason.pureconcepts.net/2012/10/install-pear-pecl-mac-os-x/#sthash.x2LKdqj6.dpuf

Categories