php.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. - name: 'Install common PHP dependencies (Debian <= 8)'
  2. apt:
  3. pkg:
  4. - 'php5-cli'
  5. - 'php5-curl'
  6. - 'php5-gd'
  7. - 'php5-intl'
  8. - 'php5-mcrypt'
  9. - 'php-mime-type'
  10. - 'php5-pgsql'
  11. - 'php5-sqlite'
  12. state: 'present'
  13. when: with_php|bool and ansible_lsb.major_release|int <= 8
  14. tags:
  15. - 'web'
  16. - 'php'
  17. - name: 'Install common PHP dependencies (Debian >= 9)'
  18. apt:
  19. pkg:
  20. - 'php{{ php_version }}-cli'
  21. - 'php{{ php_version }}-curl'
  22. - 'php{{ php_version }}-gd'
  23. - 'php{{ php_version }}-intl'
  24. - 'php{{ php_version }}-mysql'
  25. - 'php{{ php_version }}-pgsql'
  26. - 'php{{ php_version }}-sqlite3'
  27. state: 'present'
  28. when: with_php|bool and ansible_lsb.major_release|int >= 9
  29. tags:
  30. - 'web'
  31. - 'php'
  32. - name: 'Install common PHP dependencies (Debian >= 9 and PHP < 7.2)'
  33. apt:
  34. pkg:
  35. - 'php{{ php_version }}-mcrypt'
  36. state: 'present'
  37. when: with_php|bool and ansible_lsb.major_release|int >= 9 and php_version|float < 7.2
  38. tags:
  39. - 'web'
  40. - 'php'
  41. - name: 'Create PHP log directory'
  42. file:
  43. path: '/var/log/php'
  44. state: directory
  45. owner: 'root'
  46. group: 'root'
  47. mode: '0755'
  48. when: with_php|bool
  49. tags:
  50. - 'web'
  51. - 'php'
  52. - name: 'Install PHP configuration for syslog'
  53. template:
  54. src: '{{ item.src }}'
  55. dest: '{{ item.dest }}'
  56. owner: 'root'
  57. group: 'root'
  58. mode: '0644'
  59. with_items:
  60. - { src: 'rsyslog/php-errors.conf.j2', dest: '/etc/rsyslog.d/php-errors.conf' }
  61. - { src: 'logrotate/php-errors.j2', dest: '/etc/logrotate.d/php-errors' }
  62. notify:
  63. - 'Reload rsyslog for php'
  64. when: with_fpm|bool
  65. tags:
  66. - 'web'
  67. - 'php'
  68. - name: 'Install local PHP configuration overrides for php5-cli (Debian 8)'
  69. template:
  70. src: 'php/php-config-cli.ini.j2'
  71. dest: '/etc/php5/cli/conf.d/99-local-config.ini'
  72. owner: 'root'
  73. group: 'root'
  74. mode: '0644'
  75. when: with_php|bool and ansible_lsb.major_release|int == 8
  76. tags:
  77. - 'web'
  78. - 'php'
  79. - name: 'Install local PHP configuration overrides for php{{ php_version }}-cli (Debian >= 9)'
  80. template:
  81. src: 'php/php-config-cli.ini.j2'
  82. dest: '/etc/php/{{ php_version }}/cli/conf.d/99-local-config.ini'
  83. owner: 'root'
  84. group: 'root'
  85. mode: '0644'
  86. when: with_php|bool and ansible_lsb.major_release|int >= 9
  87. tags:
  88. - 'web'
  89. - 'php'
  90. - name: 'Install Apache2 module for php5'
  91. apt:
  92. pkg:
  93. - 'libapache2-mod-php5'
  94. state: 'present'
  95. notify:
  96. - 'Reload apache2'
  97. when: with_modphp5|bool
  98. tags:
  99. - 'web'
  100. - 'php'
  101. - name: 'Install Apache2 module for php{{ php_version }}'
  102. apt:
  103. pkg:
  104. - 'libapache2-mod-php{{ php_version }}'
  105. state: 'present'
  106. notify:
  107. - 'Reload apache2'
  108. when: with_modphp|bool
  109. tags:
  110. - 'web'
  111. - 'php'
  112. - name: 'Configure Apache2 modules for php-fpm{{ php_version }}'
  113. apache2_module:
  114. name: '{{ item.name }}'
  115. state: '{{ item.state }}'
  116. ignore_configcheck: '{{ item.ignore_configcheck }}'
  117. with_items:
  118. - {name: 'mpm_prefork', state: 'absent', ignore_configcheck: 'yes'}
  119. - {name: 'mpm_event', state: 'present', ignore_configcheck: 'yes'}
  120. - {name: 'php{{ php_version }}', state: 'absent', ignore_configcheck: 'no'}
  121. - {name: 'proxy_fcgi', state: 'present', ignore_configcheck: 'no'}
  122. when: with_fpm|bool and with_apache2|bool
  123. notify:
  124. - 'Reload apache2'
  125. tags:
  126. - 'web'
  127. - 'php'
  128. - name: 'Configure Apache2 modules for modphp{{ php_version }}'
  129. apache2_module:
  130. name: '{{ item.name }}'
  131. state: '{{ item.state }}'
  132. ignore_configcheck: '{{ item.ignore_configcheck }}'
  133. with_items:
  134. - {name: 'mpm_event', state: 'absent', ignore_configcheck: 'yes'}
  135. - {name: 'mpm_prefork', state: 'present', ignore_configcheck: 'yes'}
  136. - {name: 'php{{ php_version }}', state: 'present', ignore_configcheck: 'no'}
  137. when: with_modphp|bool
  138. notify:
  139. - 'Reload apache2'
  140. tags:
  141. - 'web'
  142. - 'php'
  143. - name: 'Install local PHP configuration (Debian < 8)'
  144. template:
  145. src: 'php/php-config-web.ini.j2'
  146. dest: '/etc/php5/conf.d/99-local-config.ini'
  147. owner: 'root'
  148. group: 'root'
  149. mode: '0644'
  150. notify:
  151. - 'Reload apache2'
  152. when: with_modphp5|bool and ansible_lsb.major_release|int < 8
  153. tags:
  154. - 'web'
  155. - 'php'
  156. - name: 'Install local PHP configuration for Apache 2 (Debian 8)'
  157. template:
  158. src: 'php/php-config-web.ini.j2'
  159. dest: '/etc/php5/apache2/conf.d/99-local-config.ini'
  160. owner: 'root'
  161. group: 'root'
  162. mode: '0644'
  163. notify:
  164. - 'Reload apache2'
  165. when: with_modphp5|bool and ansible_lsb.major_release|int == 8
  166. tags:
  167. - 'web'
  168. - 'php'
  169. - name: 'Install local PHP configuration for Apache 2 (Debian >= 9)'
  170. template:
  171. src: 'php/php-config-web.ini.j2'
  172. dest: '/etc/php/{{ php_version }}/apache2/conf.d/99-local-config.ini'
  173. owner: 'root'
  174. group: 'root'
  175. mode: '0644'
  176. notify:
  177. - 'Reload apache2'
  178. when: with_modphp|bool and ansible_lsb.major_release|int >= 9
  179. tags:
  180. - 'web'
  181. - 'php'
  182. - name: 'Create system checks directory /etc/phpsyscheck'
  183. file:
  184. path: '/etc/phpsyscheck'
  185. state: 'directory'
  186. owner: 'root'
  187. group: 'root'
  188. mode: '0755'
  189. tags:
  190. - 'web'
  191. - 'php'
  192. - name: 'Install phpinfo system check'
  193. template:
  194. src: 'php/phpinfo.php'
  195. dest: '/etc/phpsyscheck/index.php'
  196. owner: 'root'
  197. group: 'root'
  198. mode: '0644'
  199. - name: 'Install PHP APC extension (Debian <= 8)'
  200. apt:
  201. pkg:
  202. - 'php-apc'
  203. state: 'present'
  204. when: with_php_apc|bool and ansible_lsb.major_release|int <= 8
  205. tags:
  206. - 'web'
  207. - 'php'
  208. - name: 'Install PHP APC extension (Debian >= 9)'
  209. apt:
  210. pkg:
  211. - 'php-apcu'
  212. state: 'present'
  213. when: with_php_apc|bool and ansible_lsb.major_release|int >= 9
  214. tags:
  215. - 'web'
  216. - 'php'
  217. - name: 'Install php-apc system check'
  218. template:
  219. src: 'php/apc.php'
  220. dest: '/etc/phpsyscheck/apc.php'
  221. owner: 'root'
  222. group: 'root'
  223. mode: '0644'
  224. when: with_php_apc|bool
  225. tags:
  226. - 'web'
  227. - 'php'
  228. - name: 'Install MySQL extension for PHP - native driver (Debian 8)'
  229. apt:
  230. pkg:
  231. - 'php5-mysqlnd'
  232. state: 'present'
  233. when: not with_php_mysql_legacy|bool and ansible_lsb.major_release|int == 8
  234. tags:
  235. - 'web'
  236. - 'php'
  237. - name: 'Install MySQL extension for PHP (old driver)'
  238. apt:
  239. pkg: 'php5-mysql'
  240. state: 'present'
  241. when: with_php_mysql_legacy|bool
  242. tags:
  243. - 'web'
  244. - 'php'
  245. - name: 'Install PHPMyAdmin'
  246. apt:
  247. pkg:
  248. - 'phpmyadmin'
  249. state: 'present'
  250. when: with_phpmyadmin|bool
  251. tags:
  252. - 'web'
  253. - 'php'
  254. - name: 'Install PHPPgAdmin'
  255. apt:
  256. pkg:
  257. - 'phppgadmin'
  258. state: 'present'
  259. when: with_phppgadmin|bool
  260. tags:
  261. - 'web'
  262. - 'php'
  263. - name: 'Install FPM for PHP 5 (Debian <= 8)'
  264. apt:
  265. pkg:
  266. - 'php5-fpm'
  267. state: 'present'
  268. when: with_fpm|bool and ansible_lsb.major_release|int <= 8
  269. tags:
  270. - 'web'
  271. - 'php'
  272. - name: 'Install FPM for PHP {{ php_version }} (Debian >= 9)'
  273. apt:
  274. pkg:
  275. - 'php{{ php_version }}-fpm'
  276. state: 'present'
  277. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  278. tags:
  279. - 'web'
  280. - 'php'
  281. - name: 'Configure FPM for PHP 5 (Debian <= 8)'
  282. lineinfile:
  283. dest: '/etc/php5/fpm/php-fpm.conf'
  284. regexp: '^{{ item.key }}\s*=.*$'
  285. line: '{{ item.key }} = {{ item.value }}'
  286. insertafter: '^;{{ item.key }}'
  287. with_items:
  288. - { key: 'error_log', value: 'syslog' }
  289. - { key: 'log_level', value: 'warning' }
  290. - { key: 'emergency_restart_threshold', value: '100' }
  291. - { key: 'emergency_restart_interval', value: '5s' }
  292. - { key: 'rlimit_files', value: '262144' }
  293. - { key: 'events.mechanism', value: 'epoll' }
  294. - { key: 'include', value: '/etc/php5/fpm/pool.d/local-pool.cnf' }
  295. notify:
  296. - 'Reload FPM for PHP 5'
  297. when: with_fpm|bool and ansible_lsb.major_release|int <= 8
  298. tags:
  299. - 'web'
  300. - 'php'
  301. - name: 'Configure FPM for PHP {{ php_version }} (Debian >= 9)'
  302. lineinfile:
  303. dest: '/etc/php/{{ php_version }}/fpm/php-fpm.conf'
  304. regexp: '^{{ item.key }}\s*=.*$'
  305. line: '{{ item.key }} = {{ item.value }}'
  306. insertafter: '^;{{ item.key }}'
  307. with_items:
  308. - { key: 'error_log', value: 'syslog' }
  309. - { key: 'log_level', value: 'warning' }
  310. - { key: 'emergency_restart_threshold', value: '100' }
  311. - { key: 'emergency_restart_interval', value: '5s' }
  312. - { key: 'rlimit_files', value: '262144' }
  313. - { key: 'events.mechanism', value: 'epoll' }
  314. - { key: 'include', value: '/etc/php/{{ php_version }}/fpm/pool.d/local-pool.cnf' }
  315. notify:
  316. - 'Reload FPM for PHP'
  317. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  318. tags:
  319. - 'web'
  320. - 'php'
  321. - name: 'Install FPM pools configuration for PHP 5 (Debian <= 8)'
  322. template:
  323. src: 'fpm/php5-fpm-pools.conf.j2'
  324. dest: '/etc/php5/fpm/pool.d/local-pool.cnf'
  325. owner: 'root'
  326. group: 'root'
  327. mode: '0644'
  328. notify:
  329. - 'Reload FPM for PHP 5'
  330. when: with_fpm|bool and ansible_lsb.major_release|int <= 8
  331. tags:
  332. - 'web'
  333. - 'php'
  334. - name: 'Install FPM pools configuration for PHP {{ php_version }} (Debian > 9)'
  335. template:
  336. src: 'fpm/php-fpm-pools.conf.j2'
  337. dest: '/etc/php/{{ php_version }}/fpm/pool.d/local-pool.cnf'
  338. owner: 'root'
  339. group: 'root'
  340. mode: '0644'
  341. notify:
  342. - 'Reload FPM for PHP'
  343. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  344. tags:
  345. - 'web'
  346. - 'php'
  347. - name: 'Install local PHP configuration overrides for php5-fpm (Debian 8)'
  348. template:
  349. src: 'php/php-config-web.ini.j2'
  350. dest: '/etc/php5/fpm/conf.d/99-local-config.ini'
  351. owner: 'root'
  352. group: 'root'
  353. mode: '0644'
  354. when: with_fpm|bool and ansible_lsb.major_release|int == 8
  355. tags:
  356. - 'web'
  357. - 'php'
  358. - name: 'Install local PHP configuration overrides for php{{ php_version }}-fpm (Debian >= 9)'
  359. template:
  360. src: 'php/php-config-web.ini.j2'
  361. dest: '/etc/php/{{ php_version }}/fpm/conf.d/99-local-config.ini'
  362. owner: 'root'
  363. group: 'root'
  364. mode: '0644'
  365. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  366. tags:
  367. - 'web'
  368. - 'php'
  369. - name: 'Install Apache2 config files for PHP FPM'
  370. template:
  371. src: 'fpm/apache2/fpm-pool.conf.j2'
  372. dest: '/etc/apache2/conf-available/fpm-pool.conf'
  373. owner: 'root'
  374. group: 'root'
  375. mode: '0644'
  376. when: with_fpm|bool and with_apache2|bool
  377. tags:
  378. - 'web'
  379. - 'php'
  380. - name: 'Install Nginx config files for PHP FPM (fpm servers pool)'
  381. template:
  382. src: 'fpm/nginx/fpm-pool.conf.j2'
  383. dest: '/etc/nginx/conf.d/fpm-pool.conf'
  384. owner: 'root'
  385. group: 'root'
  386. mode: '0644'
  387. notify:
  388. - 'Reload nginx'
  389. when: with_fpm|bool and with_nginx|bool
  390. tags:
  391. - 'web'
  392. - 'php'
  393. - name: 'Install Nginx config files for PHP FPM (fpm fastcgi config)'
  394. template:
  395. src: 'fpm/nginx/fastcgi_pass_fpm.j2'
  396. dest: '/etc/nginx/fastcgi_pass_fpm'
  397. owner: 'root'
  398. group: 'root'
  399. mode: '0644'
  400. notify:
  401. - 'Reload nginx'
  402. when: with_fpm|bool and with_nginx|bool
  403. tags:
  404. - 'web'
  405. - 'php'
  406. - name: 'Ensure FPM for PHP 5 is running (Debian <= 8)'
  407. service:
  408. name: 'php5-fpm'
  409. state: 'started'
  410. when: with_fpm|bool and ansible_lsb.major_release|int <= 8
  411. tags:
  412. - 'web'
  413. - 'php'
  414. - name: 'Ensure FPM for PHP {{ php_version }} is running (Debian >= 9)'
  415. service:
  416. name: 'php{{ php_version }}-fpm'
  417. state: 'started'
  418. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  419. tags:
  420. - 'web'
  421. - 'php'
  422. # vim: ft=yaml.ansible