How to Install Monica Personal CRM on Debian 12

Conventionally, Customer Relationship Management (CRM) software is made for businesses to manage their customers. CRM software helps businesses to gather data from customers and provide assistance via various means of communication.

Monica Personal CRM, however, is aimed at individuals and their personal relationships with their family and friends. Monica CRM helps in organizing and storing everything that there is to about the people around you. It is open-source and completely free to use. It is written using the Laravel PHP web framework.

In this tutorial, you will learn how to install Monica Personal CRM on a Debian 12 server.

Prerequisites

  • A server running Debian 12 with a minimum of 1.5 GB of RAM. If your server has less than 1.5 GB of RAM, the Yarn installation tasks will most likely fail. Upgrade to a server with better RAM before proceeding with this tutorial to ensure a smooth installation.

  • A non-root user with sudo privileges.

  • Uncomplicated Firewall(UFW) is enabled and running.

  • A Fully Qualified Domain Name (FQDN) like monica.example.com pointing to your server.

  • An SMTP account with an email service like Amazon SES or Mailgun.

  • Everything is updated.

    $ sudo apt update && sudo apt upgrade
    
  • A few essential packages are required for the tutorial and Monica CRM to run. Some of these will already be on your server.

    $ sudo apt install curl wget nano software-properties-common dirmngr apt-transport-https ca-certificates lsb-release debian-archive-keyring gnupg2 ufw unzip -y
    

Step 1 - Configure Firewall

The first step before installing any packages is to configure the firewall to allow HTTP and HTTPS connections.

Check the status of the firewall.

$ sudo ufw status

You should see something like the following.

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)

Allow HTTP and HTTPs ports.

$ sudo ufw allow http
$ sudo ufw allow https

Check the status again to confirm.

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)

Step 2 - Install Git

Git comes usually pre-installed with Debian 12 but in case it is not installed, run the following command to install it.

$ sudo apt install git -y

Check Git's version.

$ git --version
git version 2.39.2

Run the following commands to configure Git to add your name and email address to it.

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

Step 3 - Install Node

Monica CRM needs Node.js to work. Import the Nodesource GPG key.

$ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/nodesource.gpg

Create the Nodesource deb repository. The current Node LTS version is 20.x but it doesn't work with the Yarn package manager therefore we have set it to 18.x for now.

$ NODE_MAJOR=18
$ echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

Update the system repositories list.

$ sudo apt update

Install Node.js.

$ sudo apt install nodejs -y

Confirm if it is installed properly.

$ node --version
v18.18.2

Update NPM.

$ sudo npm install -g npm@latest

Verify the NPM version.

$ npm --version
10.2.4

Step 4 - Install Yarn

Yarn is another Javascript package manager that is needed by Monica CRM along with Node.js. The usual method of installing Yarn is to install it globally. This ensures all testing and automation tools in a project use the same version of Yarn, preventing inconsistency.

Install Yarn using the following command.

$ sudo npm install --global yarn

Verify Yarn installation.

$ yarn --version
1.22.21

Step 5 - Install Nginx

Debian 12 ships with an older version of Nginx. To install the latest version, you need to download the official Nginx repository.

Import Nginx's signing key.

$ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

Add the repository for Nginx's stable version.

$ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

Update the system repositories.

$ sudo apt update

Install Nginx.

$ sudo apt install nginx

Verify the installation. On Debian systems, the following command will only work with sudo.

$ sudo nginx -v
nginx version: nginx/1.24.0

Start the Nginx server.

$ sudo systemctl start nginx

Check the service status.

$ sudo systemctl status nginx
? nginx.service - nginx - high performance web server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running) since Mon 2023-11-20 13:24:40 UTC; 4s ago
       Docs: https://nginx.org/en/docs/
    Process: 16778 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
   Main PID: 16779 (nginx)
      Tasks: 2 (limit: 2315)
     Memory: 1.7M
        CPU: 8ms
     CGroup: /system.slice/nginx.service
             ??16779 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
             ??16780 "nginx: worker process"

Open your server's IP address in your web browser. You should see the following page which means your server is up and running.

Nginx Default Page

Step 6 - Install PHP and extensions

Debian 12 ships with PHP 8.2 by default. You can install it and the extensions required by Monica CRM by running the following command.

$ sudo apt install php php-bcmath php-cli php-curl php-common \
    php-fpm php-gd php-gmp php-intl php-json php-mbstring \
    php-mysql php-opcache php-redis php-xml php-zip

To always stay on the latest version of PHP or if you want to install multiple versions of PHP, add Ondrej's PHP repository.

First, import Sury's repo PHP GPG key.

$ sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg

Add Ondrej Sury's PHP repository.

$ sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

Update your system repository list.

$ sudo apt update

You will probably receive information about pending upgrades. Run them.

$ sudo apt upgrade

Install PHP and its extensions.

$ sudo apt install php8.2 php8.2-bcmath php8.2-cli php8.2-curl php8.2-common \
    php8.2-fpm php8.2-gd php8.2-gmp php8.2-intl php8.2-mbstring \
    php8.2-mysql php8.2-opcache php8.2-redis php8.2-xml php8.2-zip

Check the version of PHP installed.

$ php --version
PHP 8.2.12 (cli) (built: Oct 27 2023 13:00:10) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies

Step 7 - Configure PHP-FPM

Open php.ini for editing.

$ sudo nano /etc/php/8.2/fpm/php.ini

To set file upload sizes, change the values of the upload_max_filesize and post_max_size variables. This value decides the size of the file you can upload to Monica. By default, it is set at 10MB which is what we will configure with PHP.

$ sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 10M/' /etc/php/8.2/fpm/php.ini
$ sudo sed -i 's/post_max_size = 8M/post_max_size = 10M/' /etc/php/8.2/fpm/php.ini

Configure PHP's memory limit depending on your server resources and requirements.

$ sudo sed -i 's/memory_limit = 128M/memory_limit = 256M/' /etc/php/8.2/fpm/php.ini

Open the file /etc/php/8.2/fpm/pool.d/www.conf.

$ sudo nano /etc/php/8.2/fpm/pool.d/www.conf

We need to set the Unix user/group of PHP processes to nginx. Find the user=www-data and group=www-data lines in the file and change them to nginx.

...
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nginx
group = nginx
...

Also, find the lines listen.owner=www-data and listen.group=www-data in the file and change them to nginx.

listen.owner = nginx
listen.group = nginx

Save the file by pressing Ctrl + X and entering Y when prompted.

Restart the PHP-fpm process. Make sure you have Nginx installed before restarting the PHP service otherwise, it will fail since it won't be able to find the nginx group.

$ sudo systemctl restart php8.2-fpm

Step 8 - Install Composer

Composer acts as a dependency manager for PHP. It is also the dependency manager of the Laravel PHP framework, which is what powers Monica CRM.

Download the Composer installation script.

$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

Verify the downloaded installer.

$ php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

You will receive the following output.

Installer verified

Run the installation script to download the latest version of Composer.

$ php composer-setup.php

Remove the installation script.

$ php -r "unlink('composer-setup.php');"

Move the downloaded binary file to the /usr/local/bin directory.

$ sudo mv composer.phar /usr/local/bin/composer

Confirm the installation.

$ composer --version
Composer version 2.6.5 2023-10-06 10:11:52

Step 9 - Install MariaDB

MariaDB is a drop-in replacement for MySQL which means commands to run and operate MariaDB are the same as those for MySQL.

Debian 12 by default ships with MariaDB 10.11.4 which is a bit outdated. To get the latest stable version of MariaDB, you need to use the official repository.

Import MariaDB's GPG key.

$ sudo curl -o /usr/share/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'

Create MariaDB's repository file.

$ echo "deb [signed-by=/usr/share/keyrings/mariadb-keyring.pgp] https://deb.mariadb.org/10.11/debian `lsb_release -cs` main" | sudo tee /etc/apt/sources.list.d/mariadb-server.list

Update the system repository list.

$ sudo apt update

Issue the following command to install the MariaDB server.

$ sudo apt install mariadb-server -y

Check if MariaDB is installed correctly.

$ mysql --version

You should see the following output.

mysql  Ver 15.1 Distrib 10.11.6-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

You can also use mariadb --version to check the version.

MariaDB service is already enabled and running. Check its status using the following command.

$ sudo systemctl status mariadb
? mariadb.service - MariaDB 10.11.6 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             ??migrated-from-my.cnf-settings.conf
     Active: active (running) since Tue 2023-11-21 07:49:48 UTC; 8min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 28307 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 28308 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 28310 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR>
    Process: 28350 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 28352 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 28339 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 8 (limit: 2315)
     Memory: 213.3M
        CPU: 585ms
     CGroup: /system.slice/mariadb.service
             ??28339 /usr/sbin/mariadbd

Run the following command to perform default configuration such as giving a root password, removing anonymous users, disallowing root login remotely, and dropping test tables.

$ sudo mariadb-secure-installation

You will be asked for your root password. Since we don't have any root password set, press the Enter key to proceed.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): [PRESS ENTER]
OK, successfully used password, moving on...

Next, you will be asked if you want to switch to the unix_socket plugin. The unix_socket plugin allows you to log in to MariaDB with your Linux user credentials. Choose n to skip switching to it since you already have a protected root account.

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

Next, you will be asked if you want to change your root password. On Debian 12, the root account for MariaDB is tied closely to automated system maintenance, so you should not change the configured authentication methods for the account. Doing so would allow a package update to break the database system by removing access to the administrative account. Type n to proceed.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

From here on, press y and then Enter to accept defaults for all the following questions. This will remove access to anonymous users, test databases, disable remote root login, and load the changes.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

That's it. Next time you want to log in to the MariaDB shell, use the following command.

$ sudo mysql

Enter your Linux root password when prompted.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 38
Server version: 10.11.6-MariaDB-1:10.11.6+maria~deb12 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Press exit to close the MariaDB shell.

Step 10 - Configure MariaDB

Log in to the MariaDB shell.

$ sudo mysql

Create a new MySQL database, database user, and password for your Monica CRM installation.

MariaDB> CREATE DATABASE monica CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB> CREATE USER 'monicauser'@'localhost' IDENTIFIED BY 'yourpassword';
MariaDB> GRANT ALL PRIVILEGES ON monica.* TO 'monicauser'@'localhost';

Replace monica, monicauser and yourpassword with the credentials of your choice. Choose a strong password.

Also, create an administrative user with the same capabilities as the root account.

MariaDB> GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Flush the privileges to ensure that they are saved in the current session.

MariaDB> FLUSH PRIVILEGES;

Exit the MariaDB shell.

MariaDB> exit

Step 11 - Downloading Monica

Create the web root directory.

$ sudo mkdir /var/www/html -p

Set the currently logged-in user as the owner of this directory.

$ sudo chown -R $USER:$USER /var/www/html

Switch to the directory.

$ cd /var/www/html

Clone the official Monica Github repository at this location.

$ git clone https://github.com/monicahq/monica.git

Switch to the cloned directory.

$ cd monica

Grab the latest data from GitHub.

$ git fetch

Checkout the latest version of Monica. To choose the latest version, check the Monica releases page. At the time of writing this tutorial, the latest available version is 4.0.0. Substitute 4.0.0 with the version you are installing in the command below.

$ git checkout tags/v4.0.0

You will get the following output.

Note: switching to 'tags/v4.0.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at e1a3e1315 build: delete heroku workflow (#6540)

Step 12 - Installing Monica

Make sure you are in the root directory for Monica.

$ cd /var/www/html/monica

Copy the sample environment variable file to create one for configuring Monica CRM.

$ cp .env.example .env

Change the following values as shown. Set the APP_ENV variable to production. This will enforce the HTTPS protocol. Set the APP_URL variable to your Monica's domain name along with HTTPS protocol. Set the database credentials as created in the previous step. In our tutorial, we are using Amazon's SES SMTP service. Enter the details for the service you are going to use. If you are not going to use any, you can skip filling those fields.

APP_ENV=production
...
APP_URL=https://monica.example.com
...
DB_DATABASE=monicadb
DB_USERNAME=monicauser
DB_PASSWORD=YourPassword23!
...
MAIL_MAILER=smtp
MAIL_HOST=email-smtp.us-west-2.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=SESID
MAIL_PASSWORD=SESKey
MAIL_ENCRYPTION=tls
# Outgoing emails will be sent with these identity
[email protected]
MAIL_FROM_NAME="Monica CRM"
# New registration notification sent to this email
[email protected]
...

Once finished, save the file by pressing Ctrl + X and entering Y when prompted.

Install all required packages for Monica using Composer.

$ composer install --no-interaction --no-dev

Use Yarn to install frontend packages and build the assets (JS, CSS, and fonts).

$ yarn install
$ yarn run production

Generate the APP_KEY value and fill it automatically in the .env file. You will be prompted with a yes or no question on whether to proceed. Type yes to proceed.

$ php artisan key:generate

Issue the following command to run migrations, seed the database, and create symlink directories. You will be prompted with a yes or no question on whether to proceed. Type yes to proceed. Enter your required email address and password to create a default user and use those values in the command.

$ php artisan setup:production [email protected] --password=yourpassword -v

You will receive the following output notifying you about the successful installation.

Monica v4.0.0 is set up, enjoy.
? Filling database
   INFO  Seeding database.


-----------------------------
|
| Welcome to Monica v4.0.0
|
-----------------------------
| You can now sign in to your account:
| username: [email protected]
| password: <hidden>
| URL:      https://monica.example.com
-----------------------------
Setup is done. Have fun.

Step 13 - Install SSL

We need to install Certbot to generate the SSL certificate. You can either install Certbot using Debian's repository or grab the latest version using the Snapd tool. We will be using the Snapd version.

Debian 12 comes doesn't come with Snapd installed. Install Snapd package.

$ sudo apt install snapd

Run the following commands to ensure that your version of Snapd is up to date.

$ sudo snap install core && sudo snap refresh core

Install Certbot.

$ sudo snap install --classic certbot

Use the following command to ensure that the Certbot command can be run by creating a symbolic link to the /usr/bin directory.

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

Verify if Certbot is functioning correctly.

$ certbot --version
certbot 2.7.4

Run the following command to generate an SSL Certificate.

$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email protected] -d monica.example.com

The above command will download a certificate to the /etc/letsencrypt/live/monica.example.com directory on your server.

Generate a Diffie-Hellman group certificate.

$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096

Check the Certbot renewal scheduler service.

$ sudo systemctl list-timers

You will find snap.certbot.renew.service as one of the services scheduled to run.

NEXT                        LEFT           LAST                        PASSED      UNIT                      ACTIVATES     
---------------------------------------------------------------------------------------------------------------------------               
Tue 2023-11-21 11:39:00 UTC 4min 54s left Tue 2023-11-21 11:09:07 UTC 24min ago    phpsessionclean.timer     phpsessionclean.service
Tue 2023-11-21 12:57:00 UTC 1h 22min left -                           -            snap.certbot.renew.timer  snap.certbot.renew.service
Wed 2023-11-22 00:00:00 UTC 12h left      Tue 2023-11-21 00:00:03 UTC 11h ago      dpkg-db-backup.timer      dpkg-db-backup.service

Do a dry run of the process to check whether the SSL renewal is working fine.

$ sudo certbot renew --dry-run

If you see no errors, you are all set. Your certificate will renew automatically.

Step 14 - Configure Nginx

Allow Nginx access to the Monica root directory.

$ sudo chown -R nginx:nginx /var/www/html/monica

Set the correct directory permissions on the storage directory.

$ sudo chmod -R 775 /var/www/html/monica/storage

Open the file /etc/nginx/nginx.conf for editing.

$ sudo nano /etc/nginx/nginx.conf

Add the following line before the line include /etc/nginx/conf.d/*.conf;.

server_names_hash_bucket_size  64;

Save the file by pressing Ctrl + X and entering Y when prompted.

Create and open the file /etc/nginx/conf.d/monica.conf for editing.

$ sudo nano /etc/nginx/conf.d/monica.conf

Paste the following code in it. Replace monica.example.com with your domain name. Make sure the value of the client_max_body_size is set to 10MB which is what the default upload size of files in Monica is. It is the same value we configured with PHP earlier.

server {

    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name monica.example.com;
    root /var/www/html/monica/public;

    index index.php;
    client_max_body_size 10M;

    access_log  /var/log/nginx/monica.access.log;
    error_log   /var/log/nginx/monica.error.log;

    ssl_certificate      /etc/letsencrypt/live/monica.example.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/monica.example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/monica.example.com/chain.pem;
    
    ssl_session_timeout  5m;
    ssl_session_cache shared:MozSSL:10m;
    ssl_session_tickets off;
    
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_keep_conn on;
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
# enforce HTTPS
server {
    listen 80;
    listen [::]:80;
    server_name  monica.example.com;
    return 301   https://$host$request_uri;
}

Save the file by pressing Ctrl + X and entering Y when prompted.

Verify your Nginx configuration.

$ sudo nginx -t

Restart the Nginx server.

$ sudo systemctl restart nginx

Step 15 - Access Monica CRM

Open the URL https://monica.example.com in your browser and you will be taken to the login page as shown below.

Monica CRM Login Page

Enter the email and password you configured in step 12 and press the Login button to proceed. You will be taken to the welcome screen from where you can start using the application.

Monica CRM Welcome Screen

Step 16 Set up Cron

Monica CRM requires several background processes to ensure its smooth running. This is managed using Cron functionality. To do this, set up a cron that will run every minute to run the php artisan schedule:run command.

Run the crontab editor. We are passing nginx as the user as it has access to the /var/www/html/monica directory.

$ sudo crontab -u nginx -e

If this is your first time running crontab, you will be asked for your choice of editor.

no crontab for nginx - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny

Choose 1-3 [1]: 1

Enter 1 to choose the nano editor as it is the easiest one to operate. Next, you will be taken to the crontab editor. Paste this line at the bottom of the file.

* * * * * php /var/www/html/monica/artisan schedule:run >> /dev/null 2>&1

Save the file by pressing Ctrl + X and entering Y when prompted. That's it. Monica's scheduled tasks will be run regularly using cron functionality.

Step 17 - Update Monica CRM

The first step to backing up the Monica CRM is to make sure it's backed up. You can back up the SQL from the settings page. Click the Settings icon on the top right of the dashboard to open the Account settings page. Next, open the Export data page from the left menu.

Monica Export Data page

Click the Export to SQL button to export the database. There is an Export to Json option as well which backups a lot more than just the SQL but there is no way to import it. You will probably see the status as failed for both exports but if you browse the directory /var/www/html/monica/storage/app/public/exports on your server, you should see both files.

$ ls /var/www/html/monica/storage/app/public/exports -al
total 84
drwxr-xr-x 2 nginx nginx  4096 Nov 22 09:47 .
drwxrwxr-x 4 nginx nginx  4096 Nov 22 09:47 ..
-rw-r--r-- 1 nginx nginx 53712 Nov 22 09:47 cvlK5RAl7VVLdYLplnSZ8SFGHHwDZy9cjRhtoOWB.json
-rw-r--r-- 1 nginx nginx 17050 Nov 22 09:47 dgZf5T0SnXeAuZ67HfaFLu2JosyUsByJcp2C8nlv.sql

Now that we have backed up the data, time to update.

Switch to the Monica directory.

$ cd /var/www/html/monica

Since the directory's permissions are set to nginx, we will need to use sudo to run any commands. But it is better to switch the permissions temporarily instead of using sudo which is what we will do.

$ sudo chown -R $USER:$USER /var/www/html/monica

Fetch the latest Git changes.

$ git fetch

Clone the desired version. For our tutorial, we are referring to the beta version. Don't use it on a production server.

$ git checkout tags/v5.0.0-beta.3

Update the dependencies.

$ composer install --no-interaction --no-dev

Install the frontend packages.

$ yarn install

Build the JavaScript and CSS assets.

$ yarn run production

Run the following command to update the instance. This runs migration scripts for the database and flushes all caches for config, route, and view as an optimization process.

$ php artisan monica:update --force

If you want to restore the SQL database to a different Monica instance, make sure your instance is completely empty which means no tables and no data. Once you have ensured that, run the following command to start the database migration process.

$ php artisan migrate

Next, import the monica.sql file using the following command.

$ sudo mysqlimport -u monicauser -p monica /var/www/html/monica/storage/app/public/exports/dgZf5T0SnXeAuZ67HfaFLu2JosyUsByJcp2C8nlv.sql

You will be prompted for your Monica user DB password configured earlier. Next, log in to the instance using the credentials used on the older instance.

Once you are finished, restore the Monica directory permissions to the nginx user.

$ sudo chown -R nginx:nginx /var/www/html/monica

Conclusion

This concludes our tutorial where you learned how to install Monica CRM software on a Debian 12 server. If you have any questions, post them in the comments below.

Share this page:

0 Comment(s)