系统环境
- 系统:Linux CentOS 7.9
- 安装宝塔面板并安装 Nginx1.18、MySql5.7、PHP7.4
- 必要 PHP 扩展:imap、intl、zip、xml、mcrypt、mailparse
- 必要 PHP 函数:
putenv、imap_open
注意:数据库一定要 MySQL >= 5.7版本
1、安装宝塔
参考官网安装教程:https://www.bt.cn/new/download.html
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec
2、宝塔安装PHP7.4 (【宝塔Linux】php7.4 安装 zip 扩展)
PHP7.4的安装路径为:/www/server/php/74
新建快捷方式:
ln -sf /www/server/php/74/bin/php /usr/local/bin/php ln -sf /www/server/php/74/bin/phpize /usr/local/bin/phpize ln -sf /www/server/php/74/bin/php-config /usr/local/bin/php-config ln -sf /www/server/php/74/bin/composer /usr/local/bin/composer
3、配置PHP7.4
- 必要 PHP 扩展:imap、intl、zip、xml、mcrypt、mailparse、fileinfo
- 必要 PHP 函数:
putenv、imap_open
4、安装PHP扩展:zip
(1) 安装libzip
先删除旧版本 yum remove zip #下载编译安装 wget https://nih.at/libzip/libzip-1.2.0.tar.gz tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make && make install
安装完成后,查看是否存在/usr/local/lib/pkgconfig目录,如果存在,执行如下命令来设置PKG_CONFIG_PATH:
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
(2) 安装ZipArchive
cd /www/server/php/74/src/ext/zip /www/server/php/74/bin/phpize ./configure --with-php-config=/www/server/php/74/bin/php-config make && make install echo "extension = zip.so" >> /www/server/php/74/etc/php.ini echo "extension = zip.so" >> /www/server/php/74/etc/php-cli.ini # 注意:现在的PHP命令行模式,有自己单独的配置文件
(3) 重启php
5、配置PHP参数
upload_max_filesize 300M post_max_size 350M memory_limit 400M max_execution_time 600 max_input_time 600
6、安装依赖包
chown -R www:www /www/wwwroot/mautic.xxx.com cd /www/wwwroot/mautic.xxx.com su www composer install
7、在宝塔后台,提交新建“空”数据库
安装步骤
1、配置站点
在宝塔后台添加站点、数据库、域名,然后添加 Nginx伪静态规则:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
2、然后下载 Mautic 安装包,上传到网站根目录解压。
下载地址:https://github.com/mautic/mautic/tags
3、添加计划任务
/usr/bin/php /www/wwwroot/mautic.xxx.com/bin/console mautic:segments:update /usr/bin/php /www/wwwroot/mautic.xxx.com/bin/console mautic:campaigns:update /usr/bin/php /www/wwwroot/mautic.xxx.com/bin/console mautic:campaigns:trigger /usr/bin/php /www/wwwroot/mautic.xxx.com/bin/console mautic:emails:send /usr/bin/php /www/wwwroot/mautic.xxx.com/bin/console mautic:email:fetch /usr/bin/php /www/wwwroot/mautic.xxx.com/bin/console mautic:social:monitoring /usr/bin/php /www/wwwroot/mautic.xxx.com/bin/console mautic:webhooks:process # 下载IP地址 /www/server/php/74/bin/php /www/wwwroot/mautic.woyoalliance.com/bin/console mautic:iplookup:download
根据上面官方给出的 N 条计划任务,我们可以手动在宝塔面板后台手动添加计划任务 Shell 脚本(* * * * 表示每分钟执行 1 次)可以看下面我给出的宝塔计划任务截图。

4、Mautic 安装完成以后,需要登录 Mautic 后台更新 GeoIP 数据库,下面给出一个官方的教程地址,自行根据官方教程去注册获取 IP 数据库的授权秘钥。
官方教程地址:https://docs.mautic.org/en/setup/maxmind-license
下面给出一个 Mautic 后台更新 GeoIP 数据库成功的截图:
注意:把账号和密码用“:”分隔 填入即可,如:官方给的账号信息
Account ID
518888
License key
X5N0BHuYSsW6DPa1

5、跟踪代码不能使用
在布署了Mautic的跟踪代码的时候,加载404报错,或不能发送数据,这些也都是因为伪静态没设置好。
添加如下代码:
location ~ /mtc.js {
default_type "application/javascript";
try_files $uri /index.php$is_args$args;
}
location ~ /mtracking.gif {
default_type "application/javascript";
try_files $uri /index.php$is_args$args;
}
location ~ /mtc/event {
default_type "application/javascript";
try_files $uri /index.php$is_args$args;
}
参考:
- 如何安装Mautic? 搭建一套免费的自动营销系统-Mautic开源自动营销系统实践(1)
- Mautic使用手册1: centos7 http部署 + 编译php 整合+ mautic 部署
- 使用Mautic的几个坑
- 宝塔面板 LNMP 环境下 Mautic 3.X 最新版开源 EDM 邮件行销系统安装教程
- 宝塔面板php7.3&7.4版本不支持ZipArchive手工安装扩展方法
另外一份Nginx配置
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
# redirect some entire folders
rewrite ^/(vendor|translations|build)/.* /index.php break;
# Deny everything else in /app folder except Assets folder in bundles
location ~ /app/bundles/.*/Assets/ {
allow all;
access_log off;
}
location ~ /app/ { deny all; }
# Deny everything else in /addons or /plugins folder except Assets folder in bundles
location ~ /(addons|plugins)/.*/Assets/ {
allow all;
access_log off;
}
# location ~ /(addons|plugins)/ { deny all; }
# Deny all php files in themes folder
location ~* ^/themes/(.*)\.php {
deny all;
}
# Don't log favicon
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Don't log robots
location = /robots.txt {
access_log off;
log_not_found off;
}
# Deny yml, twig, markdown, init file access
location ~* /(.*)\.(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
deny all;
access_log off;
log_not_found off;
}
# Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc...
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# Deny all grunt, composer files
location ~* (Gruntfile|package|composer)\.(js|json)$ {
deny all;
access_log off;
log_not_found off;
}
# Deny access to any files with a .php extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# A long browser cache lifetime can speed up repeat visits to your page ,有些统计功能是.gif后置,需求去掉这个拦截
#location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml|js)$ {
location ~* \.(webp|svg|woff|woff2|ttf|css|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
摘自:在Ubuntu 18.04服务器上安装Mautic的方法
Win10下,安装Composer报错
运行:
composer install
时,报错:
SymfonyComponentDebugExceptionFatalThrowableError : Return value of SymfonyComponentProcessProcess::close() must be of the type integer, null returned
解决方案:
1、修改PHP配置文件php.ini,找到 disable_functions 字段,删除 proc_get_status、proc_open、reallink 函数。
2、设置 sys_temp_dir 选项,如:
sys_temp_dir = "d:\software\BtSoft\temp_sys\"
参考:
工作中的备份
1. Nginx配置
server
{
listen 80;
listen 443 ssl http2;
server_name mautic.xxx.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/mautic.xxx.com;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
ssl_certificate /www/server/panel/vhost/cert/mautic.xxx.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/mautic.xxx.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-74.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/mautic.xxx.com.conf;
#REWRITE-END
#禁止访问的文件或目录
#location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
#{
# return 404;
#}
#一键申请SSL证书验证目录相关设置
#location ~ ^/.well-known/{
# allow all;
#}
#禁止在证书验证目录放入敏感文件
#if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
#return 403;
#}
access_log /dev/null;
error_log /www/wwwlogs/test-mautic.xxx.com.error.log;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
# redirect some entire folders
rewrite ^/(vendor|translations|build)/.* /index.php break;
# Deny everything else in /app folder except Assets folder in bundles
location ~ /app/bundles/.*/Assets/ {
allow all;
access_log off;
}
location ~ /app/ { deny all; }
# Deny everything else in /addons or /plugins folder except Assets folder in bundles
location ~ /(addons|plugins)/.*/Assets/ {
allow all;
access_log off;
}
location ~ /(addons|plugins)/ { deny all; }
# Deny all php files in themes folder
location ~* ^/themes/(.*)\.php {
deny all;
}
# Don't log favicon
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Don't log robots
location = /robots.txt {
access_log off;
log_not_found off;
}
# Deny yml, twig, markdown, init file access
location ~* /(.*)\.(?:markdown|md|twig|yaml|yml|ht|htaccess|ini)$ {
deny all;
access_log off;
log_not_found off;
}
# Deny all attempts to access hidden files/folders such as .htaccess, .htpasswd, .DS_Store (Mac), etc...
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# Deny all grunt, composer files
location ~* (Gruntfile|package|composer)\.(js|json)$ {
deny all;
access_log off;
log_not_found off;
}
# Deny access to any files with a .php extension in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# A long browser cache lifetime can speed up repeat visits to your page
#location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml|js)$ {
location ~* \.(webp|svg|woff|woff2|ttf|css|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
}
2.定时任务
任务名称:【Mautic自动营销系统】计划任务
执行周期:N分钟/5分钟
脚本内容:
/www/server/php/74/bin/php /www/wwwroot/mautic.woyoalliance.com/bin/console mautic:segments:update /www/server/php/74/bin/php /www/wwwroot/mautic.woyoalliance.com/bin/console mautic:campaigns:update /www/server/php/74/bin/php /www/wwwroot/mautic.woyoalliance.com/bin/console mautic:campaigns:trigger /www/server/php/74/bin/php /www/wwwroot/mautic.woyoalliance.com/bin/console mautic:emails:send /www/server/php/74/bin/php /www/wwwroot/mautic.woyoalliance.com/bin/console mautic:email:fetch /www/server/php/74/bin/php /www/wwwroot/mautic.woyoalliance.com/bin/console mautic:social:monitoring /www/server/php/74/bin/php /www/wwwroot/mautic.woyoalliance.com/bin/console mautic:webhooks:process