Closed sxmxc24 closed 5 years ago
Edited web.yaml and mastervpc.yaml parameters
Hi,
How have you been able to do that? I'm trying to do the same, but the installation fails every time as the autoscalinggroups receive FAILURE signal.
I've added the following part to the 04-web.yaml after the WebLaunchConfiguration70, and added the necessary parameters (and condition) to activate that. It's almost the same as WebLaunchConfiguration72, I've changed the 7.0->7.2 at the commands and added the link to ElastiCacheClient7.2:
WebLaunchConfiguration72:
Condition: PHP72
Type: AWS::AutoScaling::LaunchConfiguration
Metadata:
AWS::CloudFormation::Init:
configSets:
deploy_webserver:
- install_webserver
- build_cacheclient
- build_wordpress
- build_opcache
- download_aws_ini
- install_aws_ini
- install_cacheclient
- install_wordpress
- install_opcache
- start_webserver
install_webserver:
packages:
yum:
awslogs: []
httpd24: []
mysql56: []
php72: []
php72-mysqlnd: []
files:
/tmp/create_site_conf.sh:
content:
!Join [
"",[
"#!/bin/bash -xe\n",
"if [ ! -f /etc/httpd/conf.d/", !Ref WPDirectory, ".conf ]; then\n",
" touch /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
" echo 'ServerName 127.0.0.1:80' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
" echo 'DocumentRoot /var/www/wordpress/", !Ref WPDirectory, "' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
" echo '<Directory /var/www/wordpress/", !Ref WPDirectory, ">' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
" echo ' Options Indexes FollowSymLinks' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
" echo ' AllowOverride All' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
" echo ' Require all granted' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
" echo '</Directory>' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
"fi\n"
]
]
mode: 000500
owner: root
group: root
commands:
create_site_conf:
command: ./create_site_conf.sh
cwd: /tmp
ignoreErrors: false
build_cacheclient:
packages:
yum:
gcc-c++: []
files:
/tmp/install_cacheclient.sh:
content:
!Sub |
#!/bin/bash -xe
wget -P /tmp/ https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/files/1993851/AmazonElasticacheClusterClient-PHP72-64bit-libmemcached-1.0.8.tar.gz
tar -xf /tmp/AmazonElasticacheClusterClient-PHP72-64bit-libmemcached-1.0.8.tar.gz
cp '/tmp/amazon-elasticache-cluster-client.so' /usr/lib64/php/7.2/modules/
if [ ! -f /etc/php-7.2.d/50-memcached.ini ]; then
touch /etc/php-7.2.d/50-memcached.ini
fi
sed -i '3i extension=/usr/lib64/php/7.2/modules/amazon-elasticache-cluster-client.so;' /etc/php-7.2.d/50-memcached.ini
sed -i '3i extension=igbinary.so;' /etc/php-7.2.d/50-memcached.ini
mode: 000500
owner: root
group: root
build_opcache:
packages:
yum:
php72-opcache: []
files:
/tmp/install_opcache.sh:
content:
!Sub |
#!/bin/bash -xe
# create hidden opcache directory locally & change owner to apache
if [ ! -d /var/www/.opcache ]; then
mkdir -p /var/www/.opcache
fi
# enable opcache in /etc/php-7.0.d/10-opcache.ini
sed -i 's/;opcache.file_cache=.*/opcache.file_cache=\/var\/www\/.opcache/' /etc/php-7.2.d/10-opcache.ini
sed -i 's/opcache.memory_consumption=.*/opcache.memory_consumption=512/' /etc/php-7.2.d/10-opcache.ini
download opcache-instance.php to verify opcache status
if [ ! -f /var/www/wordpress/${WPDirectory}/opcache-instanceid.php ]; then
wget -P /var/www/wordpress/${WPDirectory}/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/opcache-instanceid.php
fi
mode: 000500
owner: root
group: root
build_wordpress:
files:
/tmp/install_wordpress.sh:
content:
!Join [
"",[
"#!/bin/bash -xe\n",
"\n",
"# install wp-cli\n",
"if [ ! -f /bin/wp/wp-cli.phar ]; then\n",
" curl -o /bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar\n",
" chmod +x /bin/wp\n",
"fi\n",
"\n",
"# make site directory\n",
"if [ ! -d /var/www/wordpress/", !Ref WPDirectory, " ]; then\n",
" mkdir -p /var/www/wordpress/", !Ref WPDirectory, "\n",
"\n",
" cd /var/www/wordpress/", !Ref WPDirectory, "\n",
" # install wordpress if not installed\n",
" # use public alb host name if wp domain name was empty\n",
" if ! $(wp core is-installed --allow-root); then\n",
" wp core download --version='", !Ref WPVersion, "' --locale='", !Ref WPLocale, "' --allow-root\n",
" wp core config --dbname='", !Ref DatabaseName, "' --dbuser='", !Ref DatabaseMasterUsername, "' --dbpass='", !Ref DatabaseMasterPassword, "' --dbhost='", !Ref DatabaseClusterEndpointAddress, "' --dbprefix=wp_ --allow-root\n",
" wp core install --url=", !If [ NoWPDomainName, !Ref PublicAlbHostname, !Join [ "", [ "'http://www.", !Ref WPDomainName, "'" ] ] ], " --title='", !Ref WPTitle, "' --admin_user='", !Ref WPAdminUsername, "' --admin_password='", !Ref WPAdminPassword, "' --admin_email='", !Ref WPAdminEmail, "' --skip-email --allow-root\n",
" sed -i \"/$table_prefix = 'wp_';/ a \\define('WP_HOME', 'http://' . \\$_SERVER['HTTP_HOST']); \" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n",
" sed -i \"/$table_prefix = 'wp_';/ a \\define('WP_SITEURL', 'http://' . \\$_SERVER['HTTP_HOST']); \" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n",
" # enable HTTPS in wp-config.php if ACM Public SSL Certificate parameter was not empty\n",
!If [ NoSslCertificate, !Join [ '', [ " sed -i \"/$table_prefix = 'wp_';/ a \\# No ACM Public SSL Certificate \" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n" ] ] , !Join [ '', [ " sed -i \"/$table_prefix = 'wp_';/ a \\$_SERVER['HTTPS'] = 'on';\" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n" ] ] ],
"\n",
" # set permissions of wordpress site directories\n",
" chown -R apache:apache /var/www/wordpress/", !Ref WPDirectory, "\n",
" chmod u+wrx /var/www/wordpress/", !Ref WPDirectory, "/wp-content/*\n",
" if [ ! -f /var/www/wordpress/", !Ref WPDirectory, "/opcache-instanceid.php ]; then\n",
" wget -P /var/www/wordpress/", !Ref WPDirectory, "/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/opcache-instanceid.php\n",
" fi\n",
" fi\n",
" RESULT=$?\n",
" if [ $RESULT -eq 0 ]; then\n",
" touch /var/www/wordpress/", !Ref WPDirectory, "/wordpress.initialized\n",
" else\n",
" touch /var/www/wordpress/", !Ref WPDirectory, "/wordpress.failed\n",
" fi\n",
"fi\n"
]
]
mode: 000500
owner: root
group: root
download_aws_ini:
files:
/tmp/download_aws_ini.sh:
content:
!Join [
"",[
"#!/bin/bash -x\n",
"\n",
"wget -P /etc/php-7.2.d/ ", !Ref PHPIniOverride, "\n"
]
]
mode: 000500
owner: root
group: root
install_aws_ini:
commands:
install_aws_ini:
command: ./download_aws_ini.sh
cwd: /tmp
ignoreErrors: true
install_wordpress:
commands:
install_wordpress:
command: ./install_wordpress.sh
cwd: /tmp
ignoreErrors: false
install_cacheclient:
commands:
install_cacheclient:
command: ./install_cacheclient.sh
cwd: /tmp
ignoreErrors: false
install_opcache:
commands:
install_opcache:
command: ./install_opcache.sh
cwd: /tmp
ignoreErrors: false
start_webserver:
services:
sysvinit:
httpd:
enabled: true
ensureRunning: true
Properties:
IamInstanceProfile: !Ref WebInstanceProfile
ImageId: !FindInMap [ RegionMap, !Ref 'AWS::Region', AMI ]
InstanceMonitoring: true
InstanceType: !Ref WebInstanceType
KeyName: !Ref EC2KeyName
SecurityGroups:
- !Ref WebSecurityGroup
UserData:
"Fn::Base64":
!Sub |
#!/bin/bash -xe
yum update -y
mkdir -p /var/www/wordpress
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 ${ElasticFileSystem}.efs.${AWS::Region}.amazonaws.com:/ /var/www/wordpress
/opt/aws/bin/cfn-init --configsets deploy_webserver --verbose --stack ${AWS::StackName} --resource WebLaunchConfiguration72 --region ${AWS::Region}
/opt/aws/bin/cfn-signal --exit-code $? --stack ${AWS::StackName} --resource WebAutoScalingGroup --region ${AWS::Region}
@Nipazz did you edit the PHPVersion in the parameters section of the master-newvpc.yaml template?
Also within the master-vpc.yaml template you have to make sure the TemplateURL for the web.yaml template is pointing to your S3 bucket because it will fail if its pointed to the AWS bucket due to their template not containing PHPversion 7.2.
Yeah, I've edited the Master to point to the correct template and I've also added the parameter to both templates. I think I've missed something, so if you could share your working templates that would be great :)
I was missing an apostrophe. I've updated my previous message, so if anyone want to install the website with PHP7.2 you can use that as a reference.
In the future, "ignoreErrors: true" helps a lot at debugging!
Currently unable to create a stack with PHP 7.2 installed and the default version.
I have to manually upgrade to 7.2 after stack creation is complete.