Installing Redis + Redis PHP + phpRedisAdmin on alert server in 15 minutes

Installing Redis + Redis PHP + phpRedisAdmin on alert server in 15 minutes


Everyone has long known that the best binary - those that have been compiled on this computer. And when the question comes to performance, the compilation of the components on this machine will give its advantage in speed and stability.

This article will discuss how to prepare Redis, phpredis (C module for php) and phpRedisAdmin to work on operational server.

In order to collect all full, we need to have on the server:
  • gcc 4.5.2 (I compiled for this version, but I think other problems will not arise)
  • Make 3.81 (Again, the version is not critical)
  • php5-dev (version must match the version of php)


Once we see that all dependencies are satisfied, we begin to gather all the ingredients.
We need:
  • Redis 2.4.4 Stable
  • phpredis 2.1.3
  • phpRedisAdmin


Putting Redis


In order to raise Radishes, we need the source code itself. You can get them to github. So
https://github.com/antirez/redis/zipball/2.4.4 load once the tag.

$ wget https://github.com/antirez/redis/zipball/2.4.4 $ unzip 2.4.4 $ cd antirez-redis-04bba69


Now we have all the source code Redis 2.4.4, it remains to compile them.
It's very simple
$ make $ make test


The first team we have assembled Redis, his second check on the performance.
Make test will take a long time (about 2 minutes). After the test should return a string "\ o / All tests passed without errors!"

Redis is collected, the garbage is left clean and carry radishes in the correct directory.
Redis blown the whole compiled in a folder / usr / bin / redis. A so run Redis-server, in / usr / bin create a shell file redis-server.

We take a Redis files in / usr / bin / redis


We still remain in the folder antirez-redis-04bba69, where lie the sources
$ 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 have copied all the files from the Redis and removed the folder with the source, she will no longer be needed.
Be careful with the last command! sudo to not need it, the folder, and so in our possession.

Now we need to create a file to start the redis-server.

$ sudo vim /usr/bin/redis-server


Instead of vim can use any other editor. It does not matter.
In the file paste:
cd / usr / bin / redis &&. / redis-server redis.conf
Save and close.

To do this, the file must be given the right to performance.
$ 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 loaded, it remains to configure it.
Replace the configuration file

daemonize no to daemonize yes # Let works like a demon
0 on timeout timeout 30 # If a client bug, which is not disconnected, hang forever in the memory of Redis
loglevel notice on the loglevel warning # We have a military server, at least debug messages
Need to uncomment line 166 and set a password for example requirepass foobared
350 comment a line, it is not necessary.

Save and close.

Run!


If everything was done correctly, you run the server
$ redis-server $ telnet localhost 6379


The idea is to show you the invitation from the Redis
Trying 127.0.1.1 ...
Connected to localhost.
Escape character is '^]'.

If you got it, then everything is fine, Redis works.

Testing the server


Now we are dealing with Redis on the socket.
Avtoriziruemsya:
AUTH mypassword


Set the test value
SET testkey testvalue KEYS * # Получаем все ключи GET testkey # Сервер должен вернуть testvalue QUIT


If all goes well, then the server is running, and we end up with him. Set a command to autoload at startup and all.

Redis + PHP5. Compile the module for PHP


Here, too, is very simple, so you can simply follow the commands.
$ cd ~ $ wget https://github.com/nicolasff/phpredis/zipball/2.1.3 $ unzip 2.1.3 $ cd nicolasff-phpredis-43bc590

Then I think comments are not needed.

Now collect redis.so extension.
$ phpize $ ./configure CFLAGS="-O3" $ make clean all

Now, in a file folder modules appeared redis.so, it is something we need and.

$ sudo cp modules/redis.so /usr/lib/php5/<date> $ cd .. $ rm -rf nicolasff-phpredis-43bc590

<date> change the name of the folder that looks something like this: 20090626.

Further, to provide information about the php Redis.so
so
$ sudo vim /etc/php5/apache2/conf.d/redis.ini

and enter it in the extension = redis.so
Upon request to replace apache2 cli, cgi and so on, depending on how you use php, and how you want to use with Redis.

Now restarting apache2 and php file in a test write:
$redis = new Redis(); $redis->connect('localhost:6379');

If the error is that the class of Redis does not exist, has taken off, then everything is fine.

Carry out the benchmark 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 have appeared that 80,000 requests were processed in 2.6 seconds.

On this we ended up with php. Next phpRedisAdmin.

Installing phpRedisAdmin



Installing phpRedisAdmin absolutely necessary, but to visualize the data can not hurt.

Downloading from git itself admin.
$ cd /var/www $ git clone git://github.com/ErikDubbelboer/phpRedisAdmin.git redisadmin $ cd redisadmin $ chmod 755 -R /var/www/redisadmin


We create a folder redisadmin in / var / www. Add rights to the files, because initially I had permission denied on redisadmin.

Do not forget to configure your Web server, so the site can be opened from the network already.
But the use of redis admin is not safe to prodakshene, so it must be as close or as to all prying eyes with a password.

$ vim config.inc.php

Need to uncomment line 11 and set a password to the server.

Next you need to uncomment a block from 36 to 46 bar, appointing Admin password will be requested at the entrance to phpRedisAdmin

PROFIT!
For 15 minutes we were able to raise Redis server, configure it to work with PHP and raise phpRedisAdmin.