DevOps

How to deploy CI/CD compatible and production ready web-service

Contents:

 - New project files deployment on server
 - Nginx settings for new project
 - Supervisor fix

New project files deployment on server manual

PROJECT_NAME=your project name

sudo mkdir /var/www/PROJECT_NAME
sudo chmod 755 -R /var/www/PROJECT_NAME

cd /var/www/PROJECT_NAME
git clone git@gitlab.site.ru:company/PROJECT_NAME.git

mv PROJECT_NAME html

cd html

composer update

cp .env.example .env

- Create new DB and write her in to .env file

mv /var/www/PROJECT_NAME/html/.env /var/www/PROJECT_NAME/.env
ln -s /var/www/PROJECT_NAME/.env /var/www/PROJECT_NAME/html/.env

- next if your App already adapted for outer storage watching

mv /var/www/PROJECT_NAME/html/storage /var/www/PROJECT_NAME/storage
php artisan migrate
php artisan tenancy:customer:create my_new_customer
sudo chown www-data -R /var/www/PROJECT_NAME/storage/logs/
sudo chown www-data -R /var/www/PROJECT_NAME/storage/framework/cache/
sudo chown www-data -R /var/www/PROJECT_NAME/storage/framework/views/ #(not sudo chmod 755 -R /var/www/PROJECT_NAME/storage/)
ln -s /var/www/customers /var/www/PROJECT_NAME/html/customers

Nginx settings for new project

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/PROJECT_NAME
sudo nano /etc/nginx/sites-available/PROJECT_NAME

- edit your new file as this:

server {
    listen 80;
    listen [::]:80;

    server_name PROJECT_NAME.ru;
    root /var/www/PROJECT_NAME/www/public;

    index index.php index.html;

    try_files $uri $uri/ /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
sudo ln -s /etc/nginx/sites-available/PROJECT_NAME /etc/nginx/sites-enabled/PROJECT_NAME

sudo nginx -t
sudo systemctl reload nginx


- Config your DNS server:
 Main -> Domain names -> Your domain name -> Records -> Create -> 
  Name  -> Your domain name
  Type     -> A
  IP-adress -> Your IP adress

- (optional) Edit hosts file on Your working machine (only if your DNS still not configured):
 open C:\Windows\System32\drivers\etc\hosts

11.22.33.44 PROJECT_NAME.ru

Supervisor fix

cd /var/www/PROJECT_NAME

mkdir supervisor
mkdir /var/www/PROJECT_NAME/storage/logs/supervisor-logs
cd supervisor

touch PROJECT_NAME-worker.conf
sudo nano PROJECT_NAME-worker.conf


- write new supervisor worker configuration as it:

[program:PROJECT_NAME_slow]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /var/www/PROJECT_NAME/html/artisan queue:listen database --timeout=0 --queue=slow --tries=1 --memory=768 --sleep=3
autostart=true
autorestart=true
user=www-data
group=www-data
numprocs=2
redirect_stderr=true
stderr_logfile=/var/www/PROJECT_NAME/storage/logs/supervisor-logs/error.log
stdout_logfile=/var/www/PROJECT_NAME/storage/logs/supervisor-logs/worker.log
sudo ln -s /var/www/PROJECT_NAME/supervisor/PROJECT_NAME-worker.conf /etc/supervisor/conf.d/PROJECT_NAME-worker.conf 
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start all
sudo supervisorctl status
How To Install "supervisor" Package on Ubuntu
Step 1
sudo apt-get update -y​
Step 2
sudo apt-get install -y supervisor
Афоризм дня:
Мир есть не отсутствие войны, но добродетель, проистекающая из твердости духа. (556)

Leave a reply

Яндекс.Метрика