php.yml 11 KB

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