Install Redis + Redis PHP + phpRedisAdmin on a battle server in 15 minutes
This article will discuss how to prepare Redis, phpredis (C module for php) and phpRedisAdmin to work on a combat server.
In order to collect everything fully, we need to have on the server:
- gcc 4.5.2 (I compiled under this version, but I think that there will be no problems with others)
- Make 3.81 (Again, the version is not fundamental)
- php5-dev (Version must match php version)
After we make sure that all the dependencies are satisfied, we begin to collect all the components.
We will need:
- Redis 2.4.4 Stable
- phpredis 2.1.3
- phpRedisAdmin
Putting Redis Together
In order to collect Radish, we need the source itself. You can get them from github. Therefore,
https://github.com/antirez/redis/zipball/2.4.4 load the desired tag immediately.
$ wget https://github.com/antirez/redis/zipball/2.4.4
$ unzip 2.4.4
$ cd antirez-redis-04bba69
Now we have all the Redis 2.4.4 sources, it remains to compile them.
Everything is very simple
$ make
$ make test
The first team we assembled Redis, the second we tested it for performance.
Make test will take a long time (about 2 minutes). After the test, the line "\ o / All tests passed without errors!" Should return
Redis is collected, it remains to clear the garbage and take the radishes to the desired directory.
Take all the compiled Redis to the / usr / bin / redis folder. And to start Redis-server, in / usr / bin we will create a redis-server shell file.
We take away Redis files in / usr / bin / redis
We still remain in the antirez-redis-04bba69 folder, where the source code lies
$ sudo mkdir /usr/bin/redis
$ sudo cp src/redis-benchmark /usr/bin/redis
$ sudo cp src/redis-check-aof /usr/bin/redis
$ sudo cp src/redis-check-dump /usr/bin/redis
$ sudo cp src/redis-cli /usr/bin/redis
$ sudo cp src/redis-server /usr/bin/redis
$ cd ..
$ rm -rf antirez-redis-04bba69
We copied all the files from Redis and deleted the source folder, we no longer need it.
Be careful with the last team! sudo is not needed for her, the folder is already in our possession.
Now we need to create a file to run redis-server.
$ sudo vim /usr/bin/redis-server
Instead of vim, you can use any other editor. This is not important. Insert
into the file:
cd / usr / bin / redis && ./redis-server redis.conf
Save, close.
You must be given the right to execute this file.
$ sudo chmod 755 /usr/bin/redis-server
It remains to take redis.conf
$ cd /usr/bin/redis/
$ sudo wget https://raw.github.com/antirez/redis/unstable/redis.conf
$ sudo vim redis.conf
Redis.conf is loaded, it remains to configure it.
Replace
daemonize no with daemonize yes in the configuration file # Let it work like a
timeout 0 daemon with timeout 30 # In case of a bug, a client that doesn’t disconnect will hang forever in memory Redis
loglevel notice on loglevel warning # We have a battle server, at least debug messages
Line 166 you need to uncomment and set the password, for example, requirepass foobared We comment the
line 350, it is not needed.
Save, close.
Launch!
If everything was done correctly, then start the server
$ redis-server
$ telnet localhost 6379
In theory, you should be shown an invitation from Redis
Trying 127.0.1.1 ...
Connected to localhost.
Escape character is '^]'.
If you received it, then everything is fine, Redis works.
Testing server
Now we are talking with Redis on the socket.
Log in:
AUTH mypasswordSet the test value
SET testkey testvalue
KEYS * # Получаем все ключи
GET testkey # Сервер должен вернуть testvalue
QUIT
If everything went well, then the server is working, and we are done with it. We set the startup command at system startup and that’s it.
Redis + PHP5. Compiling a module for PHP
Here, too, everything is very simple, so you can just follow the commands.
$ cd ~
$ wget https://github.com/nicolasff/phpredis/zipball/2.1.3
$ unzip 2.1.3
$ cd nicolasff-phpredis-43bc590
Here I think comments are not needed.
Now we are collecting redis.so extension.
$ phpize
$ ./configure CFLAGS="-O3"
$ make clean all
Now the redis.so file has appeared in the modules folder, and we need it.
$ sudo cp modules/redis.so /usr/lib/php5/
$ cd ..
$ rm -rf nicolasff-phpredis-43bc590
Next, give php information about Redis.so
therefore
$ sudo vim /etc/php5/apache2/conf.d/redis.ini
and enter extension = redis.so in it.
Optionally, replace apache2 with cli, cgi, and so on, depending on how you have installed php and how you want to use it with Redis.
Now restart apache2 and write in the test php file:
$redis = new Redis();
$redis->connect('localhost:6379');
If the error that the Redis class does not exist does not crash, then everything is fine.
Let's benchmark the test directly in php.
try {
$redis = new Redis();
$redis->connect('localhost:6379');
} catch(RedisException $e) {
exit('Connect error');
}
$benchmark = microtime(true);
for($i=0;$i < 80000; $i++)
$redis->set('key','value');
echo microtime(true) - $benchmark;
I got information that 80,000 requests were processed in 2.6 seconds.
On this with php we are done. Next is phpRedisAdmin.
Install phpRedisAdmin
Installing phpRedisAdmin is absolutely unnecessary, but it doesn’t hurt to visualize the data.
Download from git admin panel itself.
$ cd /var/www
$ git clone git://github.com/ErikDubbelboer/phpRedisAdmin.git redisadmin
$ cd redisadmin
$ chmod 755 -R /var/www/redisadmin
We create the redisadmin folder in / var / www. We add the rights to the files, because initially I have permission denied on redisadmin.
Do not forget to configure the web server so that the site can be opened from the network.
But using redis admin is not safe on production, so you need to close it with a password for all prying eyes.
$ vim config.inc.php
It is necessary to uncomment line 11 and set the password for the server.
Next, you need to uncomment the block from line 36 to line 46 by assigning an admin password that will be requested when entering phpRedisAdmin
PROFIT!
In 15 minutes we were able to raise the Redis server, configure it to work with PHP and raise phpRedisAdmin.