Aug 25, 2024 3 min read

Dolibarr: Simplifying Self-Hosting

Dolibarr: Simplifying Self-Hosting
Table of Contents

Dolibarr is a versatile, open-source ERP and CRM software designed to help businesses manage everything from invoices and inventory to projects and contacts. Its self-hosted nature provides complete control over your data and allows for extensive customization to fit specific business needs. In this guide, we’ll cover all the necessary steps to deploy, configure, and manage Dolibarr effectively, from installation and reverse proxy setup to backups, updates, and leveraging its advanced features.

Installing Dolibarr

πŸ“¦ Docker/Docker Compose Setup

Using Docker is one of the easiest ways to deploy Dolibarr. Below is a ready-to-use docker-compose.yml file to set up Dolibarr with a MariaDB database.


version: '3.8'

services:

dolibarr:

image: dolibarr/dolibarr:latest

container_name: dolibarr_app

ports:

- "8080:80"

volumes:

- ./dolibarr_data:/var/www/html/documents

environment:

DOLI_DB_HOST: db

DOLI_DB_PORT: 3306

DOLI_DB_NAME: dolibarr

DOLI_DB_USER: dolibarr_user

DOLI_DB_PASSWORD: strongpassword

depends_on:

- db

db:

image: mariadb:10.11

container_name: dolibarr_db

environment:

MYSQL_ROOT_PASSWORD: rootpassword

MYSQL_DATABASE: dolibarr

MYSQL_USER: dolibarr_user

MYSQL_PASSWORD: strongpassword

volumes:

- ./db_data:/var/lib/mysql

Deploy the stack with the following commands:


mkdir dolibarr && cd dolibarr

nano docker-compose.yml  # Paste the above content

docker-compose up -d

Access Dolibarr at http://your-server-ip:8080 and complete the setup wizard.

πŸš€ Manual Installation

For those who prefer manual deployment, here are the steps for setting up Dolibarr on a Linux server:

  1. Install dependencies:

sudo apt update

sudo apt install apache2 php libapache2-mod-php php-mysql mariadb-server unzip wget -y

  1. Set up the database:

sudo mysql -u root -p

CREATE DATABASE dolibarr;

CREATE USER 'dolibarr_user'@'localhost' IDENTIFIED BY 'strongpassword';

GRANT ALL PRIVILEGES ON dolibarr.* TO 'dolibarr_user'@'localhost';

FLUSH PRIVILEGES;

EXIT;

  1. Download and extract Dolibarr:

wget https://github.com/Dolibarr/dolibarr/archive/refs/tags/<version>.zip

unzip <version>.zip

sudo mv dolibarr-<version> /var/www/html/dolibarr

sudo chown -R www-data:www-data /var/www/html/dolibarr

sudo chmod -R 755 /var/www/html/dolibarr

  1. Configure Apache:

sudo nano /etc/apache2/sites-available/dolibarr.conf

Add the following content:


<VirtualHost *:80>

ServerAdmin [email protected]

DocumentRoot /var/www/html/dolibarr/htdocs

ServerName yourdomain.com

<Directory /var/www/html/dolibarr/htdocs>

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/dolibarr_error.log

CustomLog ${APACHE_LOG_DIR}/dolibarr_access.log combined

</VirtualHost>

Enable the site and restart Apache:


sudo a2ensite dolibarr.conf

sudo a2enmod rewrite

sudo systemctl restart apache2

Access Dolibarr at http://yourdomain.com and complete the setup.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

Create an Nginx server block to proxy Dolibarr traffic from http://yourdomain.com to your Docker or manual setup.


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

Add the following:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://127.0.0.1:8080;  # Update port based on your Dolibarr setup

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

error_log /var/log/nginx/dolibarr_error.log;

access_log /var/log/nginx/dolibarr_access.log;

}

Enable the configuration and reload Nginx:


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

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

Secure your instance using Let’s Encrypt:


sudo apt install certbot python3-certbot-nginx -y

sudo certbot --nginx -d yourdomain.com

Verify auto-renewal with:


sudo certbot renew --dry-run

Logging and Debugging Dolibarr

πŸ—ƒοΈ Enabling Debug Logs

Enable debug logging in Dolibarr by editing the configuration file:


nano /path/to/dolibarr/documents/conf/conf.php

Set:


$dolibarr_main_prod = 0;

πŸ“„ Viewing Logs

For Docker users:


docker logs dolibarr_app

For manual setups, check:


tail -f /var/www/html/dolibarr/documents/logs/*.log

πŸ› οΈ Troubleshooting Common Issues

  • Check for permissions issues:

sudo chown -R www-data:www-data /var/www/html/dolibarr

  • Verify database connection settings in conf.php.

Backup and Restore

πŸ—‚οΈ File-Based Backups

Create a backup of Dolibarr’s configuration and documents:


tar -czvf dolibarr_files_backup.tar.gz /var/www/html/dolibarr/documents

πŸ”„ Database Backups

Export the database:


mysqldump -u dolibarr_user -p dolibarr > dolibarr_db_backup.sql

πŸ“… Automated Backup Scripts

Automate backups with a cron job:


crontab -e

Add:


0 2 * * * tar -czvf /backup/dolibarr_files_$(date +\%F).tar.gz /var/www/html/dolibarr/documents && mysqldump -u dolibarr_user -p'dbpassword' dolibarr > /backup/dolibarr_db_$(date +\%F).sql

Updating and Upgrading Dolibarr

⬆️ Updating Docker Images


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

Download the latest release, replace the old files, and run the update script:


wget https://github.com/Dolibarr/dolibarr/archive/refs/tags/<latest-version>.zip

unzip <latest-version>.zip

sudo cp -r dolibarr-<latest-version>/* /var/www/html/dolibarr

sudo php /var/www/html/dolibarr/htdocs/install/upgrade.php

Leveraging Dolibarr’s Unique Features

πŸ”§ Enabling APIs

Enable the API in conf.php:


$dolibarr_main_api_key = 'yourapikey';

Test API connectivity:


curl -X GET "http://yourdomain.com/api/index.php/products" -H "DOLAPIKEY: yourapikey"

🌟 Advanced Configurations

Add custom modules by uploading them to /var/www/html/dolibarr/custom, then enable them in the admin panel.

Wrapping Up

This guide has covered everything you need to deploy, configure, and manage Dolibarr on your server. From installation and reverse proxy setup to backups, updates, and advanced configurations, you now have the tools to fully leverage Dolibarr’s power. Start implementing these steps today to maximize your control and customization of this robust ERP/CRM system.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.