php.yml 11 KB

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