Install Phpredis On Elastic Beanstalk

Install

Phpredis is not available as a package on Amazon Linux so we have to run a command to install it.

# these commands run before the application and web server are
# set up and the application version file is extracted.
commands:
    01_redis_install:
        # run this command from /tmp directory
        cwd: /tmp
        # don't run the command if phpredis is already installed (file /etc/php.d/redis.ini exists)
        test: '[ ! -f /etc/php.d/redis.ini ] && echo "redis not installed"'
        # executed only if test command succeeds
        command: |
            wget https://github.com/nicolasff/phpredis/zipball/master -O phpredis.zip \
            && unzip -o phpredis.zip \
            && cd nicolasff-phpredis-* \
            && phpize \
            && ./configure \
            && make \
            && make install \
            && echo extension=redis.so > /etc/php.d/redis.ini

See Amazon's documentation for more info.

Troubleshooting

Logs of the execution of .ebextension/*.config files are found in /var/log/cfn-init.log.

You should see something like

[DEBUG] Running command 01_redis_install
[DEBUG] Running test for command 01_redis_install
[DEBUG] Test command output: redis not installed
[DEBUG] Test for command 01_redis_install passed
[INFO] Command 01_redis_install succeeded
[DEBUG] Command 01_redis_install output: --2014-05-16 14:33:03--  https://github.com/nicolasff/phpredis/zipball/master
Resolving github.com (github.com)... 192.30.252.130
Connecting to github.com (github.com)|192.30.252.130|:443... connected.
...
Quentin Pleplé
May 2014