Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save matyo91/6449284 to your computer and use it in GitHub Desktop.

Select an option

Save matyo91/6449284 to your computer and use it in GitHub Desktop.

Revisions

  1. matyo91 created this gist Sep 5, 2013.
    92 changes: 92 additions & 0 deletions Symfony - Installer Redis pour Symfony2 sur Ubuntu
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    Redis (de l'anglais REmote DIctionary Server qui peut-être traduit par « serveur de dictionnaire distant » et jeu de mot avec Redistribute) est un système de gestion de base de données clef-valeur scalable, très hautes performances, écrit avec le langage de programmation C ANSI et distribué sous licence BSD. Il fait partie de la mouvance NoSQL et vise à fournir les performances les plus élevées possibles.

    Ici, nous allons voir comment installer le serveur sur Ubuntu, et l'utiliser sur Symfony2

    # Installer Redis Serveur

    Les dernières sources à jour de Redis sont téléchargeable [ici](http://redis.io/download).

    $ cd /tmp
    $ wget http://redis.googlecode.com/files/redis-x.x.x.tar.gz
    $ tar -zxf redis-x.x.x.tar.gz
    $ cd redis-x.x.x
    $ make
    $ sudo make install

    Les binaires Redis doivent maintenant être installées dans /usr/local/bin.

    On installe une configuration par défaut crée par [ijonas](https://github.com/ijonas/dotfiles/)

    $ cd /tmp
    $ wget https://github.com/ijonas/dotfiles/raw/master/etc/init.d/redis-server
    $ wget https://github.com/ijonas/dotfiles/raw/master/etc/redis.conf
    $ sudo mv redis-server /etc/init.d/redis-server
    $ sudo chmod +x /etc/init.d/redis-server
    $ sudo mv redis.conf /etc/redis.conf

    Avant de démarrer le serveur Redis pour la première fois, on ajoute un utilisateur redis.

    $ cd /tmp
    $ sudo mkdir -p /var/lib/redis
    $ sudo mkdir -p /var/log/redis
    $ sudo useradd --system --home-dir /var/lib/redis redis
    $ sudo chown redis.redis /var/lib/redis
    $ sudo chown redis.redis /var/log/redis

    Il faut activer les services de Redis qui vont démarrer automatiquement lors du boot et s'arêterons proprement lors du shutdown.

    $ sudo update-rc.d redis-server defaults

    Maintenant on démarre le serveur Redis

    $ sudo /etc/init.d/redis-server start

    # Installer PHP-Redis

    $ sudo pear channel-discover drewish.github.com/phpredis
    $ sudo pecl install drewishPhpRedis/PhpRedis

    Il faut ensuite éditer le fichier php.ini pour charger les extensions ajoutées par pecl. Puis redémarer apache

    $ sudo service apache2 restart

    # Installer PHPRedisAdmin

    Installer l'interface admin redis via http

    $ cd /var/www/tools/
    $ git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
    $ cd phpRedisAdmin/
    $ git submodule init
    $ git submodule update

    # configure v-host
    $ cd /etc/apache2/sites-available/
    $ sudo nano tools.phpredisadmin.dev
    <virtualhost *:80>
    DocumentRoot /var/www/tools/phpRedisAdmin
    ServerAlias phpredisadmin.tools.dev
    <directory /var/www/tools/phpRedisAdmin>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </directory>

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel error

    ErrorLog ${APACHE_LOG_DIR}/tools.phpredisadmin.dev.error.log
    CustomLog ${APACHE_LOG_DIR}/tools.phpredisadmin.dev.access.log combined
    </virtualhost>

    # add v-host
    $ sudo a2ensite tools.phpredisadmin.dev

    # restart apache
    $ sudo service apache2 reload

    # Utiliser Redis pour Symfony2

    Maintenant, nous avons tous les prérequis pour utilser Redis en php. Pour le joindre facilement avec un projet sur Symfony, il faut se référer à l'installation du bundle [SncRedisBundle](https://github.com/snc/SncRedisBundle)