【问题标题】:How to install a PHP extension witn Amazon AWS Elastic Beanstalk?如何使用 Amazon AWS Elastic Beanstalk 安装 PHP 扩展?
【发布时间】:2016-12-08 09:37:51
【问题描述】:

我们在 EC2 实例上的 PHP 应用程序中使用 aws elastic beanstalk。由于我们选择了负载均衡,它会不断地改变实例。

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

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

我们需要安装Geoip插件。如何在不影响实例更改的情况下安装它?

【问题讨论】:

  • 您是否使用自定义 AMI?
  • 不,我们在部署应用程序时选择了免费套餐中包含的所有默认设置。

标签: php amazon-web-services amazon-ec2 amazon-elastic-beanstalk geoip


【解决方案1】:

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

我更喜欢使用代码进行这种自定义(您也可以使用 AWS 控制台进行此操作)。因此,在源根目录中创建一个文件,路径如下: .ebextensions/php-modules.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/

【讨论】:

【解决方案2】:

YAML

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

【讨论】:

  • 这种方式也可以在没有确切版本号的情况下工作php-pecl-redis: []
【解决方案3】:

我们为 php7 使用 geoip 的工作配置:

.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

【讨论】:

    猜你喜欢
    • 2014-07-15
    • 2017-12-08
    • 2014-03-14
    • 2017-01-12
    • 2018-07-01
    • 1970-01-01
    • 2015-06-11
    • 2012-01-10
    • 2014-09-15
    相关资源
    最近更新 更多