1. Download and install Redis
Copy/paste the following code block into your terminal.
# Downloading latest wget http://download.redis.io/redis-stable.tar.gz # Extracting tar xvzf redis-stable.tar.gz # Changing to folder cd redis-stable # Installing make
Optional: test if it works:
Now move redis to a global place:
# Moving "redis-server" to local usr sudo cp src/redis-server /usr/local/bin/ # Moving "redis-cli" to local usr sudo cp src/redis-cli /usr/local/bin/ # Removing the remaining "redis-stable" folder rm -rf ../redis-stable *
We assume that /usr/local/bin is in your PATH environment variable so that you can execute both the binaries without specifying the full path.
2. Connecting “redis” to PHP (and “MAMP”)
Error: Attempted to load class “Redis” from the global namespace.
Redis is installed in step one. But that doesn’t mean that MAMP knows about Redis. Check if this localhost phpinfo page contains “redis”. => If not, follow the following steps to make Redis work with MAMP.
- We must install a connection between PHP and Redis:
We search for the possible installations. Pick the one you need for your php version.
brew search redis
It can be that you first need to execute
brew tap homebrew/dupes, more info about homebrew/dupes
We want to use it in php 5.6 so we install the following:
brew install homebrew/php/php56-redis
Will give as result a path
/usr/local/Cellar/php56-redis/2.2.8, which can vary depending on another version
- Open MAMP Pro and click on “File” > “Edit Template” > “PHP” > “PHP 5.6.10 php.ini” (or the version you are using). Go to the part where “extension=” is being defined and add the following:
Restart MAMP and the error will be gone and Redis can be used when starting it up
Older alternative way
When using MAMP
Using your own php version instead of 18.104.22.168
Adding Memcache and Redis to MAMP 2.1.3 (PHP 5.3.20)
Not sure how long this will be good for, but here’s an easy path to adding Memached and Redis support to MAMP 2.1.3. It depends on the fact that, right now, the Homebrew PHP project and MAMP are using the same versions of PHP. This assumes you have Homebrew and MAMP 2.1.3 installed. I’ll just be describing the process for PHP 5.3.20.
Make sure you’ve tapped homebrew-dupes and homebrew-php with:
brew tap homebrew/dupesand
brew tap josegonzalez/php.
Install memcached and redis for PHP Homebrew:
brew install php53-memcacheand
brew install php53-redis.
Go into MAMP and navigate to: File menu > Edit Template > PHP > PHP 22.214.171.124 php.ini.
Find the “; Extensions” block at line 531. Add the following at the end of the list of current extensions:
# Use the right folders from brew install extension="/usr/local/Cellar/php53-memcache/2.2.7/memcache.so" extension="/usr/local/Cellar/php53-redis/2.2.2/redis.so"
Your PHPInfo should now mention Memcache and Redis.