AWSのUbuntu18.04LTSにmauticをインストール

最近マーケティングオートメーションなる考え方を勉強していて、
マルケト
SATORI
HUBSPOT
Salesforce Pardot

なんか色々とあるということは理解できたけど、ほとんどが有償でハードルが高いです。
調べていた中でOSS版mauticだとお手軽に勉強できそうだったのでインストールしてみました。ひさびさにPHPのサーバ構築で、FastCGIのところでやや嵌りましたが無事にインストールできました。なのでひとまず備忘録として置いておきます。
この通りの手順でやって損害出るかもなのでコピペして本番運用はしない方がいいかと思います。それなりにセキュリティ対策はしておいてください。環境はAWSのUbuntu18.04+PHP7.2+MariaDBです。PHP7.3でやりたかったんですが、対応してないってことなので泣く泣くPHP7.2です。
あとはゆくゆくのバージョンアップを考えてgit cloneでインストールしてみました。
バージョンアップ、これは今後の課題、それでは以下手順です。

◆作業手順
## ホスト名設定
$ sudo hostnamectl set-hostname mautic_srv

## アップデート
$ sudo apt-get -y update
$ sudo apt-get -y upgrade

## sshセキュア強化
$ sudo vi /etc/ssh/sshd_config
PermitRootLogin no            ←追記

$ sudo service ssh restart

## 日本語化
$ sudo apt-get -y install language-pack-ja
$ sudo update-locale LANG=ja_JP.UTF-8
$ sudo apt-get -y install binutils
$ strings /etc/default/locale
$ sudo apt-get -y install manpages-ja manpages-ja-dev

## timeZone設定
$ sudo ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
$ sudo dpkg-reconfigure --frontend noninteractive tzdata
$ strings /etc/localtime

## ntp
$ sudo apt-get -y install ntp
$ ntpq -p
$ date

## chkrootkitインストール
$ sudo apt-get -y install chkrootkit
$ sudo  chkrootkit | grep INFECTED

## デフォルトエディタ変更
$ sudo update-alternatives --config editor
$ sudo apt-get -y remove nano

## 追加リポジトリ
$ sudo apt-get -y install apt-file

## Fail2Banインストール
$ sudo apt-get -y install fail2ban
$ sudo fail2ban-client status
$ sudo fail2ban-client status sshd

## メール送信設定
$ sudo apt-get -y install postfix sasl2-bin mailutils
$ sudo vi /etc/postfix/main.cf
------------------
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.example.com]:587
------------------

$ sudo vi /etc/postfix/sasl_passwd
---------------------------
[smtp.example.com]:587 id:password
---------------------------

$ sudo chmod 600 /etc/postfix/sasl_passwd
$ sudo postmap hash:/etc/postfix/sasl_passwd
$ sudo systemctl restart postfix
$ echo "test" | mail -s "test" test@example.com

# ubuntuユーザをwww-dataグループに追加
$ sudo usermod -aG www-data ubuntu


## nginxインストール
$ sudo apt-get -y install nginx
$ nginx -v
nginx version: nginx/1.14.0 (Ubuntu)

## SSL証明書設定
# 自己証明書
$ cd /etc/nginx/
$ sudo mkdir ssl
$ cd ssl
$ sudo openssl genrsa -aes128 -out server.key 2048
Enter pass phrase for server.key:test
Verifying - Enter pass phrase for server.key:test
$ sudo openssl rsa -in server.key -out server.key
Enter pass phrase for server.key:test
$ sudo openssl req -new -days 3650 -key server.key -out server.csr
$ sudo openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 36500

## nginx設定
# Basic認証設定
$ sudo apt-get -y install apache2-utils
$ sudo htpasswd -c /etc/nginx/.htpasswd user
New password: password
Re-type new password: password

# 設定ファイル修正
$ sudo vi /etc/nginx/nginx.conf
---------
http {
        ##
        # Basic Settings
        ##
          server_tokens off;   ←追記
   keepalive_timeout 160;  ←修正


$ sudo vi /etc/nginx/conf.d/mautic.conf
---------
upstream phpfpm{
  server unix:/var/run/php/php7.2-fpm.sock;
}

server {
        listen 80; # httpへのアクセスをhttpsへリダイレクトする
        listen [::]:80;
        server_name  servername;

        if ($http_x_forwarded_proto != https) {
            return 301 https://$host$request_uri;
        }
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl on;
    server_name  servername;
    root /var/www/mautic;
    index  index.html index.htm index.php;
    client_max_body_size 128M;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_session_timeout 5m;
    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_prefer_server_ciphers on;
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains" always;

    location / {
        #root /var/www/mautic;
        index  index.php;
        auth_basic "Please Input ID and Password";
        auth_basic_user_file /etc/nginx/.htpasswd;
        try_files $uri $uri/ /index.php?$query_string;
    }

    # Deny access to any files with a .php extension in the uploads directory
    location ~* /(?:uploads|files)/.*\.php$ {
            deny all;
    }

    # Solve email tracking pixel not found
    location ~ email/(.*).gif {
        try_files $uri /index.php?$args;
    }
    # Solve JS Loading 404 Error
    location ~ (.*).js {
        try_files $uri /index.php?$args;
    }

    location ~* \.(jpg|jpeg|gif|png|css|js|ico)$ {
        access_log        off;
        log_not_found     off;
        expires           8d;
    }

    # Don't output hidden files
    location ~ /\. {
        return 404;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass phpfpm;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 16k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }
}
---------


## PHP7.2インストール
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get -y install php7.2-fpm php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-zip php7.2-cur php7.2-bcmath
$ php -v

# PHP.ini編集
$ sudo vi /etc/php/7.2/fpm/php.ini
memory_limitを書き替え
---------------------------
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 256M
---------------------------

#Composerインストール
$ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer
Downloading...

Composer (version 1.8.6) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

#RabbitMQインストール
$ sudo apt -y install rabbitmq-server


## MariaDBインストール
$ sudo apt-get -y install mariadb-server

# 文字コード設定
$ sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf
以下2行の通りutf8に変更
---------------------------
 character-set-server = utf8
 collation-server = utf8_general_ci
---------------------------

$ sudo vi /etc/mysql/mariadb.conf.d/50-client.cnf
以下の通りutf8に変更
---------------------------
 default-character-set = utf8
---------------------------

$ sudo vi /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf
---------------------------
default-character-set = utf8 
---------------------------


## MariaDB初期設定
$ sudo mysql_secure_installation

# パスワード設定(空白にしない) 
Enter current password for root (enter for none):
Change the root password? [Y/n] Y
New password:password
Re-enter new password:password

# 匿名ユーザ削除
Remove anonymous users? [Y/n] Y

# rootリモートログイン禁止 
Disallow root login remotely? [Y/n] Y

# テストデータベース削除 
Remove test database and access to it? [Y/n] Y

# 特権情報リロード 
Reload privilege tables now? [Y/n] Y

# MariaDB再起動
$ sudo service mysqld restart

# 接続確認
$ mysql --version
$ sudo mysql -u root -p

MariaDB [(none)]> show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

# Mautic用データベース作成
MariaDB [(none)]> create database mautic;
MariaDB [(none)]> select user from mysql.user where user='mautic';
MariaDB [(none)]> grant all privileges on mautic.* to mautic@localhost identified by 'password';
MariaDB [(none)]> exit
$ sudo mysql -u mautic -p
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mautic             |
+--------------------+
MariaDB [(none)]> exit


#Mauticインストール(gitしてからcomposer)
$ sudo git clone https://github.com/mautic/mautic.git
$ cd mautic/
$ sudo composer self-update
$ sudo composer install
$ sudo git checkout master

## ログ類初期化
$ sudo find /var/log/ -type f -name \* -exec cp -f /dev/null {} \;
$ history -c


◆参照URL
・インストール
https://qiita.com/mochizukikotaro/items/432816520ccf34e9a418
https://concrete5.co.jp/blog/install-mautic-on-aws-ec2
https://4649-24.com/mautic/
https://websiteforstudents.com/install-mautic-on-ubuntu-16-04-18-04-with-apache2-mariadb-and-php-7-1/
https://qiita.com/katzueno/items/51d6c40f6e8f1b3efe58
https://www.linuxbabe.com/ubuntu/install-mautic-onubuntu-16-04-marketing-automation-software

・mautic設定
https://concrete5.co.jp/blog/mautic-blank-jp-mautic
https://webloco.webolha.com/websuccess/2018/01/25/mautic-on-premise-2018/
https://www.dreampockets.com/2018/08/%E3%80%90mautic%E3%80%91%E7%AE%A1%E7%90%86%E7%94%BB%E9%9D%A2%E3%81%AE%E6%97%A5%E6%9C%AC%E8%AA%9E%E5%8C%96%E3%81%AE%E6%89%8B%E9%A0%86/

とりあえずインストールは何とかできたので、これをどう使うかですね。
なんかいろいろできそうなので試してみたいと思います。
あと、システム連携とかどうするのかなぁ。色々と調べながらやっていこうと思います。

コメント

このブログの人気の投稿

証券外務員1種勉強(計算式暗記用メモ)

GASでGoogleDriveのサブフォルダとファイル一覧を出力する

マクロ経済学(IS-LM分析)