6

We are using aws elastic beanstalk for our PHP application on EC2 instance. Since we opted for load balancing, it keeps changing the instance time and again.

I am wondering if we install a PHP plugin, will it be affected by change of instance or it will be available in new instance as well?

Asking this question because we have observed everytime instance is changed by elastic beanstalk, our application is redeployed.

We need to install Geoip plugin. How to install it without affecting it on instance change ?

user2053100
  • 73
  • 1
  • 1
  • 3

3 Answers3

7

If you keep the env settings saved, you will always have the same EC2 settings when executing your app.

I prefer to do this kind of customizing using code (you can do this using the AWS Console too). So, create a file in your source root, with the following path: .ebextensions/php-modules.config with these contents (ps: I'm using this in production with no problem):

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 phpredis-phpredis-* \
            && phpize \
            && ./configure \
            && make \
            && make install \
            && echo extension=redis.so > /etc/php.d/redis.ini

This is for install php-redis, but you can use the same approach to geoip as well.

For more information: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP.container.html#php-configuration-namespace

Source of the example: http://qpleple.com/install-phpredis-on-amazon-beanstalk/

Tulio Faria
  • 874
  • 7
  • 16
  • updated link to AWS resources regarding this customization : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-commands – Nir May 08 '20 at 23:44
  • Phpredis link does not work anymore, gives 404 error https://codeload.github.com/phpredis/phpredis/legacy.zip/master – Ankit Sharma Oct 24 '20 at 04:17
  • I have the issue that a different version of redis gets installed by another process before deployment file named /etc/php.d/50-redis.ini instead of /etc/php.d/redis.ini and this causes a break. – Urasquirrel Jul 28 '21 at 13:47
  • @Urasquirrel this is not a problem with the answer. – Tulio Faria Jul 28 '21 at 18:44
6

YAML

packages:
    yum:
        php70-pecl-redis.x86_64: []
user857276
  • 1,407
  • 1
  • 14
  • 19
0

Our working configuration with geoip for php7:

.ebextensions/php-modules.config

commands:
    01_geoip_install:
        # run this command from /tmp directory
        cwd: /tmp
        # don't run the command if php-geoip is already installed
        test: '[ ! -f /usr/lib64/php/7.0/modules/geoip.so ] && echo "geoip is not installed"'
        # executed only if test command succeeds
        command: |
          yum install -y geoip geoip-devel \
          && cd /tmp \
          && wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz \
          && gunzip ./GeoIP.dat.gz \
          && rm /usr/share/GeoIP/GeoIP.dat \
          && mv ./GeoIP.dat /usr/share/GeoIP/GeoIP.dat \
          && pecl7 install geoip-1.1.1 \
          && service httpd restart
WayFarer
  • 1,040
  • 11
  • 19