Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Install Monica CRM on Ubuntu with Nginx

How to Install Monica CRM on Ubuntu with Nginx

Setting up Monica CRM on Ubuntu with Nginx provides a powerful, self-hosted contact and relationship management system tailored to your needs. This guide walks you through installing Monica CRM on an Ubuntu server, configuring Nginx as a reverse proxy, and ensuring everything runs smoothly. Before starting, ensure your server runs Ubuntu 20.04 or later, has root access, and a domain name pointing to your server’s IP address. Having basic knowledge of Linux commands and server management will help you follow these steps more comfortably.

What You’ll Need

  • Ubuntu 20.04 or later server with root or sudo user access
  • Domain name pointed to your server’s IP address
  • Root or sudo privileges on the server
  • Basic familiarity with terminal commands
  • SSL certificate (optional but recommended for HTTPS)

Step-by-Step

  1. Update your server packages: Run sudo apt update && sudo apt upgrade -y to ensure your system is current.
  2. Install necessary dependencies: Install PHP, Composer, MySQL, and other required packages:
    sudo apt install nginx php php-fpm php-cli php-mbstring php-xml php-bcmath php-curl php-zip php-mysql unzip git mysql-server -y
  3. Secure MySQL installation: Run sudo mysql_secure_installation and follow prompts to set root password and remove anonymous users.
  4. Create a database for Monica: Log into MySQL and run:
    sudo mysql -u root -p
    CREATE DATABASE monica_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    CREATE USER 'monica_user'@'localhost' IDENTIFIED BY 'your_password';
    GRANT ALL PRIVILEGES ON monica_db.* TO 'monica_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  5. Download Monica CRM: Navigate to your web root directory and clone the latest release:
    cd /var/www/
    sudo git clone https://github.com/monicahq/monica.git monica
  6. Set permissions: Adjust ownership and permissions:
    sudo chown -R www-data:www-data /var/www/monica
    sudo chmod -R 755 /var/www/monica
  7. Configure environment variables: Copy the example environment file and edit it:
    cd /var/www/monica
    sudo cp .env.example .env
    sudo nano .env

    Update database credentials and other settings accordingly. Save and exit.

  8. Install dependencies with Composer: Run:
    sudo apt install composer
    cd /var/www/monica
    composer install --no-dev --optimize-autoloader
  9. Generate application key: Run:
    php artisan key:generate
  10. Run database migrations: Execute:
    php artisan migrate
  11. Configure Nginx: Create a new server block:
    sudo nano /etc/nginx/sites-available/monica

    Insert the following configuration, replacing with your actual domain:

    server {
        listen 80;
        server_name ;
    
        root /var/www/monica/public;
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    

    Enable the site and restart Nginx:

    sudo ln -s /etc/nginx/sites-available/monica /etc/nginx/sites-enabled/
    sudo nginx -t
    sudo systemctl restart nginx
  12. Set up HTTPS (optional but recommended): Use Certbot to obtain SSL certificates:
    sudo apt install certbot python3-certbot-nginx
    sudo certbot --nginx -d 
  13. Complete installation: Visit to access Monica CRM. Log in with default credentials or set up your admin account.

Common Mistakes

  • Forgetting to set correct permissions on the Monica directory, leading to server errors.
  • Using incorrect database credentials in the .env file, causing connection failures.
  • Not enabling the site in Nginx or misconfiguring the server block, resulting in 404 errors.
  • Forgetting to run database migrations, which prevents the app from functioning properly.
  • Neglecting to restart PHP-FPM or Nginx after configuration changes.

Tips

  • Always back up your database and configuration files before making major changes.
  • Use a strong, unique password for your database user.
  • Keep your server updated to receive security patches and improvements.
  • Configure automatic SSL renewal with Certbot to maintain HTTPS.
  • Regularly check server logs for errors: /var/log/nginx/error.log and /var/log/php7.4-fpm.log.

Troubleshooting

If you encounter issues during installation or after setup:

  • Website not loading or 500 errors: Check Nginx and PHP-FPM logs for errors. Ensure permissions are correct and migrations are run.
  • Database connection errors: Verify database credentials in the .env file and ensure MySQL service is running.
  • SSL certificate issues: Confirm domain DNS settings are correct and Certbot certificates are valid. Re-run Certbot if necessary.
  • Application errors: Clear cache and config cache using:
    php artisan cache:clear
    php artisan config:cache
  • Always restart services after configuration changes:
    sudo systemctl restart nginx
    sudo systemctl restart php7.4-fpm

Frequently Asked Questions

Can I install Monica CRM without a domain name?

Yes, you can access it via your server’s IP address, but for SSL and a better user experience, a domain is recommended.

Is it necessary to use HTTPS for Monica CRM?

While not mandatory, HTTPS encrypts data between your browser and server, enhancing security and trust.

How do I upgrade Monica CRM in the future?

Pull the latest updates from the GitHub repository, run composer install, and migrate the database if needed. Always back up first.

What should I do if I forget my Monica admin password?

Use the Laravel artisan command to reset passwords or consult Monica’s documentation for user management options.

Can I run Monica CRM on other web servers like Apache?

Yes, but this guide covers Nginx. Configuration steps differ slightly; adjust accordingly if using Apache.

Is Monica CRM suitable for small or large teams?

It works well for small to medium teams, but for very large organizations, consider performance and scalability aspects.

By following these steps carefully, you can successfully host Monica CRM on your Ubuntu server with Nginx, giving you a private, customizable contact management system tailored to your needs. Regular maintenance and updates will keep your installation secure and functional for years to come.

Related

How to Install Monica CRM on Ubuntu with Nginx
Scroll to top