繁体   English   中英

如何安装Amazon AWS Elastic Beanstalk的PHP扩展?

[英]How to install a PHP extension witn Amazon AWS Elastic Beanstalk?

我们在EC2实例上使用aws弹性beanstalk作为我们的PHP应用程序。 由于我们选择了负载平衡,因此它会不断更改实例。

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

提出这个问题是因为我们观察到每次实例都是由弹性beanstalk改变的,我们的应用程序被重新部署。

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

如果保存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/

YAML

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

我们使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM