Advertisement
Guest User

Untitled

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