How to install memcache on Mavericks? (MAMP) - php

I have MAMP on my machine, and I would like to install memcache for php, because one of my project throws errors like Fatal error: Class 'Memcache' not found.
I installed X-Code from appstore, and libevent, memcached, libmemcached with homebrew.
Then..
cd /tmp; pecl download memcached
gzip -d < memcached-2.2.0.tgz | tar -xvf -
cd memcached-2.2.0; phpize
./configure; make
sudo make install
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20100525/
After that I copied memcached.so and memcache.so to my extension_folder:
/Applications/MAMP/bin/php/php5.5.10/lib/php/extensions/no-debug-non-zts-20121212/
and added extension = memcached.so to my php.ini.
I still get fatal error.. what's the problem?

How to install memcache and memcached on any version MAMP and on any version of php on LINUX/MAC by yourself?
open a terminal
install brew:
ruby -e "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install memcached
brew install libmemcached
start memchached (daemon) as you whish
To have launchd start memcached at login:
ln -sfv /usr/local/opt/memcached/*.plist ~/Library/LaunchAgents
Then to load memcached now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
Or, if you don't want/need launchctl, you can just run:
/usr/local/opt/memcached/bin/memcached
download the SAME !!! VERSION of php source code from php.net what you want to use with MAMP
extract to /tmp
configure -> make -> make install
when "make install" ends you can see ON THE TERMINAL SCREEN !!! the paths where the php binary was installed on your system
cd that path where your binary located
pecl i memcache
follow onscreen !!! instruction and copy memcache.so
if no instruction, which I doubt it then locate YOUR VERSION of php extensions directory/no-debug-non-zts... or copy memcache.so to here on MAC
/Applications/MAMP/bin/php/[PHP VERSION YOU
USE!!!]/lib/php/extensions/no-debug-non-zts-20060613
add to php.ini (the same version you downloaded and using with mamp) this line: extension=memcache.so;
phpinfo(); and check memcached appears.
OK ITS DONE !!! NOW -> have a beer :)

Related

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 :)

How to install PHP extension 'pcntl' on my Mac OSX

My operating system is:Mac OSX 10.11
I'm trying to install Phabricator on my Mac, when I execute the command of
phabricator cpopt$ ./bin/phd start
I got an error:
"ERROR: The PHP extension 'pcntl' is not installed. You must install it to run daemons on this machine."
I've search this problem on google and I got lots of solutions,but they all don't work to me,I'm almost in despair.
How can I achieve that?
Do you have brew installed (read here to install http://brew.sh/)?
Try:
brew install php
or if you need to install PHP 5.6 with brew you could do this:
brew install php#5.6
Then to include it in your PATH (if it is not automatically added), it may be necessary to run the commands in the CLI you may need to update your path, e.g. (this is the case if you were to brew install php#7.1 but was not the case when I just tested with brew install php - if you are using bash instead of zsh, change .zshrc to .bashrc.
echo 'export PATH="/usr/local/opt/php#7.1/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php#7.1/sbin:$PATH"' >> ~/.zshrc
If that doesn't work, I wonder if phabricator is calling the right version of php.
Out of curiosity, what is the output you get from this? That is what phabricator is using to determine your php version.
/usr/bin/env php -v
Also... is your php.ini updated to have the pcntl extension? Run this to see your modules and look for pcntl:
php -i | grep pcntl
Double-check the php.ini that the php-cli is running:
php -i | grep php.ini
I had to do this to install the platform.sh command line tool. This was the top hit in Google so I'm adding this information. The process I followed was as below.
In Terminal:
Add yourself to the 'wheel' user group.
sudo dscl . append /Groups/wheel GroupMembership <username>
Grant group write access to /usr/local/bin
sudo chmod -R g+w /usr/local/bin
Link libpng for brew
brew link libpng
Install pcntl for php (5.6 in my case)
brew install homebrew/php/php56-pcntl
Just in case anyone else uses MAMP, I recently updated it to the latest version. Then I was getting the error
"ERROR: The PHP extension 'pcntl' is not installed. You must install it to run daemons on this machine."
I had not restarted my terminal since I updated it. After reloading the session everything worked fine.

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

PHP redis error

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());")

Can I install the memcached PHP extension with PECL?

I'm having trouble installing the "memcached" PHP extension from PECL, though I can successfully installed the "memcache" extension. (They are separate PHP extensions.)
For example, these commands work okay:
$ sudo pecl install memcache
$ sudo pecl install APC
$ sudo pecl install oauth
However, attempting to install memcached causes errors:
$ sudo pecl install memcached
...
ld: library not found for -lmemcached
collect2: ld returned 1 exit status
make: *** [memcached.la] Error 1
ERROR: `make' failed
I'm using pecl, memcached, and libmemcached from Mac Ports (macports.org) on a recent Intel Mac. The libmemcached libraries can be found in /opt/local:
/opt/local/include/libmemcached
/opt/local/include/libmemcached/libmemcached_config.h
/opt/local/lib/libmemcached.2.0.0.dylib
/opt/local/lib/libmemcached.2.dylib
/opt/local/lib/libmemcached.a
/opt/local/lib/libmemcached.dylib
/opt/local/lib/libmemcached.la
Any idea what I may be doing wrong?
Andrei Zmievski (developer of the memcached plugin) kindly answered my email request with the following instructions:
$ pecl download memcached
$ tar zxvf memcached-1.0.0.tgz (or whatever version downloads)
$ cd memcached-1.0.0
$ phpize
$ ./configure --with-libmemcached-dir=/opt/local
$ make
$ sudo make install
This worked perfectly.
same situation here. i had to do the above, but with explicit path names (i run my php etc. out of /opt/local)
/opt/local/bin/pecl download memcached
tar zxvf memcached-1.0.0.tgz
cd memcached-1.0.0
/opt/local/bin/phpize
./configure --prefix=/opt/local --with-php-config=/opt/local/bin/php-config --with-libmemcached-dir=/opt/local
make
make install
normally this kind of stuff is pretty simple on os x with macports, but there is no php5-memcached package yet (only one for the older, memcache (no "d") package). oh, an i also had to install an older version of libmemcached, since the latest version didn't compile on os x 10.5.8 for me. oy!
As you've seen, the new memcached extension, uses libmemcached to do the heavy lifting. If it were Linux, I'd say that it was possible that you don't have /opt/local/lib/ listed in ld.so.conf (and run 'ldconfig').
MaxOSX doesn't use that though. It is, however installable from 'ports' apparently. http://lsimons.wordpress.com/2008/05/01/serious-php-part-1/
Well, after many tries only this solution works for me.
Install XAMPP
Install brew (https://github.com/Homebrew/homebrew/wiki/Installation)
$ brew
install libmemcached
cd /Applications/XAMPP/xamppfiles/bin/
$ sudo ./pecl install memcached
Build process completed successfully Installing
'/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/memcached.so'
install ok: channel://pecl.php.net/memcached-2.2.0 configuration
option "php_ini" is not set to php.ini location You should add
"extension=memcached.so" to php.ini
VOILA !!

Categories