Advertisement
Guest User

Untitled

a guest
Feb 4th, 2020
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. packages:
  2. yum:
  3. php7-php-fpm: []
  4.  
  5. files:
  6. "/opt/elasticbeanstalk/hooks/appdeploy/pre/26_phpfpm_config.sh":
  7. mode: "000755"
  8. owner: root
  9. group: root
  10. content: |
  11. #!/usr/bin/env bash
  12.  
  13. # Configure PHP FPM based on the memory limits of this server
  14. MAX_CHILDREN=$(free -m | awk 'FNR == 2 {print int(($2-200)/18 / 5) * 5}')
  15. MIN_SPARE=$(($MAX_CHILDREN/5*1))
  16. MAX_SPARE=$(($MAX_CHILDREN/5*2))
  17. START=$(($MIN_SPARE + ($MAX_SPARE - $MIN_SPARE) / 2))
  18.  
  19. sed -i "s/pm.max_children.*/pm.max_children = $MAX_CHILDREN/" /etc/php-fpm-7.1.d/www.conf
  20. sed -i "s/pm.start_servers.*/pm.start_servers = $START/" /etc/php-fpm-7.1.d/www.conf
  21. sed -i "s/pm.min_spare.*/pm.min_spare_servers = $MIN_SPARE/" /etc/php-fpm-7.1.d/www.conf
  22. sed -i "s/pm.max_spare.*/pm.max_spare_servers = $MAX_SPARE/" /etc/php-fpm-7.1.d/www.conf
  23.  
  24. "/opt/elasticbeanstalk/hooks/appdeploy/pre/27_phpfpm_start.sh":
  25. mode: "000755"
  26. owner: root
  27. group: root
  28. content: |
  29. #!/usr/bin/env bash
  30.  
  31. . /opt/elasticbeanstalk/support/envvars
  32.  
  33. #service php-fpm-5.5 start
  34. service php-fpm-7.1 start
  35.  
  36. "/opt/elasticbeanstalk/hooks/appdeploy/enact/99_reload_app_server.sh":
  37. mode: "000755"
  38. owner: root
  39. group: root
  40. content: |
  41. #!/usr/bin/env bash
  42.  
  43. . /opt/elasticbeanstalk/support/envvars
  44.  
  45. if [ "$EB_FIRST_RUN" = "true" ]; then
  46. # Hard restart on first app deploy
  47. service httpd restart
  48. #service php-fpm-5.5 restart
  49. service php-fpm-7.1 restart
  50. else
  51. # Graceful restart on other app deploys
  52. service httpd graceful
  53. #service php-fpm-5.5 reload
  54. service php-fpm-7.1 reload
  55. fi
  56.  
  57. "/etc/php-fpm.d/www.conf":
  58. mode: "000644"
  59. owner: root
  60. group: root
  61. content: |
  62. [www]
  63. user = webapp
  64. group = webapp
  65.  
  66. #listen = /var/run/php-fpm/php5-fpm.sock
  67. listen = /var/run/php-fpm/php-fpm-7.1.sock
  68. listen.owner = webapp
  69. listen.group = webapp
  70. listen.mode = 0666
  71.  
  72. ; These values are defauls, but dynamically configured by script above on deploymentsudo
  73. pm = dynamic
  74. pm.max_children = 20
  75. pm.start_servers = 6
  76. pm.min_spare_servers = 4
  77. pm.max_spare_servers = 8
  78. pm.max_requests = 1000
  79. ping.path = /ping
  80. pm.status_path = /status
  81.  
  82. chdir = /
  83. catch_workers_output = yes
  84.  
  85. php_admin_value[error_log] = /var/log/httpd/php-fpm.www.log
  86. php_admin_flag[log_errors] = on
  87. php_admin_flag[display_errors] = off
  88.  
  89. "/etc/httpd/conf.d/php.conf":
  90. mode: "000644"
  91. owner: root
  92. group: root
  93. content: |
  94. # Ping to make sure PHP is still alive (allow only from load balancers and localhost)
  95. <LocationMatch "/(ping|status)$">
  96. Require ip 10.0.0.0/8
  97. Require ip 127.0.0.1
  98. </LocationMatch>
  99. #ProxyPassMatch ^/(ping|status)$ unix:/var/run/php-fpm/php5-fpm.sock|fcgi://localhost/
  100. ProxyPassMatch ^/(ping|status)$ unix:/var/run/php-fpm/php-fpm-7.1.sock|fcgi://localhost/
  101.  
  102. #
  103. # Cause the PHP interpreter to handle files with a .php extension.
  104. #
  105. <FilesMatch \.php$>
  106. RewriteEngine on
  107. RewriteCond %{REQUEST_FILENAME} !-f
  108. RewriteRule ^ - [R=404,L]
  109. #SetHandler "proxy:unix:/var/run/php-fpm/php5-fpm.sock|fcgi://localhost"
  110. SetHandler "proxy:unix:/var/run/php-fpm/php-fpm-7.1.sock|fcgi://localhost"
  111. </FilesMatch>
  112.  
  113. #
  114. # Allow php to handle Multiviews
  115. #
  116. AddType text/html .php
  117.  
  118. #
  119. # Add index.php to the list of files that will be served as directory
  120. # indexes.
  121. #
  122. DirectoryIndex index.php
  123.  
  124. "/etc/httpd/conf.d/realip.conf":
  125. mode: "000644"
  126. owner: root
  127. group: root
  128. content: |
  129. RemoteIPHeader X-Forwarded-For
  130.  
  131. "/etc/httpd/conf.d/mpm.conf":
  132. mode: "000644"
  133. owner: root
  134. group: root
  135. content: |
  136. <IfModule mpm_event_module>
  137. StartServers 3
  138. MinSpareThreads 75
  139. MaxSpareThreads 150
  140. ThreadLimit 32
  141. ThreadsPerChild 32
  142. MaxRequestWorkers 512
  143. MaxConnectionsPerChild 0
  144. ServerLimit 16
  145. </IfModule>
  146.  
  147.  
  148. commands:
  149. 01_adjust_configdeploy_reload_app_server_hook:
  150. cwd: /opt/elasticbeanstalk/hooks/configdeploy/enact
  151. test: "! grep -q php-fpm-7.1 99_reload_app_server.sh"
  152. command: "echo service php-fpm-7.1 restart >> 99_reload_app_server.sh"
  153.  
  154. 02_adjust_restartappserver_restart_hook:
  155. cwd: /opt/elasticbeanstalk/hooks/restartappserver/enact
  156. test: "! grep -q php-fpm-7.1 01_restart.sh"
  157. command: "echo service php-fpm-7.1 restart >> 01_restart.sh"
  158.  
  159. 03_fix_preinit_configure_php_hook:
  160. cwd: /opt/elasticbeanstalk/hooks/preinit
  161. command: "sed -i \"s~'AWS Settings' /etc/httpd/conf/httpd.conf~'AWS Settings' /etc/php.ini~g\" 04_configure_php.sh"
  162.  
  163. 04a_use_event_mpm:
  164. cwd: /etc/httpd/conf.modules.d
  165. command: "sed -i 's/^LoadModule mpm_prefork_module/#LoadModule mpm_prefork_module/' 00-mpm.conf"
  166. 04b_use_event_mpm:
  167. cwd: /etc/httpd/conf.modules.d
  168. command: "sed -i 's/^#LoadModule mpm_event_module/LoadModule mpm_event_module/' 00-mpm.conf"
  169.  
  170. 06_tail_php-fpm_logs:
  171. cwd: /opt/elasticbeanstalk/tasks/taillogs.d
  172. test: "! grep -q php-fpm webapp.conf"
  173. command: "echo -e \"\n/var/log/httpd/php-fpm.www.log\" >> webapp.conf"
  174.  
  175. 07_correct_log_format:
  176. cwd: /etc/httpd/conf
  177. command: "sed -i 's/LogFormat \"%h/LogFormat \"%a/g' httpd.conf"
  178.  
  179. 08_turn_off_mod_php:
  180. cwd: /etc/httpd/conf.modules.d/
  181. ignoreErrors: true
  182. command: "mv 10-php.conf 10-php.conf.disabled 2>/dev/null"
  183.  
  184. 09_fix_upstart_script:
  185. cwd: /etc/init
  186. test: "! grep -q post-stop httpd.conf"
  187. command: "echo -e \"post-stop script\n\tsleep 5\nend script\" >> /etc/init/httpd.conf"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement