Cách cài đặt Matic trong ngnix và MariaDB

Cài đặt Nginx HTTP Server

sudo apt update
sudo apt install nginx

Ngnix start khi server khởi động

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Cài đặt MariaDb mới nhất với repository configuration tool

sudo apt-get install software-properties-common
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu bionic main'
sudo apt update

Importing MariaDB GPG Public Key

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db

Update MariaDB và cài đặt

sudo apt update
sudo apt-get install mariadb-server galera-4 mariadb-client libmariadb3 mariadb-backup mariadb-common

Cài đặt để MariaDb start khi hệ thống start

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Cài đặt bảo mật và tạo database

sudo mysql_secure_installation

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y


https://congthoidai.com/cho-phep-ket-noi-den-mysql-tu-xa/

Cài đặt PHP 7.4 và các gói liên quan

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

sudo apt install php7.4-fpm php7.4-common php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-mysql php7.4-bcmath php7.4-gd php7.4-xml php7.4-cli php7.4-zip

Chỉnh sửa cấu hình của PHP

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = Asia/Ho_Chi_Minh

Khỏi động lại ngnix

sudo systemctl restart nginx.service

Download git, và mautic phiên bản mới nhất và cấu hình permision

sudo apt install curl git
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
cd /var/www/html
sudo git clone https://github.com/mautic/mautic.git
cd /var/www/html/mautic
sudo composer install
sudo chown -R www-data:www-data /var/www/html/mautic/
sudo chmod -R 755 /var/www/html/mautic/

Cấu hình mautic trên ngnix

sudo nano /etc/nginx/sites-available/mautic

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/mautic;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;

     client_max_body_size 100M;

    location / {
        try_files $uri /index.php$is_args$args;       
    }

    location ~ \.php$ {
               include snippets/fastcgi-php.conf;
               fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
    }
}

Copy cấu hình đó vào ngnix

sudo ln -s /etc/nginx/sites-available/mautic /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Cấu hình SSL cho mautic

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    root /var/www/html/mautic;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;

    ssl_certificate     www.example.com.crt;
    ssl_certificate_key www.example.com.key;

     client_max_body_size 100M;

    location / {
        try_files $uri /index.php$is_args$args;       
    }

    location ~ \.php$ {
               include snippets/fastcgi-php.conf;
               fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
    }
}

Note: www.example.com.crt là certificate và root Certificates

cat your_domain.crt intermediate.crt root.crt >> ssl-bundle.crt
 
Hoặc 

cat your_domain.crt your_domain.ca-bundle >> ssl-bundle.crt

Chúc các bạn thành công