setup php website with nginx role

This commit is contained in:
2015-09-13 17:44:27 -04:00
parent 50e8b2f41f
commit 8ddae69caf
7 changed files with 107 additions and 1 deletions

View File

@@ -0,0 +1,12 @@
---
# handlers/main.yml
# define handlers here
#- name: restart <service>
# service: name=<service> state=restarted
#- name: stop <service>
# service: name=<service> state=stopped
- name: restart php
service: name=php5-fpm state=restarted

View File

@@ -0,0 +1,30 @@
---
# tasks/main.yml
# define tasks here
# install packages
- name: Ensure dependencies are installed.
apt: pkg={{ item }} state=installed
with_items:
- php5-fpm
# phalcon
- apt_repository: repo='ppa:phalcon/stable' state=present
- apt: pkg=php5-phalcon state=installed update_cache=yes
# config
- name: php.ini setup
lineinfile: dest=/etc/php5/fpm/php.ini line='{{ item.line }}' regexp='{{ item.regexp }}'
with_items:
- { "line":"cgi.fix_pathinfo=0", "regexp":";?cgi.fix_pathinfo=" }
notify:
- restart php
- name: pool.d/www.conf setup
lineinfile: dest=/etc/php5/fpm/pool.d/www.conf line='{{ item.line }}' regexp='{{ item.regexp }}'
with_items:
- { "line":"listen = /var/run/php5-fpm.sock", "regexp":";?listen =" }
notify:
- restart php

View File

@@ -0,0 +1,5 @@
---
# defaults/main.yml
# define default variable values here
server_port: 80

View File

@@ -0,0 +1,7 @@
---
# meta/main.yml
# define dependancies here
dependencies:
- {role: nginx }
- {role: php-fpm}

View File

@@ -0,0 +1,20 @@
---
#setup a named webserver on a host
- name: create symlink
file: state=link src="{{ repo }}" dest="{{ server_root }}"
- name: create nginx vhost
template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/{{ server_hostname }}.conf
notify:
- reload nginx
- name: activate nginx vhost
file: state=link src=/etc/nginx/sites-available/{{ server_hostname }}.conf dest=/etc/nginx/sites-enabled/{{ server_hostname }}.conf
notify:
- reload nginx
- name: update host file
lineinfile: dest=/etc/hosts line='127.0.0.1 {{ server_hostname }}' owner=root group=root mode=0644

View File

@@ -0,0 +1,26 @@
server {
listen {{ server_port }};
server_name {{ server_hostname }};
root {{ server_root }}/public;
access_log /var/log/nginx/{{ server_hostname }}_access.log;
error_log /var/log/nginx/{{ server_hostname }}_error.log;
index index.php index.html
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

View File

@@ -10,3 +10,9 @@
roles: roles:
- jenkins - jenkins
- {
role: website,
server_hostname: "htmlgames.xai-corp.net",
server_root: "/var/www/{{ server_hostname }}",
repo: "/home/richard/Documents/Aptana\ Studio\ 3/xai-corp\ workspace/htmlgames/"
}