簡體   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