提问者:小点点

如何在亚马逊AWS弹性豆茎上安装PHP扩展?


我们在EC2实例上的PHP应用程序中使用了aws弹性豆茎。由于我们选择了负载平衡,它会一次又一次地更改实例。

我想知道,如果我们安装一个PHP插件,它会受到实例更改的影响,或者它也会在新实例中可用?

问这个问题是因为我们观察到每次实例被弹性豆茎更改时,我们的应用程序都会被重新部署。

我们需要安装Geoip插件。如何安装它而不影响实例更改?


共3个答案

匿名用户

如果保留env设置,则在执行应用程序时将始终具有相同的EC2设置。

我更喜欢使用代码进行这种自定义(您也可以使用AWS控制台进行此操作)。因此,在您的源代码根目录中创建一个文件,路径如下:. ebexsionsions/php-模块.config,其中包含这些内容(ps:我在生产中使用此文件没有问题):

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

这是用于安装php-redis,但您也可以使用相同的方法来安装Geoip。

更多信息:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP.container.html#php-configuration-namespace

示例来源:http://qpleple.com/install-phpredis-on-amazon-beanstalk/

匿名用户

YAML

packages:
    yum:
        php70-pecl-redis.x86_64: []

匿名用户

我们使用Geoip for php7的工作配置:

. eb扩展/php-模块。配置

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