This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
blog/_posts/2022-11-05-monica.md
2023-06-03 15:58:09 +08:00

162 lines
6.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
layout : post
title : "私人CRM管理"
subtitle : "I Love Monica"
date : 2022-11-05 11:51:37
author : "Manford Fan"
catalog : false
header-img : "img/post-bg-universe.jpg"
tags :
- Monica
- CRM
- Server
---
> ***Personal CRM. Remember everything about your friends, family and business relationships.***
Monica允许人们持续追踪记录他们生活中重要的人事物或者具有纪念意义的瞬间或者曾经的活动等等。它会帮你记住你什么时候和他打了最后一次电话帮你记住你朋友的名字年龄以及他们孩子的出生日期即使你们非常久没有联系了。开发者说这个项目是为那些记忆力不怎么样的人准备的我想他可能是在说我。
## 一、服务部署
在项目开发页作者提供了三种使用Monica的方式
- 直接使用他们的服务,这是最简单的方式
- 在自己的服务器上部署,提供了原生部署与服务部署
- 通过PaaS platform部署高科技
一如既往我还是选择了最原始的原生服务器部署比较惊喜的是开发者的部署实例中有以Debian系统做了演示并且提供了非常详细的部署过程非常NICE
#### 1. 必要环境
Monica是一个综合性的后台应用界面也是典型的现代风格需要很多其他组件的支撑这也是在安装部署服务之前必须要满足的环境条件。
- git下载源码
- php 8.1Monica的主要环境
- Composer
- Node.js
- Yarn
- MySQL
- Nginx/Apache
如下是必要环境部署的一些命令有些是作为环境依赖有些还需要自己配置构建比如创建一个空的数据库以备后用配置Nginx反向代理修改php8.1的内存限制等,数据库的初始化可以参考[MySQL基础篇](https://blog.rustle.cc/2022/06/18/sql_basic/)这篇文章。
```bash
# install php8.1
sudo apt install -y curl software-properties-common
curl -sSL https://packages.sury.org/php/apt.gpg | sudo tee /etc/apt/trusted.gpg.d/php-sury.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php-sury.list
apt update
apt install -y php8.1 php8.1-bcmath php8.1-curl php8.1-gd php8.1-gmp \
php8.1-intl php8.1-mbstring php8.1-mysql php8.1-redis php8.1-xml php8.1-zip
# install composer
curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
# install node
curl -sSL https://deb.nodesource.com/setup_16.x | bash -
apt install -y nodejs
# install yarn & mariadb & nginx
npm install --global yarn
apt install -y mariadb-server
apt install nginx
```
#### 2. 部署过程
Monica在Debian上部署的全部过程均可参考官方给出[文档](https://github.com/monicahq/monica/blob/main/docs/installation/providers/debian.md),非常详细的描述了如下`5`个步骤:
1. 将项目克隆到本地网站空间
2. 准备数据库,可参考[MySQL基础篇](https://blog.rustle.cc/2022/06/18/sql_basic/)
3. 配置Monica这是最重要的一个环节有很多需要做的
* 执行`cp .env.example .env`来创建自己的环境文件,并根据情况修改如下
- 设定`DB_USERNAME``DB_PASSWORD`变量
- 配置邮件服务器
-`APP_ENV`变量设置成`production`这将强制https
* 运行`composer install --no-interaction --no-dev`安装所有的包
* 运行`yarn install`安装前端所需要的包,并通过`yarn run production`命令进行构建
* 运行`php artisan key:generate`生成的值会被写进环境文件的`APP_KEY`变量
* 运行`php artisan setup:production -v`做最后的数据库初始化等操作
> 可以通过`php artisan setup:production --email=your@email.com --password=yourpassword -v`来设定初始账号密码
#### 3. 反代优化
部署完成之后使用Nginx反向代理源码自带了一个Ngxin的反向代理模板文件`nginx_app.conf`,但是直接用会报错,需要修改一下。
```nginx
server {
server_name monica.rustle.cc;
listen [::]:54442;
listen 54442;
listen [::]:443 ssl http2;
listen 443 ssl http2;
charset utf-8;
access_log logs/monica.access.log main;
if ($scheme = http) {
return 302 https://$host$request_uri;
}
root /opt/source-code/monica/public;
index index.php;
location / {
# try to serve file directly, fallback to rewrite
try_files $uri @rewriteapp;
}
location @rewriteapp {
# Redirect .well-known urls (https://en.wikipedia.org/wiki/List_of_/.well-known/_services_offered_by_webservers)
rewrite .well-known/carddav /dav/ permanent;
rewrite .well-known/caldav /dav/ permanent;
rewrite .well-known/security.txt$ /security.txt permanent;
# Old carddav url
rewrite carddav/(.*) /dav/$1 permanent;
# rewrite all to app.php
# rewrite ^(.*)$ /index.php/$1 last;
rewrite ^(.*)$ /index.php last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
try_files @heroku-fcgi @heroku-fcgi;
internal;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php?$args;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
include fastcgi_params;
}
}
```
另外Monica还需要一些后台进程持续的运行基本上是一些发送邮件提醒以及检查版本是否需要更新的信息。所以需要以`www-data`的身份运行`cron`服务还有就是要把Monica文件夹及其所有的子目录和子文件的所属信息修改为`www-data`至此Monica的部署全部完成可以访问域名开启使用模式。
```bash
crontab -u www-data -e
* * * * * php /var/www/monica/artisan schedule:run >> /dev/null 2>&1
chown -R www-data:www-data /var/www/monica
chmod -R 775 /var/www/monica/storage
```
## 二、常用功能
其实Monica就是一个关系管理软件帮助记忆力不太好的人记录一些事情或者主动的记录一些重要的有纪念意义的事情。该应用整体风格相当简洁功能栏也只有仪表盘联系人以及日记比较常用的功能有...... 没得选,联系人和日记都是比较常用的,
![monica](/img/posts/monica.png 'monica')
## 三、参考文档
- [Monica Github](https://github.com/monicahq/monica)