diff --git a/roles/configure-nginx/files/vhost.conf.j2 b/roles/configure-nginx/files/vhost.conf.j2 new file mode 100644 index 0000000..446eeea --- /dev/null +++ b/roles/configure-nginx/files/vhost.conf.j2 @@ -0,0 +1,39 @@ +map $sent_http_content_type $expires { + default off; + text/html epoch; + text/css max; + application/javascript max; + ~image/ max; +} + +server { + root /var/www/{{ vhost_name }}; + index index.php index.html index.htm; + server_name {{ domain }}; + listen 80; + + expires $expires; + client_max_body_size 50M; + + autoindex off; + + location / { + try_files $uri $uri/ @handler; + } + + location /admin { + try_files $uri $uri/ /admin/index.php?$args; + } + + location @handler { + if (!-e $request_filename) { rewrite / /index.php last; } + rewrite ^(.*.php)/ $1 last; + } + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass unix:/var/run/php/php{{ php_version }}-fpm.sock; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} \ No newline at end of file diff --git a/roles/configure-nginx/tasks/main.yml b/roles/configure-nginx/tasks/main.yml index eadcf99..7d02947 100644 --- a/roles/configure-nginx/tasks/main.yml +++ b/roles/configure-nginx/tasks/main.yml @@ -1,7 +1,13 @@ --- +- name: Create wwwroot + file: + path: /var/www/{{ vhost_name }} + state: directory + mode: '0755' + - name: Prepare config file - copy: - src: files/web-{{ vhost_name }}.conf + template: + src: files/vhost.conf.j2 dest: /etc/nginx/sites-available/web-{{ vhost_name }}.conf - name: Create a symbolic link diff --git a/roles/configure-php/tasks/main.yml b/roles/configure-php/tasks/main.yml index 05a6ff3..57e35e6 100644 --- a/roles/configure-php/tasks/main.yml +++ b/roles/configure-php/tasks/main.yml @@ -28,7 +28,7 @@ - name: Start PHP systemd: - name: "{{ item }}" + name: "php{{ php_version }}-fpm" daemon_reload: yes enabled: yes state: started diff --git a/roles/install-wordpress/main.yml b/roles/install-wordpress/main.yml new file mode 100644 index 0000000..04e6944 --- /dev/null +++ b/roles/install-wordpress/main.yml @@ -0,0 +1,17 @@ +--- +- name: Download latest WP + get_url: + url: https://wordpress.org/latest.zip + dest: /var/www/{{ vhost_name }} + mode: '0660' + +- name: Extract wordpress + unarchive: + src: /var/www/{{ vhost_name }}/latest.zip + dest: /var/www/{{ vhost_name }} + remote_src: yes + +- name: Delete the wordpress zip + file: + state: absent + path: /var/www/{{ vhost_name }}/latest.zip \ No newline at end of file diff --git a/setup_server.yml b/setup_server.yml index b10eedf..fbf49e4 100644 --- a/setup_server.yml +++ b/setup_server.yml @@ -11,3 +11,4 @@ - role: configure-nginx - role: install-php - role: configure-php + - role: install-wordpress \ No newline at end of file diff --git a/vars/external.yml b/vars/external.yml index 944e368..b31ecb6 100644 --- a/vars/external.yml +++ b/vars/external.yml @@ -1,4 +1,5 @@ --- php_version: 8.1 -password: magic -vhost_name: projectwp \ No newline at end of file +vhost_name: projectwp +domain: projectwp.com +db_pwd: 123456 \ No newline at end of file