From e55018a496a7381fd9fe92845ef526e1edd965ae Mon Sep 17 00:00:00 2001 From: danielcristho Date: Fri, 19 Apr 2024 19:23:59 +0700 Subject: [PATCH] feat: add new project --- ansible-laravel-with-swoole/ansible.cfg | 0 ansible-laravel-with-swoole/handlers/main.yml | 0 ansible-laravel-with-swoole/playbook.yml | 7 ++++ ansible-laravel-with-swoole/tasks/main.yml | 37 +++++++++++++++++++ .../templates/nginx.j2 | 28 ++++++++++++++ ansible-laravel-with-swoole/templates/sail.j2 | 4 ++ .../templates/supervisor.j2 | 16 ++++++++ 7 files changed, 92 insertions(+) create mode 100644 ansible-laravel-with-swoole/ansible.cfg create mode 100644 ansible-laravel-with-swoole/handlers/main.yml create mode 100644 ansible-laravel-with-swoole/playbook.yml create mode 100644 ansible-laravel-with-swoole/tasks/main.yml create mode 100644 ansible-laravel-with-swoole/templates/nginx.j2 create mode 100644 ansible-laravel-with-swoole/templates/sail.j2 create mode 100644 ansible-laravel-with-swoole/templates/supervisor.j2 diff --git a/ansible-laravel-with-swoole/ansible.cfg b/ansible-laravel-with-swoole/ansible.cfg new file mode 100644 index 0000000..e69de29 diff --git a/ansible-laravel-with-swoole/handlers/main.yml b/ansible-laravel-with-swoole/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/ansible-laravel-with-swoole/playbook.yml b/ansible-laravel-with-swoole/playbook.yml new file mode 100644 index 0000000..e3172c1 --- /dev/null +++ b/ansible-laravel-with-swoole/playbook.yml @@ -0,0 +1,7 @@ +--- +- name: Deploy Laravel App Using Swoole Runtime + hosts: all + become: true + remote_user: root + roles: + - config \ No newline at end of file diff --git a/ansible-laravel-with-swoole/tasks/main.yml b/ansible-laravel-with-swoole/tasks/main.yml new file mode 100644 index 0000000..47ae6d8 --- /dev/null +++ b/ansible-laravel-with-swoole/tasks/main.yml @@ -0,0 +1,37 @@ +--- +- name: Add PHP repository + ansible.builtin.apt_repository: + repo: "ppa:ondrej/php" + state: present + +- name: Install PHP 8.2 & dependencies + ansible.builtin.apt: + name: + - php8.2-mysql + - php8.2-fpm + - php8.2-mbstring + - php8.2-xml + - php8.2-bcmath + - php8.2-curl + - php8.2-cli + - php8.2-common + - php8.2-zip + - php8.2-gd + - php8.2-swoole + - php8.2-soap + state: present + update_cache: true + +- name: Add sail config + ansible.builtin.template: + src: sail.j2 + dest: /etc/php/8.2/cli/conf.d/99-sail.ini + mode: preserve + +- name: Add supervisor config + ansible.builtin.template: + src: supervisor.j2 + dest: /etc/supervisor/conf.d/laravel.conf + mode: preserve + + diff --git a/ansible-laravel-with-swoole/templates/nginx.j2 b/ansible-laravel-with-swoole/templates/nginx.j2 new file mode 100644 index 0000000..d195eba --- /dev/null +++ b/ansible-laravel-with-swoole/templates/nginx.j2 @@ -0,0 +1,28 @@ +server { + listen 80; + server_name yourdomain.com; + root /var/www/public; + + # CORS Config + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' '*' always; + add_header 'Access-Control-Allow-Headers' '*' always; + + index index.html index.htm index.php; + error_page 404 /index.php; + location / { + proxy_pass http://127.0.0.1:8089; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + + location ~ /\.ht { + deny all; + } + + error_log /var/log/nginx/athena_error.log; + access_log /var/log/nginx/athena_access.log; +} \ No newline at end of file diff --git a/ansible-laravel-with-swoole/templates/sail.j2 b/ansible-laravel-with-swoole/templates/sail.j2 new file mode 100644 index 0000000..4d70973 --- /dev/null +++ b/ansible-laravel-with-swoole/templates/sail.j2 @@ -0,0 +1,4 @@ +[PHP] +post_max_size = 100M +upload_max_filesize = 100M +variables_order = EGPCS \ No newline at end of file diff --git a/ansible-laravel-with-swoole/templates/supervisor.j2 b/ansible-laravel-with-swoole/templates/supervisor.j2 new file mode 100644 index 0000000..650e93d --- /dev/null +++ b/ansible-laravel-with-swoole/templates/supervisor.j2 @@ -0,0 +1,16 @@ +program:laravel-octane-worker] +process_name=%(program_name)s_%(process_num)02d +command=php -d variables_order=EGPCS /var/www/laravel/artisan octane:start --server=swoole --max-requests=1000 --workers=4 --task-workers=12 --port=8089 +autostart=true +autorestart=true +user=www-data +redirect_stderr=true +stdout_logfile=/var/www/laravel/storage/logs/swoole_http.log +stopwaitsecs=3600 +environment=LARAVEL_SAIL="1" + +[supervisord] +nodaemon=true +user=root +logfile=/var/log/supervisor/supervisord.log +pidfile=/var/run/supervisord.pid \ No newline at end of file