Skip to content

Instantly share code, notes, and snippets.

@jeroendesloovere
Last active November 27, 2023 09:58
Show Gist options
  • Save jeroendesloovere/be002d64cd6c73f5435da49ceb2d6b93 to your computer and use it in GitHub Desktop.
Save jeroendesloovere/be002d64cd6c73f5435da49ceb2d6b93 to your computer and use it in GitHub Desktop.
install redis

Redis Installation

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:

make test

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.

  1. 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

  1. 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:
extension=/usr/local/Cellar/php56-redis/2.2.8/redis.so

Restart MAMP and the error will be gone and Redis can be used when starting it up redis-server.

Installation problems

Older alternative way

When using MAMP

Using your own php version instead of 5.3.2.0

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.

  1. Make sure you've tapped homebrew-dupes and homebrew-php with: brew tap homebrew/dupes and brew tap josegonzalez/php.

  2. Install memcached and redis for PHP Homebrew: brew install php53-memcache and brew install php53-redis.

  3. Go into MAMP and navigate to: File menu > Edit Template > PHP > PHP 5.3.2.0 php.ini.

  4. 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"

Restart MAMP.

Your PHPInfo should now mention Memcache and Redis.

@zqbinary
Copy link

zqbinary commented May 6, 2018

brew install homebrew/php/php56-redis

Updating Homebrew...

Error: homebrew/php was deprecated. This tap is now empty as all its formulae were migrated.

@frumbert
Copy link

frumbert commented May 22, 2018

brew install php56-redis
Updating Homebrew...
Error: No available formula with the name "homebrew/php/php56-redis"
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/php is shallow clone. To get complete history run:
git -C "$(brew --repo homebrew/php)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment