Here we install redis on MacOS and enable redis in PHP. Install redis on Mac OS
First, install it. it will be installed under/usr/local/bin by default.
The code is as follows:
Cd/tmp
Wget http://redis.googlecode.com/files/redis-2.6.9.tar.gz
Tar-zxf redis-2.6.9.tar.gz
Cd redis-2.6.9
Make
Sudo make install
Then download some configuration files (mainly opening deamon and so on, without comparing it with the default configuration)
The code is as follows:
Wget https://github.com/ijonas/dotfiles/raw/master/etc/redis.conf
Sudo mv redis. conf/etc/redis. conf
Sudo/usr/local/bin/redis-server redis. conf
If you do not have the directory permission, you cannot create a directory.
/Var/log/redis. log
/Var/lib/redis/
Redis startup failed
OK. Now we have finished it. your redis has been successfully run.
Try it!
The code is as follows:
/Opt/redis-cli
# Redis 127.0.0.1: 6379> indicates that the service has been connected.
Set anythink helloworld
Get anythink
Exit
Good saw helloworld, which means everything is normal.
What if I need to stop redis or restart it?
The code is as follows:
Cat/opt/redis. pid
# A pid will be obtained after cat, and mine is 44277
Sudo kill 44277
# The Startup method is the same as before.
Set automatic startup and background running
Do the following as root:
Create com. redis. plist under/Library/LaunchDaemons with the following content:
The code is as follows:
Label
Com. redis
RunAtLoad
ProgramArguments
/Usr/local/bin/redis-server
/Etc/redis. conf
Run later
The code is as follows:
Sudo launchtcl load/Library/LaunchDaemons/com. redis. plist
Sudo launchtcl start com. redis
Check the situation:
The code is as follows:
$ Cat/var/run/redis. pid
If the pid number is displayed, it indicates that the pid is running ~
Install php-redis extension
If you need to use redis in PHP, continue reading
The code is as follows:
Curl-O https://nodeload.github.com/nicolasff/phpredis/zip/master
Tar-zxf master
Cd phpredis-master/
Phpize
./Configure
Make
Sudo make install
# A path is prompted at this time.
#/Usr/lib/php/extensions/no-debug-non-zts-20090626/
# Indicates that the extension has been placed in this location
Vim/etc/php. ini
# Add the following content
Extension = redis. so
# Restart apache
Sudo httpd-k restart
# View the extended installation status
Php-m | grep redis
# Redis indicates that the installation is successful.
If the following error message is displayed when phpize is executed
Cannot find autoconf. Please check your autoconf installation
And the $ PHP_AUTOCONF environment variable.
Then, rerun this script.
Download M4 and autoconf respectively.
The code is as follows:
Curl-O http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
Curl-O http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
Note that the apache and php mentioned above are all built-in with MacOS. if you are installing your own phpize, specify the absolute path.
Graphic Management Tools
In addition, redis also has a WEB-based graphical interface management tool called phpRedisAdmin. some Undefined indexes will appear when the service is started, and it will take a while. If you want to try it, run the following command to install it (SourceTree is recommended for git). This management tool supports String, Hash, List, Set, and Zset
The code is as follows:
Git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
Cd phpRedisAdmin/
Git clone https://github.com/nrk/predis.git