Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.33 KB | None | 0 0
  1. ---
  2. AWSTemplateFormatVersion: 2010-09-09
  3.  
  4. Description: Reference Architecture to host WordPress on AWS - Creates WordPress web Auto Scaling group
  5.  
  6. Metadata:
  7.  
  8. Authors:
  9. Description: Darryl Osborne (darrylo@amazon.com)
  10. License:
  11. Description: 'Copyright 2018 Amazon.com, Inc. and its affiliates. All Rights Reserved.
  12. Licensed under the Amazon Software License (the "License"). You may not use this file
  13. except in compliance with the License. A copy of the License is located at
  14. http://aws.amazon.com/asl/
  15. or in the "license" file accompanying this file. This file is distributed on an "AS IS"
  16. BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  17. License for the specific language governing permissions and limitations under the License.'
  18.  
  19. AWS::CloudFormation::Interface:
  20. ParameterGroups:
  21. - Label:
  22. default: Web Parameters
  23. Parameters:
  24. - PHPVersion
  25. - PHPIniOverride
  26. - EC2KeyName
  27. - WebInstanceType
  28. - WebAsgMax
  29. - WebAsgMin
  30. - WebSecurityGroup
  31. - NumberOfSubnets
  32. - Subnet
  33. - PublicAlbTargetGroupArn
  34. - PublicAlbHostname
  35. - SslCertificate
  36. - Label:
  37. default: WordPress Parameters
  38. Parameters:
  39. - WPVersion
  40. - WPTitle
  41. - WPDomainName
  42. - WPDirectory
  43. - WPAdminUsername
  44. - WPAdminPassword
  45. - WPAdminEmail
  46. - WPLocale
  47. - Label:
  48. default: Database Parameters
  49. Parameters:
  50. - DatabaseClusterEndpointAddress
  51. - DatabaseName
  52. - DatabaseMasterUsername
  53. - DatabaseMasterPassword
  54. - Label:
  55. default: File System Parameters
  56. Parameters:
  57. - ElasticFileSystem
  58. ParameterLabels:
  59. PHPIniOverride:
  60. default: AWS php.ini Overrides
  61. DatabaseClusterEndpointAddress:
  62. default: DB Cluster Endpoint Address
  63. DatabaseMasterUsername:
  64. default: DB Master Username
  65. DatabaseMasterPassword:
  66. default: DB Master Password
  67. DatabaseName:
  68. default: DB Name
  69. ElasticFileSystem:
  70. default: EFS File System
  71. EC2KeyName:
  72. default: Existing Key Pair
  73. NumberOfSubnets:
  74. default: Number of subnets
  75. PHPVersion:
  76. default: PHP Version
  77. PublicAlbTargetGroupArn:
  78. default: Public Alb Target Group Arn
  79. PublicAlbHostname:
  80. default: Public Alb Hostname
  81. SslCertificate:
  82. default: ACM Cert attached to Public Alb
  83. Subnet:
  84. default: Subnets
  85. WebAsgMax:
  86. default: Web ASG Max
  87. WebAsgMin:
  88. default: Web ASG Min
  89. WebInstanceType:
  90. default: Web Instance Type
  91. WebSecurityGroup:
  92. default: Web Security Group
  93. WPAdminEmail:
  94. default: Admin Email
  95. WPAdminPassword:
  96. default: Admin Password
  97. WPAdminUsername:
  98. default: Admin Username
  99. WPDirectory:
  100. default: Site Directory
  101. WPDomainName:
  102. default: Site Domain
  103. WPLocale:
  104. default: Language Code
  105. WPTitle:
  106. default: Site Title
  107. WPVersion:
  108. default: WordPress Version
  109.  
  110. Parameters:
  111.  
  112. DatabaseClusterEndpointAddress:
  113. Description: The RDS cluster endpoint address.
  114. Type: String
  115. DatabaseMasterUsername:
  116. AllowedPattern: ^([a-zA-Z0-9]*)$
  117. Description: The Amazon RDS master username.
  118. ConstraintDescription: Must contain only alphanumeric characters and be at least 8 characters.
  119. MaxLength: 16
  120. MinLength: 1
  121. Type: String
  122. DatabaseMasterPassword:
  123. AllowedPattern: ^([a-z0-9A-Z`~!#$%^&*()_+,\\-])*$
  124. ConstraintDescription: Must be letters (upper or lower), numbers, and these special characters '_'`~!#$%^&*()_+,-
  125. Description: The Amazon RDS master password.
  126. MaxLength: 41
  127. MinLength: 8
  128. NoEcho: true
  129. Type: String
  130. DatabaseName:
  131. AllowedPattern: ^([a-zA-Z0-9]*)$
  132. Description: The Amazon RDS master database name.
  133. Type: String
  134. ElasticFileSystem:
  135. AllowedPattern: ^(fs-)([a-z0-9]{8})$
  136. Description: The Amazon EFS file system id.
  137. Type: String
  138. EC2KeyName:
  139. AllowedPattern: ^([a-zA-Z0-9 @.`~!#$%^&*()_+,\\-])*$
  140. ConstraintDescription: Must be letters (upper or lower), numbers, and special characters.
  141. Description: Name of an EC2 KeyPair. Your bastion & Web instances will launch with this KeyPair.
  142. Type: AWS::EC2::KeyPair::KeyName
  143. NumberOfSubnets:
  144. AllowedValues:
  145. - 2
  146. - 3
  147. - 4
  148. - 5
  149. - 6
  150. Default: 3
  151. Description: Number of subnets. This must match your selections in the list of subnets below.
  152. Type: String
  153. PHPIniOverride:
  154. Description: Full Amazon S3 https path to a php.ini override file (e.g. https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/20-aws.ini)
  155. Type: String
  156. PHPVersion:
  157. AllowedValues:
  158. - 5.5
  159. - 5.6
  160. - 7.0
  161. Default: 7.0
  162. Description: The version of PHP to install.
  163. Type: String
  164. PublicAlbTargetGroupArn:
  165. Description: The public application load balancer target group arn.
  166. Type: String
  167. PublicAlbHostname:
  168. Description: The hostname of the public ALB http form (e.g. http://abdc-12345-xyz.<region>.elb.amazonaws.com)
  169. Type: String
  170. SslCertificate:
  171. AllowedValues:
  172. - True
  173. - False
  174. Default: False
  175. Description: Is there an ACM SSL Certificate attached to the Public Alb?
  176. Type:
  177. String
  178. Subnet:
  179. Description: Select existing subnets. The number selected must match the number of subnets above. Subnets selected must be in separate AZs.
  180. Type: List<AWS::EC2::Subnet::Id>
  181. WebAsgMax:
  182. AllowedPattern: ^((?!0$)[1-2]?[0-9]|30)$
  183. ConstraintDescription: Must be a number between 1 and 30.
  184. Default: 4
  185. Description: Specifies the maximum number of EC2 instances in the Web Autoscaling Group.
  186. Type: String
  187. WebAsgMin:
  188. AllowedPattern: ^([0-0]?[0-9]|10)$
  189. ConstraintDescription: Must be a number between 0 and 10.
  190. Default: 2
  191. Description: Specifies the minimum number of EC2 instances in the Web Autoscaling Group.
  192. Type: String
  193. WebInstanceType:
  194. AllowedValues:
  195. - t2.nano
  196. - t2.micro
  197. - t2.small
  198. - t2.medium
  199. - t2.large
  200. - t2.xlarge
  201. - t2.2xlarge
  202. - m3.medium
  203. - m3.large
  204. - m3.xlarge
  205. - m3.2xlarge
  206. - m4.large
  207. - m4.xlarge
  208. - m4.2xlarge
  209. - m4.4xlarge
  210. - m4.10xlarge
  211. - m4.16xlarge
  212. - m5.large
  213. - m5.xlarge
  214. - m5.2xlarge
  215. - m5.4xlarge
  216. - m5.12xlarge
  217. - m5.24xlarge
  218. - c3.large
  219. - c3.xlarge
  220. - c3.2xlarge
  221. - c3.4xlarge
  222. - c3.8xlarge
  223. - c4.large
  224. - c4.xlarge
  225. - c4.2xlarge
  226. - c4.4xlarge
  227. - c4.8xlarge
  228. - c5.large
  229. - c5.xlarge
  230. - c5.2xlarge
  231. - c5.4xlarge
  232. - c5.9xlarge
  233. - c5.18xlarge
  234. - r3.large
  235. - r3.xlarge
  236. - r3.2xlarge
  237. - r3.4xlarge
  238. - r3.8xlarge
  239. - r4.large
  240. - r4.xlarge
  241. - r4.2xlarge
  242. - r4.4xlarge
  243. - r4.8xlarge
  244. - r4.16xlarge
  245. - x1.16xlarge
  246. - x1.32xlarge
  247. - x1e.xlarge
  248. - x1e.2xlarge
  249. - x1e.4xlarge
  250. - x1e.8xlarge
  251. - x1e.16xlarge
  252. - x1e.32xlarge
  253. - d2.xlarge
  254. - d2.2xlarge
  255. - d2.4xlarge
  256. - d2.8xlarge
  257. - h1.2xlarge
  258. - h1.4xlarge
  259. - h1.8xlarge
  260. - h1.16xlarge
  261. - i2.xlarge
  262. - i2.2xlarge
  263. - i2.4xlarge
  264. - i2.8xlarge
  265. - i3.large
  266. - i3.xlarge
  267. - i3.2xlarge
  268. - i3.4xlarge
  269. - i3.8xlarge
  270. - i3.16xlarge
  271. - f1.2xlarge
  272. - f1.16xlarge
  273. - g2.2xlarge
  274. - g2.8xlarge
  275. - g3.4xlarge
  276. - g3.8xlarge
  277. - g3.16xlarge
  278. - p2.xlarge
  279. - p2.8xlarge
  280. - p2.16xlarge
  281. - p3.2xlarge
  282. - p3.8xlarge
  283. - p3.16xlarge
  284. ConstraintDescription: Must be a valid Amazon EC2 instance type.
  285. Default: t2.large
  286. Description: The Amazon EC2 instance type for your web instances.
  287. Type: String
  288. WebSecurityGroup:
  289. Description: Select the web security group.
  290. Type: AWS::EC2::SecurityGroup::Id
  291. WPAdminEmail:
  292. AllowedPattern: ^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  293. Description: The WordPress admin email address.
  294. Type: String
  295. WPAdminPassword:
  296. AllowedPattern: ^([a-zA-Z0-9`~!#$%^&*()_+,\\-])*$
  297. ConstraintDescription: Must be letters (upper or lower), numbers, and these special characters '_'`~!#$%^&*()_+,-
  298. Description: The WordPress admin password.
  299. Type: String
  300. NoEcho: true
  301. WPAdminUsername:
  302. AllowedPattern: ^([a-zA-Z0-9])([a-zA-Z0-9_-])*([a-zA-Z0-9])$
  303. Description: The WordPress admin username.
  304. Type: String
  305. WPDirectory:
  306. AllowedPattern: ^([a-zA-Z0-9])([a-zA-Z0-9_-])*([a-zA-Z0-9])$
  307. Description: The WordPress site directory.
  308. Type: String
  309. WPDomainName:
  310. AllowedPattern: ^$|(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$
  311. Description: '[ Optional ] The main domain name of the WordPress site (e.g. example.com). Leave empty to use the ALB DNS name for the WordPress site.'
  312. Type: String
  313. WPLocale:
  314. Description: The main language of the WordPress site, as per https://codex.WordPress.org/Installing_WordPress_in_Your_Language. The default is 'en_GB'.
  315. Type: String
  316. Default: en_GB
  317. WPTitle:
  318. AllowedPattern: ^([a-zA-Z0-9])([a-zA-Z0-9 _-]*)([a-zA-Z0-9])$
  319. Description: The WordPress website title.
  320. Type: String
  321. WPVersion:
  322. AllowedValues:
  323. - latest
  324. - nightly
  325. - 4.5
  326. - 4.6
  327. - 4.7
  328. - 4.8
  329. - 4.9
  330. Default: latest
  331. Description: The WordPress version (make sure this version is compatible with the PHP version selected above).
  332. Type: String
  333.  
  334. Conditions:
  335.  
  336. NoSslCertificate:
  337. !Equals [ False, !Ref SslCertificate ]
  338. NumberOfSubnets1:
  339. !Equals [ 1, !Ref NumberOfSubnets ]
  340. NumberOfSubnets2:
  341. !Equals [ 2, !Ref NumberOfSubnets ]
  342. NumberOfSubnets3:
  343. !Equals [ 3, !Ref NumberOfSubnets ]
  344. NumberOfSubnets4:
  345. !Equals [ 4, !Ref NumberOfSubnets ]
  346. NumberOfSubnets5:
  347. !Equals [ 5, !Ref NumberOfSubnets ]
  348. NumberOfSubnets6:
  349. !Equals [ 6, !Ref NumberOfSubnets ]
  350. PHP55:
  351. !Equals [ 5.5, !Ref PHPVersion ]
  352. PHP56:
  353. !Equals [ 5.6, !Ref PHPVersion ]
  354. PHP70:
  355. !Equals [ 7.0, !Ref PHPVersion ]
  356. Subnet0: !Or
  357. - !Condition NumberOfSubnets1
  358. - !Condition NumberOfSubnets2
  359. - !Condition NumberOfSubnets3
  360. - !Condition NumberOfSubnets4
  361. - !Condition NumberOfSubnets5
  362. - !Condition NumberOfSubnets6
  363. Subnet1: !Or
  364. - !Condition NumberOfSubnets2
  365. - !Condition NumberOfSubnets3
  366. - !Condition NumberOfSubnets4
  367. - !Condition NumberOfSubnets5
  368. - !Condition NumberOfSubnets6
  369. Subnet2: !Or
  370. - !Condition NumberOfSubnets3
  371. - !Condition NumberOfSubnets4
  372. - !Condition NumberOfSubnets5
  373. - !Condition NumberOfSubnets6
  374. Subnet3: !Or
  375. - !Condition NumberOfSubnets4
  376. - !Condition NumberOfSubnets5
  377. - !Condition NumberOfSubnets6
  378. Subnet4: !Or
  379. - !Condition NumberOfSubnets5
  380. - !Condition NumberOfSubnets6
  381. Subnet5: !Condition NumberOfSubnets6
  382. NoWPDomainName:
  383. !Equals [ '', !Ref WPDomainName ]
  384.  
  385. Mappings:
  386.  
  387. RegionMap:
  388. ap-northeast-1:
  389. AMI: ami-da9e2cbc
  390. ap-northeast-2:
  391. AMI: ami-1196317f
  392. ap-south-1:
  393. AMI: ami-d5c18eba
  394. ap-southeast-1:
  395. AMI: ami-c63d6aa5
  396. ap-southeast-2:
  397. AMI: ami-ff4ea59d
  398. ca-central-1:
  399. AMI: ami-d29e25b6
  400. eu-central-1:
  401. AMI: ami-bf2ba8d0
  402. eu-west-1:
  403. AMI: ami-1a962263
  404. eu-west-2:
  405. AMI: ami-e7d6c983
  406. sa-east-1:
  407. AMI: ami-286f2a44
  408. us-east-1:
  409. AMI: ami-55ef662f
  410. us-east-2:
  411. AMI: ami-15e9c770
  412. us-west-1:
  413. AMI: ami-a51f27c5
  414. us-west-2:
  415. AMI: ami-bf4193c7
  416.  
  417. Resources:
  418.  
  419. WebInstanceProfile:
  420. Type: AWS::IAM::InstanceProfile
  421. Properties:
  422. Path: /
  423. Roles:
  424. - !Ref WebInstanceRole
  425. WebInstanceRole:
  426. Type: AWS::IAM::Role
  427. Properties:
  428. AssumeRolePolicyDocument:
  429. Version: 2012-10-17
  430. Statement:
  431. - Effect: Allow
  432. Principal:
  433. Service:
  434. - ec2.amazonaws.com
  435. Action:
  436. - sts:AssumeRole
  437. Path: /
  438. Policies:
  439. - PolicyName: logs
  440. PolicyDocument:
  441. Version: 2012-10-17
  442. Statement:
  443. - Effect: Allow
  444. Action:
  445. - logs:CreateLogGroup
  446. - logs:CreateLogStream
  447. - logs:PutLogEvents
  448. - logs:DescribeLogStreams
  449. Resource:
  450. - arn:aws:logs:*:*:*
  451. WebAutoScalingGroup:
  452. Type: AWS::AutoScaling::AutoScalingGroup
  453. Properties:
  454. Cooldown: 60
  455. HealthCheckGracePeriod: 120
  456. HealthCheckType: ELB
  457. LaunchConfigurationName:
  458. !If
  459. [ PHP55,
  460. !Ref WebLaunchConfiguration55,
  461. !If
  462. [ PHP56,
  463. !Ref WebLaunchConfiguration56,
  464. !Ref WebLaunchConfiguration70
  465. ]
  466. ]
  467. MaxSize: !Ref WebAsgMax
  468. MinSize: !Ref WebAsgMin
  469. Tags:
  470. - Key: Name
  471. Value: !Join [ '', [ 'Web ASG / ', !Ref 'AWS::StackName' ] ]
  472. PropagateAtLaunch: true
  473. TargetGroupARNs:
  474. - !Ref PublicAlbTargetGroupArn
  475. VPCZoneIdentifier:
  476. !If
  477. [ NumberOfSubnets1,
  478. [ !Select [ 0, !Ref Subnet ] ],
  479. !If
  480. [ NumberOfSubnets2,
  481. [ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ] ],
  482. !If
  483. [ NumberOfSubnets3,
  484. [ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ], !Select [ 2, !Ref Subnet ] ],
  485. !If
  486. [ NumberOfSubnets4,
  487. [ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ], !Select [ 2, !Ref Subnet ], !Select [ 3, !Ref Subnet ] ],
  488. !If
  489. [ NumberOfSubnets5,
  490. [ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ], !Select [ 2, !Ref Subnet ], !Select [ 3, !Ref Subnet ], !Select [ 4, !Ref Subnet ] ],
  491. [ !Select [ 0, !Ref Subnet ], !Select [ 1, !Ref Subnet ], !Select [ 2, !Ref Subnet ], !Select [ 3, !Ref Subnet ], !Select [ 4, !Ref Subnet ], !Select [ 5, !Ref Subnet ] ]
  492. ]
  493. ]
  494. ]
  495. ]
  496. ]
  497. CreationPolicy:
  498. ResourceSignal:
  499. Count: !Ref WebAsgMin
  500. Timeout: PT5M
  501. WebLaunchConfiguration55:
  502. Condition: PHP55
  503. Type: AWS::AutoScaling::LaunchConfiguration
  504. Metadata:
  505. AWS::CloudFormation::Init:
  506. configSets:
  507. deploy_webserver:
  508. - install_webserver
  509. - build_cacheclient
  510. - build_wordpress
  511. - build_opcache
  512. - download_aws_ini
  513. - install_aws_ini
  514. - install_cacheclient
  515. - install_wordpress
  516. - install_opcache
  517. - start_webserver
  518. install_webserver:
  519. packages:
  520. yum:
  521. awslogs: []
  522. httpd24: []
  523. mysql56: []
  524. php55: []
  525. php55-devel: []
  526. php55-pear: []
  527. php55-mysqlnd: []
  528. files:
  529. /tmp/create_site_conf.sh:
  530. content:
  531. !Join [
  532. "",[
  533. "#!/bin/bash -xe\n",
  534. "if [ ! -f /etc/httpd/conf.d/", !Ref WPDirectory, ".conf ]; then\n",
  535. " touch /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  536. " echo 'ServerName 127.0.0.1:80' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  537. " echo 'DocumentRoot /var/www/wordpress/", !Ref WPDirectory, "' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  538. " echo '<Directory /var/www/wordpress/", !Ref WPDirectory, ">' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  539. " echo ' Options Indexes FollowSymLinks' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  540. " echo ' AllowOverride All' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  541. " echo ' Require all granted' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  542. " echo '</Directory>' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  543. "fi\n"
  544. ]
  545. ]
  546. mode: 000500
  547. owner: root
  548. group: root
  549. commands:
  550. create_site_conf:
  551. command: ./create_site_conf.sh
  552. cwd: /tmp
  553. ignoreErrors: false
  554. build_cacheclient:
  555. packages:
  556. yum:
  557. gcc-c++: []
  558. files:
  559. /tmp/install_cacheclient.sh:
  560. content:
  561. !Sub |
  562. #!/bin/bash -xe
  563. pecl install igbinary
  564. wget -P /tmp/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/AmazonElastiCacheClusterClient-1.0.1-PHP55-64bit.tgz
  565. tar -xf '/tmp/AmazonElastiCacheClusterClient-1.0.1-PHP55-64bit.tgz'
  566. cp '/tmp/AmazonElastiCacheClusterClient-1.0.0/amazon-elasticache-cluster-client.so' /usr/lib64/php/5.5/modules/
  567. if [ ! -f /etc/php-5.5.d/50-memcached.ini ]; then
  568. touch /etc/php-5.5.d/50-memcached.ini
  569. fi
  570. echo 'extension=igbinary.so;' >> /etc/php-5.5.d/50-memcached.ini
  571. echo 'extension=/usr/lib64/php/5.5/modules/amazon-elasticache-cluster-client.so;' >> /etc/php-5.5.d/50-memcached.ini
  572. mode: 000500
  573. owner: root
  574. group: root
  575. build_opcache:
  576. packages:
  577. yum:
  578. php55-opcache: []
  579. files:
  580. /tmp/install_opcache.sh:
  581. content:
  582. !Sub |
  583. #!/bin/bash -xe
  584. # create hidden opcache directory locally & change owner to apache
  585. if [ ! -d /var/www/.opcache ]; then
  586. mkdir -p /var/www/.opcache
  587. fi
  588. # enable opcache in /etc/php-5.5.d/opcache.ini
  589. sed -i 's/;opcache.file_cache=.*/opcache.file_cache=\/var\/www\/.opcache/' /etc/php-5.5.d/opcache.ini
  590. sed -i 's/opcache.memory_consumption=.*/opcache.memory_consumption=512/' /etc/php-5.5.d/opcache.ini
  591. # download opcache-instance.php to verify opcache status
  592. if [ ! -f /var/www/wordpress/${WPDirectory}/opcache-instanceid.php ]; then
  593. wget -P /var/www/wordpress/${WPDirectory}/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/opcache-instanceid.php
  594. fi
  595. mode: 000500
  596. owner: root
  597. group: root
  598. build_wordpress:
  599. files:
  600. /tmp/install_wordpress.sh:
  601. content:
  602. !Join [
  603. "",[
  604. "#!/bin/bash -xe\n",
  605. "\n",
  606. "# install wp-cli\n",
  607. "if [ ! -f /bin/wp/wp-cli.phar ]; then\n",
  608. " curl -o /bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar\n",
  609. " chmod +x /bin/wp\n",
  610. "fi\n",
  611. "\n",
  612. "# make site directory\n",
  613. "if [ ! -d /var/www/wordpress/", !Ref WPDirectory, " ]; then\n",
  614. " mkdir -p /var/www/wordpress/", !Ref WPDirectory, "\n",
  615. "\n",
  616. " cd /var/www/wordpress/", !Ref WPDirectory, "\n",
  617. " # install wordpress if not installed\n",
  618. " # use public alb host name if wp domain name was empty\n",
  619. " if ! $(wp core is-installed --allow-root); then\n",
  620. " wp core download --version='", !Ref WPVersion, "' --locale='", !Ref WPLocale, "' --allow-root\n",
  621. " wp core config --dbname='", !Ref DatabaseName, "' --dbuser='", !Ref DatabaseMasterUsername, "' --dbpass='", !Ref DatabaseMasterPassword, "' --dbhost='", !Ref DatabaseClusterEndpointAddress, "' --dbprefix=wp_ --allow-root\n",
  622. " 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",
  623. " wp plugin install w3-total-cache --allow-root\n",
  624. " sed -i \"/$table_prefix = 'wp_';/ a \\define('WP_HOME', 'http://' . \\$_SERVER['HTTP_HOST']); \" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n",
  625. " sed -i \"/$table_prefix = 'wp_';/ a \\define('WP_SITEURL', 'http://' . \\$_SERVER['HTTP_HOST']); \" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n",
  626. " # enable HTTPS in wp-config.php if ACM Public SSL Certificate parameter was not empty\n",
  627. !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" ] ] ],
  628. "\n",
  629. " # set permissions of wordpress site directories\n",
  630. " chown -R apache:apache /var/www/wordpress/", !Ref WPDirectory, "\n",
  631. " chmod u+wrx /var/www/wordpress/", !Ref WPDirectory, "/wp-content/*\n",
  632. " if [ ! -f /var/www/wordpress/", !Ref WPDirectory, "/opcache-instanceid.php ]; then\n",
  633. " wget -P /var/www/wordpress/", !Ref WPDirectory, "/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/opcache-instanceid.php\n",
  634. " fi\n",
  635. " fi\n",
  636. " RESULT=$?\n",
  637. " if [ $RESULT -eq 0 ]; then\n",
  638. " touch /var/www/wordpress/", !Ref WPDirectory, "/wordpress.initialized\n",
  639. " else\n",
  640. " touch /var/www/wordpress/", !Ref WPDirectory, "/wordpress.failed\n",
  641. " fi\n",
  642. "fi\n"
  643. ]
  644. ]
  645. mode: 000500
  646. owner: root
  647. group: root
  648. download_aws_ini:
  649. files:
  650. /tmp/download_aws_ini.sh:
  651. content:
  652. !Join [
  653. "",[
  654. "#!/bin/bash -x\n",
  655. "\n",
  656. "wget -P /etc/php-5.5.d/ ", !Ref PHPIniOverride, "\n"
  657. ]
  658. ]
  659. mode: 000500
  660. owner: root
  661. group: root
  662. install_aws_ini:
  663. commands:
  664. install_aws_ini:
  665. command: ./download_aws_ini.sh
  666. cwd: /tmp
  667. ignoreErrors: true
  668. install_wordpress:
  669. commands:
  670. install_wordpress:
  671. command: ./install_wordpress.sh
  672. cwd: /tmp
  673. ignoreErrors: false
  674. install_cacheclient:
  675. commands:
  676. install_cacheclient:
  677. command: ./install_cacheclient.sh
  678. cwd: /tmp
  679. ignoreErrors: false
  680. install_opcache:
  681. commands:
  682. install_opcache:
  683. command: ./install_opcache.sh
  684. cwd: /tmp
  685. ignoreErrors: false
  686. start_webserver:
  687. services:
  688. sysvinit:
  689. httpd:
  690. enabled: true
  691. ensureRunning: true
  692. Properties:
  693. IamInstanceProfile: !Ref WebInstanceProfile
  694. ImageId: !FindInMap [ RegionMap, !Ref 'AWS::Region', AMI ]
  695. InstanceMonitoring: true
  696. InstanceType: !Ref WebInstanceType
  697. KeyName: !Ref EC2KeyName
  698. SecurityGroups:
  699. - !Ref WebSecurityGroup
  700. UserData:
  701. "Fn::Base64":
  702. !Sub |
  703. #!/bin/bash -xe
  704. yum update -y
  705. mkdir -p /var/www/wordpress
  706. 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
  707. /opt/aws/bin/cfn-init --configsets deploy_webserver --verbose --stack ${AWS::StackName} --resource WebLaunchConfiguration55 --region ${AWS::Region}
  708. /opt/aws/bin/cfn-signal --exit-code $? --stack ${AWS::StackName} --resource WebAutoScalingGroup --region ${AWS::Region}
  709. WebLaunchConfiguration56:
  710. Condition: PHP56
  711. Type: AWS::AutoScaling::LaunchConfiguration
  712. Metadata:
  713. AWS::CloudFormation::Init:
  714. configSets:
  715. deploy_webserver:
  716. - install_webserver
  717. - build_cacheclient
  718. - build_wordpress
  719. - build_opcache
  720. - download_aws_ini
  721. - install_aws_ini
  722. - install_cacheclient
  723. - install_wordpress
  724. - install_opcache
  725. - start_webserver
  726. install_webserver:
  727. packages:
  728. yum:
  729. awslogs: []
  730. httpd24: []
  731. mysql56: []
  732. php56: []
  733. php56-devel: []
  734. php56-pear: []
  735. php56-mysqlnd: []
  736. files:
  737. /tmp/create_site_conf.sh:
  738. content:
  739. !Join [
  740. "",[
  741. "#!/bin/bash -xe\n",
  742. "if [ ! -f /etc/httpd/conf.d/", !Ref WPDirectory, ".conf ]; then\n",
  743. " touch /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  744. " echo 'ServerName 127.0.0.1:80' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  745. " echo 'DocumentRoot /var/www/wordpress/", !Ref WPDirectory, "' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  746. " echo '<Directory /var/www/wordpress/", !Ref WPDirectory, ">' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  747. " echo ' Options Indexes FollowSymLinks' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  748. " echo ' AllowOverride All' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  749. " echo ' Require all granted' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  750. " echo '</Directory>' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  751. "fi\n"
  752. ]
  753. ]
  754. mode: 000500
  755. owner: root
  756. group: root
  757. commands:
  758. create_site_conf:
  759. command: ./create_site_conf.sh
  760. cwd: /tmp
  761. ignoreErrors: false
  762. build_cacheclient:
  763. packages:
  764. yum:
  765. gcc-c++: []
  766. files:
  767. /tmp/install_cacheclient.sh:
  768. content:
  769. !Sub |
  770. #!/bin/bash -xe
  771. pecl install igbinary
  772. wget -P /tmp/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/AmazonElastiCacheClusterClient-1.0.0-PHP56-64bit.tgz
  773. tar -xf '/tmp/AmazonElastiCacheClusterClient-1.0.0-PHP56-64bit.tgz'
  774. cp '/tmp/AmazonElastiCacheClusterClient-1.0.0/amazon-elasticache-cluster-client.so' /usr/lib64/php/5.6/modules/
  775. if [ ! -f /etc/php-5.6.d/50-memcached.ini ]; then
  776. touch /etc/php-5.6.d/50-memcached.ini
  777. fi
  778. echo 'extension=igbinary.so;' >> /etc/php-5.6.d/50-memcached.ini
  779. echo 'extension=/usr/lib64/php/5.6/modules/amazon-elasticache-cluster-client.so;' >> /etc/php-5.6.d/50-memcached.ini
  780. mode: 000500
  781. owner: root
  782. group: root
  783. build_opcache:
  784. packages:
  785. yum:
  786. php56-opcache: []
  787. files:
  788. /tmp/install_opcache.sh:
  789. content:
  790. !Sub |
  791. #!/bin/bash -xe
  792. # create hidden opcache directory locally & change owner to apache
  793. if [ ! -d /var/www/.opcache ]; then
  794. mkdir -p /var/www/.opcache
  795. fi
  796. # enable opcache in /etc/php-5.6.d/opcache.ini
  797. sed -i 's/;opcache.file_cache=.*/opcache.file_cache=\/var\/www\/.opcache/' /etc/php-5.6.d/10-opcache.ini
  798. sed -i 's/opcache.memory_consumption=.*/opcache.memory_consumption=512/' /etc/php-5.6.d/10-opcache.ini
  799. # download opcache-instance.php to verify opcache status
  800. if [ ! -f /var/www/wordpress/${WPDirectory}/opcache-instanceid.php ]; then
  801. wget -P /var/www/wordpress/${WPDirectory}/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/opcache-instanceid.php
  802. fi
  803. mode: 000500
  804. owner: root
  805. group: root
  806. build_wordpress:
  807. files:
  808. /tmp/install_wordpress.sh:
  809. content:
  810. !Join [
  811. "",[
  812. "#!/bin/bash -xe\n",
  813. "\n",
  814. "# install wp-cli\n",
  815. "if [ ! -f /bin/wp/wp-cli.phar ]; then\n",
  816. " curl -o /bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar\n",
  817. " chmod +x /bin/wp\n",
  818. "fi\n",
  819. "\n",
  820. "# make site directory\n",
  821. "if [ ! -d /var/www/wordpress/", !Ref WPDirectory, " ]; then\n",
  822. " mkdir -p /var/www/wordpress/", !Ref WPDirectory, "\n",
  823. "\n",
  824. " cd /var/www/wordpress/", !Ref WPDirectory, "\n",
  825. " # install wordpress if not installed\n",
  826. " # use public alb host name if wp domain name was empty\n",
  827. " if ! $(wp core is-installed --allow-root); then\n",
  828. " wp core download --version='", !Ref WPVersion, "' --locale='", !Ref WPLocale, "' --allow-root\n",
  829. " wp core config --dbname='", !Ref DatabaseName, "' --dbuser='", !Ref DatabaseMasterUsername, "' --dbpass='", !Ref DatabaseMasterPassword, "' --dbhost='", !Ref DatabaseClusterEndpointAddress, "' --dbprefix=wp_ --allow-root\n",
  830. " 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",
  831. " wp plugin install w3-total-cache --allow-root\n",
  832. " sed -i \"/$table_prefix = 'wp_';/ a \\define('WP_HOME', 'http://' . \\$_SERVER['HTTP_HOST']); \" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n",
  833. " sed -i \"/$table_prefix = 'wp_';/ a \\define('WP_SITEURL', 'http://' . \\$_SERVER['HTTP_HOST']); \" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n",
  834. " # enable HTTPS in wp-config.php if ACM Public SSL Certificate parameter was not empty\n",
  835. !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" ] ] ],
  836. "\n",
  837. " # set permissions of wordpress site directories\n",
  838. " chown -R apache:apache /var/www/wordpress/", !Ref WPDirectory, "\n",
  839. " chmod u+wrx /var/www/wordpress/", !Ref WPDirectory, "/wp-content/*\n",
  840. " if [ ! -f /var/www/wordpress/", !Ref WPDirectory, "/opcache-instanceid.php ]; then\n",
  841. " wget -P /var/www/wordpress/", !Ref WPDirectory, "/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/opcache-instanceid.php\n",
  842. " fi\n",
  843. " fi\n",
  844. " RESULT=$?\n",
  845. " if [ $RESULT -eq 0 ]; then\n",
  846. " touch /var/www/wordpress/", !Ref WPDirectory, "/wordpress.initialized\n",
  847. " else\n",
  848. " touch /var/www/wordpress/", !Ref WPDirectory, "/wordpress.failed\n",
  849. " fi\n",
  850. "fi\n"
  851. ]
  852. ]
  853. mode: 000500
  854. owner: root
  855. group: root
  856. download_aws_ini:
  857. files:
  858. /tmp/download_aws_ini.sh:
  859. content:
  860. !Join [
  861. "",[
  862. "#!/bin/bash -x\n",
  863. "\n",
  864. "wget -P /etc/php-5.6.d/ ", !Ref PHPIniOverride, "\n"
  865. ]
  866. ]
  867. mode: 000500
  868. owner: root
  869. group: root
  870. install_aws_ini:
  871. commands:
  872. install_aws_ini:
  873. command: ./download_aws_ini.sh
  874. cwd: /tmp
  875. ignoreErrors: true
  876. install_wordpress:
  877. commands:
  878. install_wordpress:
  879. command: ./install_wordpress.sh
  880. cwd: /tmp
  881. ignoreErrors: false
  882. install_cacheclient:
  883. commands:
  884. install_cacheclient:
  885. command: ./install_cacheclient.sh
  886. cwd: /tmp
  887. ignoreErrors: false
  888. install_opcache:
  889. commands:
  890. install_opcache:
  891. command: ./install_opcache.sh
  892. cwd: /tmp
  893. ignoreErrors: false
  894. start_webserver:
  895. services:
  896. sysvinit:
  897. httpd:
  898. enabled: true
  899. ensureRunning: true
  900. Properties:
  901. IamInstanceProfile: !Ref WebInstanceProfile
  902. ImageId: !FindInMap [ RegionMap, !Ref 'AWS::Region', AMI ]
  903. InstanceMonitoring: true
  904. InstanceType: !Ref WebInstanceType
  905. KeyName: !Ref EC2KeyName
  906. SecurityGroups:
  907. - !Ref WebSecurityGroup
  908. UserData:
  909. "Fn::Base64":
  910. !Sub |
  911. #!/bin/bash -xe
  912. yum update -y
  913. mkdir -p /var/www/wordpress
  914. 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
  915. /opt/aws/bin/cfn-init --configsets deploy_webserver --verbose --stack ${AWS::StackName} --resource WebLaunchConfiguration56 --region ${AWS::Region}
  916. /opt/aws/bin/cfn-signal --exit-code $? --stack ${AWS::StackName} --resource WebAutoScalingGroup --region ${AWS::Region}
  917. WebLaunchConfiguration70:
  918. Condition: PHP70
  919. Type: AWS::AutoScaling::LaunchConfiguration
  920. Metadata:
  921. AWS::CloudFormation::Init:
  922. configSets:
  923. deploy_webserver:
  924. - install_webserver
  925. - build_cacheclient
  926. - build_wordpress
  927. - build_opcache
  928. - download_aws_ini
  929. - install_aws_ini
  930. - install_cacheclient
  931. - install_wordpress
  932. - install_opcache
  933. - start_webserver
  934. install_webserver:
  935. packages:
  936. yum:
  937. awslogs: []
  938. httpd24: []
  939. mysql56: []
  940. php70: []
  941. php70-devel: []
  942. php7-pear: []
  943. php70-mysqlnd: []
  944. files:
  945. /tmp/create_site_conf.sh:
  946. content:
  947. !Join [
  948. "",[
  949. "#!/bin/bash -xe\n",
  950. "if [ ! -f /etc/httpd/conf.d/", !Ref WPDirectory, ".conf ]; then\n",
  951. " touch /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  952. " echo 'ServerName 127.0.0.1:80' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  953. " echo 'DocumentRoot /var/www/wordpress/", !Ref WPDirectory, "' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  954. " echo '<Directory /var/www/wordpress/", !Ref WPDirectory, ">' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  955. " echo ' Options Indexes FollowSymLinks' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  956. " echo ' AllowOverride All' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  957. " echo ' Require all granted' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  958. " echo '</Directory>' >> /etc/httpd/conf.d/", !Ref WPDirectory, ".conf\n",
  959. "fi\n"
  960. ]
  961. ]
  962. mode: 000500
  963. owner: root
  964. group: root
  965. commands:
  966. create_site_conf:
  967. command: ./create_site_conf.sh
  968. cwd: /tmp
  969. ignoreErrors: false
  970. build_cacheclient:
  971. packages:
  972. yum:
  973. gcc-c++: []
  974. files:
  975. /tmp/install_cacheclient.sh:
  976. content:
  977. !Sub |
  978. #!/bin/bash -xe
  979. ln -s /usr/bin/pecl7 /usr/bin/pecl #just so pecl is available easily
  980. pecl7 install igbinary
  981. wget -P /tmp/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/AmazonElastiCacheClusterClient-2.0.1-PHP70-64bit.tar.gz
  982. tar -xf '/tmp/AmazonElastiCacheClusterClient-2.0.1-PHP70-64bit.tar.gz'
  983. cp '/tmp/artifact/amazon-elasticache-cluster-client.so' /usr/lib64/php/7.0/modules/
  984. if [ ! -f /etc/php-7.0.d/50-memcached.ini ]; then
  985. touch /etc/php-7.0.d/50-memcached.ini
  986. fi
  987. echo 'extension=igbinary.so;' >> /etc/php-7.0.d/50-memcached.ini
  988. echo 'extension=/usr/lib64/php/7.0/modules/amazon-elasticache-cluster-client.so;' >> /etc/php-7.0.d/50-memcached.ini
  989. mode: 000500
  990. owner: root
  991. group: root
  992. build_opcache:
  993. packages:
  994. yum:
  995. php70-opcache: []
  996. files:
  997. /tmp/install_opcache.sh:
  998. content:
  999. !Sub |
  1000. #!/bin/bash -xe
  1001. # create hidden opcache directory locally & change owner to apache
  1002. if [ ! -d /var/www/.opcache ]; then
  1003. mkdir -p /var/www/.opcache
  1004. fi
  1005. # enable opcache in /etc/php-7.0.d/10-opcache.ini
  1006. sed -i 's/;opcache.file_cache=.*/opcache.file_cache=\/var\/www\/.opcache/' /etc/php-7.0.d/10-opcache.ini
  1007. sed -i 's/opcache.memory_consumption=.*/opcache.memory_consumption=512/' /etc/php-7.0.d/10-opcache.ini
  1008. # download opcache-instance.php to verify opcache status
  1009. if [ ! -f /var/www/wordpress/${WPDirectory}/opcache-instanceid.php ]; then
  1010. wget -P /var/www/wordpress/${WPDirectory}/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/opcache-instanceid.php
  1011. fi
  1012. mode: 000500
  1013. owner: root
  1014. group: root
  1015. build_wordpress:
  1016. files:
  1017. /tmp/install_wordpress.sh:
  1018. content:
  1019. !Join [
  1020. "",[
  1021. "#!/bin/bash -xe\n",
  1022. "\n",
  1023. "# install wp-cli\n",
  1024. "if [ ! -f /bin/wp/wp-cli.phar ]; then\n",
  1025. " curl -o /bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar\n",
  1026. " chmod +x /bin/wp\n",
  1027. "fi\n",
  1028. "\n",
  1029. "# make site directory\n",
  1030. "if [ ! -d /var/www/wordpress/", !Ref WPDirectory, " ]; then\n",
  1031. " mkdir -p /var/www/wordpress/", !Ref WPDirectory, "\n",
  1032. "\n",
  1033. " cd /var/www/wordpress/", !Ref WPDirectory, "\n",
  1034. " # install wordpress if not installed\n",
  1035. " # use public alb host name if wp domain name was empty\n",
  1036. " if ! $(wp core is-installed --allow-root); then\n",
  1037. " wp core download --version='", !Ref WPVersion, "' --locale='", !Ref WPLocale, "' --allow-root\n",
  1038. " wp core config --dbname='", !Ref DatabaseName, "' --dbuser='", !Ref DatabaseMasterUsername, "' --dbpass='", !Ref DatabaseMasterPassword, "' --dbhost='", !Ref DatabaseClusterEndpointAddress, "' --dbprefix=wp_ --allow-root\n",
  1039. " 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",
  1040. " wp plugin install w3-total-cache --allow-root\n",
  1041. " sed -i \"/$table_prefix = 'wp_';/ a \\define('WP_HOME', 'http://' . \\$_SERVER['HTTP_HOST']); \" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n",
  1042. " sed -i \"/$table_prefix = 'wp_';/ a \\define('WP_SITEURL', 'http://' . \\$_SERVER['HTTP_HOST']); \" /var/www/wordpress/", !Ref WPDirectory, "/wp-config.php\n",
  1043. " # enable HTTPS in wp-config.php if ACM Public SSL Certificate parameter was not empty\n",
  1044. !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" ] ] ],
  1045. "\n",
  1046. " # set permissions of wordpress site directories\n",
  1047. " chown -R apache:apache /var/www/wordpress/", !Ref WPDirectory, "\n",
  1048. " chmod u+wrx /var/www/wordpress/", !Ref WPDirectory, "/wp-content/*\n",
  1049. " if [ ! -f /var/www/wordpress/", !Ref WPDirectory, "/opcache-instanceid.php ]; then\n",
  1050. " wget -P /var/www/wordpress/", !Ref WPDirectory, "/ https://s3.amazonaws.com/aws-refarch/wordpress/latest/bits/opcache-instanceid.php\n",
  1051. " fi\n",
  1052. " fi\n",
  1053. " RESULT=$?\n",
  1054. " if [ $RESULT -eq 0 ]; then\n",
  1055. " touch /var/www/wordpress/", !Ref WPDirectory, "/wordpress.initialized\n",
  1056. " else\n",
  1057. " touch /var/www/wordpress/", !Ref WPDirectory, "/wordpress.failed\n",
  1058. " fi\n",
  1059. "fi\n"
  1060. ]
  1061. ]
  1062. mode: 000500
  1063. owner: root
  1064. group: root
  1065. download_aws_ini:
  1066. files:
  1067. /tmp/download_aws_ini.sh:
  1068. content:
  1069. !Join [
  1070. "",[
  1071. "#!/bin/bash -x\n",
  1072. "\n",
  1073. "wget -P /etc/php-7.0.d/ ", !Ref PHPIniOverride, "\n"
  1074. ]
  1075. ]
  1076. mode: 000500
  1077. owner: root
  1078. group: root
  1079. install_aws_ini:
  1080. commands:
  1081. install_aws_ini:
  1082. command: ./download_aws_ini.sh
  1083. cwd: /tmp
  1084. ignoreErrors: true
  1085. install_wordpress:
  1086. commands:
  1087. install_wordpress:
  1088. command: ./install_wordpress.sh
  1089. cwd: /tmp
  1090. ignoreErrors: false
  1091. install_cacheclient:
  1092. commands:
  1093. install_cacheclient:
  1094. command: ./install_cacheclient.sh
  1095. cwd: /tmp
  1096. ignoreErrors: false
  1097. install_opcache:
  1098. commands:
  1099. install_opcache:
  1100. command: ./install_opcache.sh
  1101. cwd: /tmp
  1102. ignoreErrors: false
  1103. start_webserver:
  1104. services:
  1105. sysvinit:
  1106. httpd:
  1107. enabled: true
  1108. ensureRunning: true
  1109. Properties:
  1110. IamInstanceProfile: !Ref WebInstanceProfile
  1111. ImageId: !FindInMap [ RegionMap, !Ref 'AWS::Region', AMI ]
  1112. InstanceMonitoring: true
  1113. InstanceType: !Ref WebInstanceType
  1114. KeyName: !Ref EC2KeyName
  1115. SecurityGroups:
  1116. - !Ref WebSecurityGroup
  1117. UserData:
  1118. "Fn::Base64":
  1119. !Sub |
  1120. #!/bin/bash -xe
  1121. yum update -y
  1122. mkdir -p /var/www/wordpress
  1123. 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
  1124. /opt/aws/bin/cfn-init --configsets deploy_webserver --verbose --stack ${AWS::StackName} --resource WebLaunchConfiguration70 --region ${AWS::Region}
  1125. /opt/aws/bin/cfn-signal --exit-code $? --stack ${AWS::StackName} --resource WebAutoScalingGroup --region ${AWS::Region}
  1126.  
  1127.  
  1128. Outputs:
  1129.  
  1130. Opcachestatus:
  1131. Value: !Join [ '', [ !Ref PublicAlbHostname, '/opcache-instanceid.php' ] ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement