我们在EC2实例上使用aws弹性beanstalk作为我们的PHP应用程序。由于我们选择了负载均衡,因此它会不断更改实例时间。
我想知道我们是否安装了一个PHP插件,是否会受到实例更改的影响,或者它也可以在新实例中使用?
提出这个问题是因为我们观察到每次弹性beanstalk都改变了实例,我们的应用程序被重新部署。
我们需要安装 Geoip 插件。如何在不影响实例更改的情况下安装它?
答案 0 :(得分:5)
如果您保存环视设置,则在执行应用时,您将始终拥有相同的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://qpleple.com/install-phpredis-on-amazon-beanstalk/
答案 1 :(得分:3)
YAML
packages:
yum:
php70-pecl-redis.x86_64: []
答案 2 :(得分:0)
我们使用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