How to Install Monica Personal CRM on Ubuntu Linux with Nginx

This article describes steps one can take to install and use Monica Personal CRM application on Ubuntu Linux.

Monica is a great open-source CRM or call it your own personal relationship management system. It is an open-source web application to organize and record your interactions with family, friends and almost group.

Monica will help you keep track of personal events, birthdays, contacts, basic journals, notes, and more. Stay in touch with a contact by sending reminders at a given interval.

For more on Monica, check its project’s GitHub page.

Below is how to install Monica on Ubuntu Linux with Nginx support.

How to install Monica personal relation manager on Ubuntu Linux with Nginx

As mentioned above, Monica is a great open-source CRM of call it your own personal relationship management system. It is an open-source web application to organize and record your interactions with family, friends and almost organizations.

Below is how to install it on Ubuntu Linux with Nginx support.

Install Nginx

Monica is a web application written in PHP. It requires a web server, and a great web server to use is Nginx.

Below is how to install Nginx on Ubuntu Linux.

sudo apt update
sudo apt install nginx

Additional help on installing Nginx can be found at the link below.

How to install Nginx on Ubuntu Linux

Install MariaDB

Monica also needs a database server to store its content. A great open-source database server to use with Monica is MariaDB.

Below is how to install MariaDB on Ubuntu Linux.

sudo apt update
sudo apt install mariadb-server

Additional help on installing MariaDB can be found at the link below.

How to install MariaDB on Ubuntu Linux

Install PHP-FPM

As described above, Monica is an application written in PHP. The current version of Monica CRM required at least PHP v8.1 or newer.

Below is how to install PHP on Ubuntu Linux.

sudo apt update
sudo apt install php8.1-fpm php8.1-cli php8.1-common php8.1-mbstring php8.1-xml php8.1-mysql php8.1-curl php8.1-zip php8.1-intl php8.1-bcmath php8.1-gd php8.1-gmp php8.1-redis

Additional help on installing PHP can be found at the link below.

How to install PHP or PHP-FPM on Ubuntu Linux

Install Composer

Composer is a PHP tool that can be used to install PHP dependencies. You may need Composer to install Monica dependencies.

You can install Composer via the one-line command below.

curl -sS  | sudo php -- --install-dir=/usr/bin --filename=composer

Install Node.js and Yarn

Node.js and Yarn are PHP package managers that will be used download and compile static files for Monica CRM.

Run the following command to add the Node.js Nodesource repository.

curl -fsSL  | sudo bash -

After that, run the following command to add the Yarn package repository to your system.

curl -sL  | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null

echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg]  stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Finally, install Node.js and Yarn using the commands below.

sudo apt update
sudo apt install nodejs yarn

Now that all required packages to install Monica are installed, we can begin configuring Monica database and created a web application portal.

Create Monica database

Let’s create a database for Monica. Run the commands below to log in to the MariaDB shell via MySQL command below.

sudo mysql -u root -p

Then create a database named monicadb.

CREATE DATABASE monicadb;

Create a database user named monicadbuser.

CREATE USER monicadbuser@localhost;

Finally, grant all access to monicadb database to monicadbuser and create a new password.

GRANT ALL ON monicadb.* TO 'monicadbuser'@'localhost' IDENTIFIED BY 'type_password_here';

Save your changes and exit.

FLUSH PRIVILEGES;
exit

Install Monica

We are ready to install Monica web app. Before we do that, let’s clone Monica project from GitHub.

sudo apt install git
cd /var/www/
sudo git clone https://github.com/monicahq/monica.git

Check out the stable branch version 3.7.0.

cd /var/www/monica
sudo git checkout tags/v3.7.0

Next, copy the default configuration .env.example to .env inside the Monica directory. Then, change the file ownership to ‘www-data‘.

sudo cp /var/www/monica/.env.example /var/www/monica/.env
sudo chown www-data:www-data /var/www/monica/.env

Run the commands below to edit the .env file.

sudo nano /var/www/monica/.env

Then update the highlighted lines to match your environment.

# The URL of your application.
APP_ENV=production
APP_URL=
# Force using APP_URL as base url of your application.
# You should not need this, unless you are using subdirectory config.
APP_FORCE_URL=false
# Database information
# To keep this information secure, we urge you to change the default password
# Currently only "mysql" compatible servers are working
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
# You can use mysql unix socket if available, it overrides DB_HOST and DB_PORT values.
#DB_UNIX_SOCKET=/var/run/mysqld/mysqld.sock
DB_DATABASE=monicadb
DB_USERNAME=monicadbuser
DB_PASSWORD=type_password_here
DB_PREFIX=
DB_TEST_HOST=127.0.0.1
DB_TEST_DATABASE=monica_test
DB_TEST_USERNAME=homestead
DB_TEST_PASSWORD=secret
# Use utf8mb4 database charset format to support emoji characters

Save the file and exit.

Next, run the commands below to update the directory permissions, create a new folder.

sudo chown -R www-data:www-data /var/www/monica
sudo mkdir -p /var/www/.cache
sudo chown -R www-data:www-data /var/www/.cache

After that, run the commands below to install PHP dependencies for Monica.

sudo -u www-data composer install --no-interaction --no-dev

Next, create a Yarn folder and also update its permissions to work with Nginx.

sudo mkdir -p /var/www/.yarn
sudo chown -R www-data:www-data /var/www/.yarn

Once you are done, run the commands below to complete installing and compiling Monica dependencies and environment.

sudo -u www-data yarn install
sudo -u www-data yarn run production
sudo -u www-data php artisan key:generate
sudo -u www-data php artisan setup:production -v

When you the last command, it should prompt you if you want to configure Monica? Type Yes to continue.

When all said and done, you should see the output similar to the one below:

Monica v3.7.0 is set up, enjoy.

✓ Filling database
Seeding: FakeUserTableSeeder
Seeded:  FakeUserTableSeeder (16,577.42ms)
Database seeding completed successfully.
-----------------------------
|
| Welcome to Monica v3.7.0
| You can now log in to your account
| URL:      
Setup is done. Have fun.

To ensure that Monica application functions well, update its directory permissions so that the web server has access to manage the content within.

sudo chown -R www-data:www-data /var/www/monica
sudo chmod -R 775 /var/www/monica/storage

Configure Nginx server block

To get the Monica portal working, we need to configure Nginx server block and define Monica directory to manage.

Run the commands below to create a server block for Monica.

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

The copy and paste the lines below into the file and save.

server {
    listen 80;

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

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
    }
}

After saving, run the commands below to enable the server block.

sudo ln -s /etc/nginx/sites-available/monicacrm /etc/nginx/sites-enabled/

Test and restart Nginx. If you don’t get any errors, you’re good to go.

sudo nginx -t
sudo systemctl restart nginx

Access Monitor portal

Now all that is left to do is to connect to the server hostname or domain and access Monitor portal.


You can register and begin using Monica.

If you want to secure Monica portal with SSL, you may want to install, and use Let’s Encrypt free SSL.

Below is how to do that with Nginx on Ubuntu Linux.

How to install and use Let’s Encrypt SSL with Nginx on Ubuntu Linux

That should do it!

Conclusion:

This post showed you how to install Monica CRM on Ubuntu Linux with Nginx. If you find any error above or have something to add, please use the comment form below.