php.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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, PHP version {{ php_version }})'
  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, PHP < 7.2, PHP version {{ php_version }})'
  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. shell: a2dismod php{{ php_version }} mpm_prefork ; a2enmod mpm_event proxy_fcgi
  114. changed_when: False
  115. when: with_fpm|bool and with_apache2|bool
  116. notify:
  117. - 'Reload apache2'
  118. tags:
  119. - 'web'
  120. - 'php'
  121. - name: 'Configure Apache2 modules for modphp{{ php_version }}'
  122. shell: a2dismod mpm_event ; a2enmod mpm_prefork php{{ php_version }}
  123. changed_when: False
  124. when: with_modphp|bool
  125. notify:
  126. - 'Reload apache2'
  127. tags:
  128. - 'web'
  129. - 'php'
  130. - name: 'Install local PHP configuration (Debian < 8)'
  131. template:
  132. src: 'php/php-config-web.ini.j2'
  133. dest: '/etc/php5/conf.d/99-local-config.ini'
  134. owner: 'root'
  135. group: 'root'
  136. mode: '0644'
  137. notify:
  138. - 'Reload apache2'
  139. when: with_modphp5|bool and ansible_lsb.major_release|int < 8
  140. tags:
  141. - 'web'
  142. - 'php'
  143. - name: 'Install local PHP configuration for Apache 2 (Debian 8)'
  144. template:
  145. src: 'php/php-config-web.ini.j2'
  146. dest: '/etc/php5/apache2/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 >= 9)'
  157. template:
  158. src: 'php/php-config-web.ini.j2'
  159. dest: '/etc/php/{{ php_version }}/apache2/conf.d/99-local-config.ini'
  160. owner: 'root'
  161. group: 'root'
  162. mode: '0644'
  163. notify:
  164. - 'Reload apache2'
  165. when: with_modphp|bool and ansible_lsb.major_release|int >= 9
  166. tags:
  167. - 'web'
  168. - 'php'
  169. - name: 'Create system checks directory /etc/phpsyscheck'
  170. file:
  171. path: '/etc/phpsyscheck'
  172. state: 'directory'
  173. owner: 'root'
  174. group: 'root'
  175. mode: '0755'
  176. when: with_phpsyscheck|bool
  177. tags:
  178. - 'web'
  179. - 'php'
  180. - name: 'Install phpinfo system check'
  181. template:
  182. src: 'php/phpinfo.php'
  183. dest: '/etc/phpsyscheck/index.php'
  184. owner: 'root'
  185. group: 'root'
  186. mode: '0644'
  187. when: with_phpsyscheck|bool
  188. tags:
  189. - 'web'
  190. - 'php'
  191. - name: 'Install PHP APC extension (Debian <= 8)'
  192. apt:
  193. pkg:
  194. - 'php-apc'
  195. state: 'present'
  196. when: with_php_apc|bool and ansible_lsb.major_release|int <= 8
  197. tags:
  198. - 'web'
  199. - 'php'
  200. - name: 'Install PHP APC extension (Debian >= 9)'
  201. apt:
  202. pkg:
  203. - 'php-apcu'
  204. state: 'present'
  205. when: with_php_apc|bool and ansible_lsb.major_release|int >= 9
  206. tags:
  207. - 'web'
  208. - 'php'
  209. - name: 'Install php-apc system check'
  210. template:
  211. src: 'php/apc.php'
  212. dest: '/etc/phpsyscheck/apc.php'
  213. owner: 'root'
  214. group: 'root'
  215. mode: '0644'
  216. when: with_phpsyscheck|bool and with_php_apc|bool
  217. tags:
  218. - 'web'
  219. - 'php'
  220. - name: 'Install MySQL extension for PHP - native driver (Debian 8)'
  221. apt:
  222. pkg:
  223. - 'php5-mysqlnd'
  224. state: 'present'
  225. when: not with_php_mysql_legacy|bool and ansible_lsb.major_release|int == 8
  226. tags:
  227. - 'web'
  228. - 'php'
  229. - name: 'Install MySQL extension for PHP (old driver)'
  230. apt:
  231. pkg: 'php5-mysql'
  232. state: 'present'
  233. when: with_php_mysql_legacy|bool
  234. tags:
  235. - 'web'
  236. - 'php'
  237. - name: 'Install PHPMyAdmin'
  238. apt:
  239. pkg:
  240. - 'phpmyadmin'
  241. state: 'present'
  242. when: with_phpmyadmin|bool
  243. tags:
  244. - 'web'
  245. - 'php'
  246. - name: 'Install PHPPgAdmin'
  247. apt:
  248. pkg:
  249. - 'phppgadmin'
  250. state: 'present'
  251. when: with_phppgadmin|bool
  252. tags:
  253. - 'web'
  254. - 'php'
  255. - name: 'Install FPM for PHP 5 (Debian <= 8)'
  256. apt:
  257. pkg:
  258. - 'php5-fpm'
  259. state: 'present'
  260. when: with_fpm|bool and ansible_lsb.major_release|int <= 8
  261. tags:
  262. - 'web'
  263. - 'php'
  264. - name: 'Install FPM for PHP {{ php_version }} (Debian >= 9)'
  265. apt:
  266. pkg:
  267. - 'php{{ php_version }}-fpm'
  268. state: 'present'
  269. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  270. tags:
  271. - 'web'
  272. - 'php'
  273. - name: 'Configure FPM for PHP 5 (Debian <= 8)'
  274. lineinfile:
  275. dest: '/etc/php5/fpm/php-fpm.conf'
  276. regexp: '^{{ item.key }}\s*=.*$'
  277. line: '{{ item.key }} = {{ item.value }}'
  278. insertafter: '^;{{ item.key }}'
  279. with_items:
  280. - { key: 'error_log', value: 'syslog' }
  281. - { key: 'log_level', value: 'warning' }
  282. - { key: 'emergency_restart_threshold', value: '100' }
  283. - { key: 'emergency_restart_interval', value: '5s' }
  284. - { key: 'rlimit_files', value: '262144' }
  285. - { key: 'events.mechanism', value: 'epoll' }
  286. - { key: 'include', value: '/etc/php5/fpm/pool.d/local-pool.cnf' }
  287. notify:
  288. - 'Reload FPM for PHP 5'
  289. when: with_fpm|bool and ansible_lsb.major_release|int <= 8
  290. tags:
  291. - 'web'
  292. - 'php'
  293. - name: 'Configure FPM for PHP {{ php_version }} (Debian >= 9)'
  294. lineinfile:
  295. dest: '/etc/php/{{ php_version }}/fpm/php-fpm.conf'
  296. regexp: '^{{ item.key }}\s*=.*$'
  297. line: '{{ item.key }} = {{ item.value }}'
  298. insertafter: '^;{{ item.key }}'
  299. with_items:
  300. - { key: 'error_log', value: 'syslog' }
  301. - { key: 'log_level', value: 'warning' }
  302. - { key: 'emergency_restart_threshold', value: '100' }
  303. - { key: 'emergency_restart_interval', value: '5s' }
  304. - { key: 'rlimit_files', value: '262144' }
  305. - { key: 'events.mechanism', value: 'epoll' }
  306. - { key: 'include', value: '/etc/php/{{ php_version }}/fpm/pool.d/local-pool.cnf' }
  307. notify:
  308. - 'Reload FPM for PHP'
  309. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  310. tags:
  311. - 'web'
  312. - 'php'
  313. - name: 'Install FPM pools configuration for PHP 5 (Debian <= 8)'
  314. template:
  315. src: 'fpm/php5-fpm-pools.conf.j2'
  316. dest: '/etc/php5/fpm/pool.d/local-pool.cnf'
  317. owner: 'root'
  318. group: 'root'
  319. mode: '0644'
  320. notify:
  321. - 'Reload FPM for PHP 5'
  322. when: with_fpm|bool and ansible_lsb.major_release|int <= 8
  323. tags:
  324. - 'web'
  325. - 'php'
  326. - name: 'Install FPM pools configuration for PHP {{ php_version }} (Debian > 9)'
  327. template:
  328. src: 'fpm/php-fpm-pools.conf.j2'
  329. dest: '/etc/php/{{ php_version }}/fpm/pool.d/local-pool.cnf'
  330. owner: 'root'
  331. group: 'root'
  332. mode: '0644'
  333. notify:
  334. - 'Reload FPM for PHP'
  335. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  336. tags:
  337. - 'web'
  338. - 'php'
  339. - name: 'Install local PHP configuration overrides for php5-fpm (Debian 8)'
  340. template:
  341. src: 'php/php-config-web.ini.j2'
  342. dest: '/etc/php5/fpm/conf.d/99-local-config.ini'
  343. owner: 'root'
  344. group: 'root'
  345. mode: '0644'
  346. when: with_fpm|bool and ansible_lsb.major_release|int == 8
  347. tags:
  348. - 'web'
  349. - 'php'
  350. - name: 'Install local PHP configuration overrides for php{{ php_version }}-fpm (Debian >= 9)'
  351. template:
  352. src: 'php/php-config-web.ini.j2'
  353. dest: '/etc/php/{{ php_version }}/fpm/conf.d/99-local-config.ini'
  354. owner: 'root'
  355. group: 'root'
  356. mode: '0644'
  357. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  358. tags:
  359. - 'web'
  360. - 'php'
  361. - name: 'Install Apache2 config files for PHP FPM'
  362. template:
  363. src: 'fpm/apache2/fpm-pool.conf.j2'
  364. dest: '/etc/apache2/conf-available/fpm-pool.conf'
  365. owner: 'root'
  366. group: 'root'
  367. mode: '0644'
  368. when: with_fpm|bool and with_apache2|bool
  369. tags:
  370. - 'web'
  371. - 'php'
  372. - name: 'Install Nginx config files for PHP FPM (fpm servers pool)'
  373. template:
  374. src: 'fpm/nginx/fpm-pool.conf.j2'
  375. dest: '/etc/nginx/conf.d/fpm-pool.conf'
  376. owner: 'root'
  377. group: 'root'
  378. mode: '0644'
  379. notify:
  380. - 'Reload nginx'
  381. when: with_fpm|bool and with_nginx|bool
  382. tags:
  383. - 'web'
  384. - 'php'
  385. - name: 'Install Nginx config files for PHP FPM (fpm fastcgi config)'
  386. template:
  387. src: 'fpm/nginx/fastcgi_pass_fpm.j2'
  388. dest: '/etc/nginx/fastcgi_pass_fpm'
  389. owner: 'root'
  390. group: 'root'
  391. mode: '0644'
  392. notify:
  393. - 'Reload nginx'
  394. when: with_fpm|bool and with_nginx|bool
  395. tags:
  396. - 'web'
  397. - 'php'
  398. - name: 'Ensure FPM for PHP 5 is running (Debian <= 8)'
  399. service:
  400. name: 'php5-fpm'
  401. state: 'started'
  402. when: with_fpm|bool and ansible_lsb.major_release|int <= 8
  403. tags:
  404. - 'web'
  405. - 'php'
  406. - name: 'Ensure FPM for PHP {{ php_version }} is running (Debian >= 9)'
  407. service:
  408. name: 'php{{ php_version }}-fpm'
  409. state: 'started'
  410. when: with_fpm|bool and ansible_lsb.major_release|int >= 9
  411. tags:
  412. - 'web'
  413. - 'php'
  414. # vim: ft=yaml.ansible