2016-08-02 92 views
2

我們在EC2實例上爲我們的PHP應用程序使用aws elastic beanstalk。由於我們選擇了負載均衡,因此它不斷更改實例。如何使用Amazon AWS Elastic Beanstalk安裝PHP擴展?

我想知道如果我們安裝一個PHP插件,是否會受到實例更改的影響,或者它也可以在新實例中使用?

問這個問題是因爲我們觀察到每個實例都被彈性beanstalk改變了,我們的應用程序被重新部署了。

我們需要安裝Geoip插件。如何在不影響實例更改的情況下安裝它?

+0

您是否在使用自定義AMI? –

+0

不,我們選擇了部署應用程序時包含在免費套餐中的所有默認設置。 – user2053100

回答

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/

0

我們與geoip的工作配置爲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 
1

YAML

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