Self Hosting Monica

Ahmed Musaad
Ahmed Musaad
Self Hosting Monica

Monica is an open-source web application to organize the interactions with your loved ones. Think of it as a CRM for your friends or family. In this post, I share a simple, easy to follow guide for those who want to self-host Monica.

Monica is an open-source web application to organize the interactions with your loved ones. We call it a PRM, or Personal Relationship Management. Think of it as a CRM (a popular tool used by sales teams in the corporate world) for your friends or family.

Steps

This Guide has been successfully tested on Ubuntu 20.04

Install Required Software

Install Git & Apache2

sudo apt update
sudo apt install -y git apache2 software-properties-common

Install PHP 7.3

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install -y php7.3 php7.3-cli php7.3-common php7.3-fpm \
    php7.3-json php7.3-opcache php7.3-mysql php7.3-mbstring php7.3-zip \
    php7.3-bcmath php7.3-intl php7.3-xml php7.3-curl php7.3-gd php7.3-gmp

Install Composer

cd /tmp
curl -s https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin/ --filename=composer
rm -f composer-setup.php

Install MySQL Server

sudo apt update
sudo apt install -y mysql-server

Prepare Database

Make sure to change the password when creating the user

sudo mysql
CREATE DATABASE monica;
CREATE USER 'monica'@'localhost' IDENTIFIED WITH mysql_native_passwordBY 'strongpassword';
GRANT ALL ON monica.* TO 'monica'@'localhost';
FLUSH PRIVILEGES;
exit

Install Monica

cd /var/www
git clone https://github.com/monicahq/monica.git
cd /var/www/monica
git checkout tags/v2.17.0
cd /var/www/monica
cp .env.example .env
sudo nano .env

Prepare the Configuration File

The configuration file is long and full of configuration options, the configuration values below achieves the following tasks:

  • Set the application environment.
  • Disable Debugging.
  • Add a random hash salt.
  • Set the application URL.
  • Configure the database connection details.
  • Disable Ping Home.
  • Configure Max Sizes for account storage and file uploads.
  • Enable multi-factor authentication.
  • Enable DAV support.
  • Configure the client ID and secret to be used in the mobile application.

Remember: Add your own database username and password, your own hash salt, your own client ID and Secret.

#Use local if you want to install Monica as a development version.
# Use production otherwise.
APP_ENV=local

# true if you want to show debug information on errors. 
# For production, put this to false.
APP_DEBUG=false

# Provide a random salt for hashses.
HASH_SALT=ChangeMeBy20+KeyLength
HASH_LENGTH=18

# The URL of your application.
APP_URL=http://localhost

# Database information
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=monica
DB_USERNAME=
DB_PASSWORD=
DB_PREFIX=
DB_USE_UTF8MB4=true

CHECK_VERSION=false

# Maximum allowed size for uploaded files, in kilobytes.
# Make sure this is an integer, without commas or spaces.
DEFAULT_MAX_UPLOAD_SIZE=10240

# Maximum allowed storage size per account, in megabytes.
# Make sure this is an integer, without commas or spaces.
DEFAULT_MAX_STORAGE_SIZE=512

# Allow Two Factor Authentication feature on your instance
MFA_ENABLED=true

# Enable DAV support
DAV_ENABLED=true

# CLIENT ID and SECRET used for the official mobile application
MOBILE_CLIENT_ID=
MOBILE_CLIENT_SECRET=

Run the Installation

# Install all packages
composer install --no-interaction --no-suggest --no-dev --ignore-platform-reqs

# Generate a random application key
php artisan key:generate

# Run the following command to run the migrations, seed the database, symlink folders, and create your first account.
# Replace the email and password with your own.
php artisan setup:production --email=your@email.com --password=yourpassword -v

Configure cron job

sudo nano /etc/cron.d/monica

# Add the following line to the file
echo "* * * * * sudo -u www-data php /var/www/monica/artisan schedule:run" | sudo tee /etc/cron.d/monica

Configure Apache2

sudo chown -R www-data:www-data /var/www/monica
sudo chmod -R 775 /var/www/monica/storage
sudo a2enmod rewrite
sudo nano /etc/apache2/sites-available/monica.conf

Here is a simple configuration that will get you up and running in no time:

<VirtualHost *:80>
    ServerName **YOUR IP ADDRESS/DOMAIN**

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/monica/public

    <Directory /var/www/monica/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Apply Things & Restart Services

sudo a2dissite 000-default.conf
sudo a2ensite monica.conf
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.3-fpm
sudo service php7.3-fpm restart
sudo service apache2 restart

Navigate to http://localhost or https://yourdomain

via GIPHY



Great! Next, complete checkout for full access to Ahmed Musaad
Welcome back! You've successfully signed in
You've successfully subscribed to Ahmed Musaad
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated