DEV Community

Ahmad Jamaly Rabib
Ahmad Jamaly Rabib

Posted on

How I am using composer to install Dolibarr modules

Those who don't know about Dolibarr, Dolibarr is a Open Source ERP and CRM system for businesses. It's codebase is written in PHP.

Here is the repository if you are interested. btw I don't think any developer will be comfortable working on this codebase first time 😅

It had a composer file to manage some dependency before but in the current stable version it is disabled. You can check the commit message here 😜

So anyway, to install any module we need to zip the module and upload via Dolibarr admin panel. Or we can copy the module to the htdocs/custom folder area. 😐

But it causes some issues when we are continuously updating modules and managing version control system for modules.

Also it causes some security risk when we open the upload functionality of the modules. 😱

And honestly why we shouldn't use composer to install modules? It felt like I am in the age of Dinosaurs. 🙄

So what we did was simple. Initialize the dolibarr project with composer. Created separate repositories for the modules.

And when we need to install any modules we just need to add that in the composer.json file.

{
    "name": "dolibarr/dolibarr",
    "description": "Dolibarr ERP & CRM is a modern and easy to use web software to manage your business",
    "license": "GPL-3.0-or-later",
    "require": {
        "myproject/dashboard": "dev-master",
        "myproject/report": "dev-master"
    },
    "repositories": [
        {
            "url": "git@github.com:myproject/dashboard.git",
            "type": "git"
        },
        {
            "url": "git@github.com:myproject/report.git",
            "type": "git"
        }
    ],
    "config" : {
       "vendor-dir" : "../vendor"
    }
}

Enter fullscreen mode Exit fullscreen mode

I did install the modules outside the project folder in the vendor directory and created symlink to show this as the custom folder inside htdocs directory.

And in the modules I added composer.json to make the module repositories as packages. Here is the composer.json file of the module

{
    "name": "myproject/dashboard",
    "description": "This module shows custom dashboard",
    "type": "dolibarr-module",
    "license": "MIT",
    "authors": [
        {
            "name": "Ahmad Jamaly Rabib",
            "email": "rabib@japantravel.com"
        }
    ],
    "require": {}
}

Enter fullscreen mode Exit fullscreen mode

I have kept the require as empty as it is not needed now but we can modify based on our needs.

So in this way whenever we add/update any module in our dolibarr main project we just need to run composer install or composer update. No need to copy the folders or making zip files to upload from dolibarr dashboard. 😎🥳

We can do the same approach for any PHP projects to reuse codes and reduce complexity. 😇 Thank you for reading!

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (1)

Collapse
 
moisesvortice profile image
Moisés Márquez

Great. I will use this approach in my next projects with Dolibarr. I think the core team needs to adapt to composer and the features of the latest PHP versions.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay