我们在EC2实例上的PHP应用程序中使用aws弹性豆茎。由于我们选择了负载平衡,它不断地更改实例。
我想知道如果我们安装一个PHP插件,它会受到实例更改的影响吗?或者它也会在新实例中可用?
问这个问题是因为我们已经观察到,每次实例被弹性豆茎更改时,我们的应用程序都会被重新部署。
我们需要安装Geoip插件。如何在不影响实例更改的情况下安装它?
如果保存env设置,则在执行应用程序时将始终具有相同的EC2设置。
我更喜欢使用代码进行这种自定义(您也可以使用AWS控制台进行自定义)。因此,在源根目录中创建一个文件,路径如下:.eextensions/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,但您也可以使用相同的方法来处理geoap。
有关详细信息:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP.container.html#php-配置命名空间
示例来源:http://qpleple.com/install-phpredis-on-amazon-beanstalk/
YAML
packages:
yum:
php70-pecl-redis.x86_64: []
php7:使用geoap的工作配置
.eextensions/php模块.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