How to Install Monica on CentOS 7

Updated on January 4, 2019
How to Install Monica on CentOS 7 header image

Monica is an open source personal relationship management system. Think of it as a CRM (a popular tool used by sales teams in the corporate world) for your friends or family. Its source code is publicly hosted on GitHub. In this guide, we will go over the installation process of a Monica application.


  • Git
  • NPM (Node Package Manager)
  • PHP 7.1 or newer
  • MariaDB
  • Nginx
  • Composer

Before you begin

Check the CentOS version.

cat /etc/centos-release
# CentOS Linux release 7.5.1804 (Core)

Create a new non-root user account with sudo access and switch to it.

useradd -c "John Doe" johndoe && passwd johndoe
usermod -aG wheel johndoe
su - johndoe

NOTE: Replace johndoe with your username.

Set up the timezone.

timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'

Ensure that your system is up to date.

sudo yum update -y

Install required packages.

sudo yum install -y git vim wget curl gcc-c++ make libpng-devel

For simplicity, disable SELinux and Firewall.

sudo setenforce 0
sudo systemctl stop firewalld
sudo systemctl disable firewalld

Install PHP

Setup the Webtatic YUM repo.

sudo rpm -Uvh

Install PHP and required PHP extensions.

sudo yum install -y php72w php72w-cli php72w-fpm php72w-common php72w-mbstring php72w-xml php72w-mysql php72w-curl php72w-zip php72w-intl

Check the version.

php --version
# PHP 7.2.6 (cli) (built: Jun  2 2018 07:49:42) ( NTS )

Start and enable PHP-FPM.

sudo systemctl start php-fpm.service
sudo systemctl enable php-fpm.service

Install MariaDB and setup database

Create the repo file for MariaDB.

sudo vi /etc/yum.repos.d/MariaDB.repo

Populate the file with the following.

name = MariaDB
baseurl =

Install MariaDB.

sudo yum install -y MariaDB-server MariaDB-client

Check the MariaDB version.

mysql --version
# mysql  Ver 15.1 Distrib 10.2.16-MariaDB, for Linux (x86_64) using readline 5.1

Start and enable the MariaDB service.

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Run the mysql_secure_installation script to improve the security of your MariaDB installation.

sudo mysql_secure_installation

Log in to MariaDB as the root user.

mysql -u root -p
# Enter password:

Create a new MariaDB database and user, and remember the credentials.

GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';

Install and configure Nginx

Create the Nginx repo.

sudo vim /etc/yum.repos.d/nginx_mainline.repo

Populate it with the following contents.

name=nginx repo

Generate the Nginx signing key.

sudo rpm --import nginx_signing.key
rm nginx_signing.key

Install Nginx.

sudo yum install -y nginx

Check the version.

sudo nginx -v
# nginx version: nginx/1.15.0

Start and enable Nginx.

sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Run sudo vim /etc/nginx/conf.d/monica.conf and configure Nginx for Monica.

server {
  listen 80;
  listen [::]:80;

  root /var/www/monica/public/;

  index index.php;
  charset utf-8;
  location ^~ /storage {
    deny all;  
  location / {
    try_files $uri $uri/ /index.php?$query_string;

  location ~* \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;

Save the file and exit.

Test the configuration.

sudo nginx -t

Reload Nginx.

sudo systemctl reload nginx.service

Install Node.js and NPM

Install Node.js.

curl --silent --location | sudo bash -
sudo yum -y install nodejs

Check the Node.js and npm versions.

node -v && npm -v
# v10.5.0
# 6.1.0

Install Composer

Install Composer.

php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

Check the version.

composer --version
# Composer version 1.6.5 2018-05-04 11:44:59

Install and configure Monica

Create an empty document root folder where Monica should be installed.

sudo mkdir -p /var/www/monica

Navigate to the document root folder.

cd /var/www/monica

Change ownership of the /var/www/monica folder to user johndoe.

sudo chown -R johndoe:johndoe /var/www/monica

Clone the Monica repository to it.

git clone .
git checkout tags/v2.3.1

NOTE: Find the latest official version on the releases page on GitHub and update the version number above to the latest release.

Run the following to create your own version of the environment variables needed for the project.

cp .env.example .env

Update the .env file to your specific needs. Don't forget to set DB_USERNAME and DB_PASSWORD with the settings used previously.

Install all packages.

composer install --no-interaction --no-suggest --no-dev --ignore-platform-reqs

Install all the front-end dependencies and tools needed to compile assets.

npm install

Compile the JS and CSS assets.

npm run production

Generate an application key. This will set APP_KEY to the correct value automatically.

php artisan key:generate

Run the migrations and seed the database and symlink folders.

php artisan setup:production

Change ownership of the /var/www/monica directory to nginx.

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

Run sudo vim /etc/php-fpm.d/www.conf and set the user and group to nginx. Initially, they will be set to apache.

sudo vim /etc/php-fpm.d/www.conf
# user = nginx
# group = nginx

Restart php-fpm.service

sudo systemctl restart php-fpm.service

The installation is complete. Open your domain in your web browser and follow the instructions shown on screen.