Installing Redis on Sakura VPS CentOS 6.5 and Running It from PHP
Redis - (pronounced “Redis”) Remote Dictionary Server
A tool that lets you build a Key Value Store.
Environment
- Sakura VPS CentOS 6.5 Final
- Redis 2.8.19 (latest Stable as of February 2015)
- PHP 5.4.34
Steps
- Install Redis
- Configure Redis
- Test setting and retrieving Redis data
- Register Redis with chkconfig
- Install phpredis
- Add redis.so to php.ini
- Restart httpd
- Call from PHP and verify behavior
Prepare for the Redis installation
1 | $ sudo su |
Install Redis
- Download the compressed archive → extract → compile
1 | # cd /usr/local/src |
Extract and build the archive
1 | # tar xzvf redis-2.2.12.tar.gz |
Back up the config file
1 | # cp -p redis.conf redis.conf.org |
Edit redis.conf
1 | # vi redis.conf |
Changes to redis.conf
1 | # daemon |
Start the Redis server
1 | # redis-server redis.conf |
Start the client
1 | # src/redis-cli |
Quick test of the Redis configuration
Set data
1 | # set tanaka test |
Retrieve data
1 | # get tanaka |
Create a startup script (under init.d)
1 | sudo cp /usr/local/src/redis-2.2.12/utils/redis_init_script /etc/init.d/redis |
Copy the config file
1 | sudo mkdir /etc/redis |
Edit the config file
1 | sudo vim /etc/redis/6379.conf |
1 | #daemonize no デーモン化の設定を有効化。 |
Create the directory that will be used later
1 | sudo mkdir /usr/local/redis/ |
Register it in the chkconfig list so it starts at boot
1 | /sbin/chkconfig --add redis |
service redis does not support chkconfig
The error above is printed when there is a space immediately after the #, so remove that space.
1 | cat /etc/init.d/redis |
The first line, # as it does use of the /proc filesystem., is the cause.
Delete this line.
After making the change above, register it in the chkconfig list once more.
- If possible, reboot and verify that it starts.
1 | reboot |
Install phpredis
// Fetch the source with git
** Edit php.ini
1 | [redis] |
Check that redis has been added as a PHP module
1 | php -m | grep redis |
Restart apache to apply the php.ini update
1 | service httpd restart |
Verify that the following example displays correctly
1 | <?php |
Installing Redis on Sakura VPS CentOS 6.5 and Running It from PHP
https://kenzo0107.github.io/en/2014/09/12/php-redis-on-centos6.5-sakura-vps/