Install EspoCRM as composer dependency

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tim
    Junior Member
    • Aug 2024
    • 18

    Install EspoCRM as composer dependency

    Hi,

    I googled a bit and found nothing on the subject. So, please excuse me if this topic has been raised before.

    With today's release of a new version of EspoCRM I finally tried something I planned for quite a while. Installing EspoCRM as composer dependency. It worked fine for me so I would like to share my setup and ask for your opinion.

    I have started with new `composer.json` with only requirement:

    Code:
    "require": {
      "espocrm/espocrm": "8.3.6"
    }​
    As espocrm/espocrm is not on the packagist I also had to add a repository:

    Code:
    "repositories": [
      {
        "type": "vcs",
        "url": "git@github.com:espocrm/espocrm.git"
      },
      {
        "type": "vcs",
        "url": "git@github.com:yurikuzn/lightncandy.git"
      }
    ]​
    yurikuzn/lightncandy was also required as EspoCRM uses custom fork.

    So after running composer upgrade espocrm/espocrm was deployed to vendor.

    Next I copied entire public/ directory from espocrm into my root.

    Then I added post-install-cmd/post-update-cmd scripts to symlink my customizations to vendor and client/ dir back to my pub. It also runs `npm ci` and `grunt`.

    Code:
    "scripts": {
      "post-install-cmd": [
        "mkdir -p data",
        "rm -fr vendor/espocrm/espocrm/data",
        "ln -s \"$(pwd)/data\" vendor/espocrm/espocrm/data",
        "rm -fr vendor/espocrm/espocrm/custom",
        "ln -s \"$(pwd)/custom\" vendor/espocrm/espocrm/custom",
        "rm -fr vendor/espocrm/espocrm/client/custom",
        "ln -s \"$(pwd)/client/custom\" vendor/espocrm/espocrm/client/custom",
        "if [ -d public/client ]; then rm -rf public/client; fi",
        "ln -s ../vendor/espocrm/espocrm/client public/client",
        "cd vendor/espocrm/espocrm && npm ci && grunt"
      ],
      "post-update-cmd": [
        "mkdir -p data",
        "rm -fr vendor/espocrm/espocrm/data",
        "ln -s \"$(pwd)/data\" vendor/espocrm/espocrm/data",
        "rm -fr vendor/espocrm/espocrm/custom",
        "ln -s \"$(pwd)/custom\" vendor/espocrm/espocrm/custom",
        "rm -fr vendor/espocrm/espocrm/client/custom",
        "ln -s \"$(pwd)/client/custom\" vendor/espocrm/espocrm/client/custom",
        "if [ -d public/client ]; then rm -rf public/client; fi",
        "ln -s ../vendor/espocrm/espocrm/client public/client",
        "cd vendor/espocrm/espocrm && npm ci && grunt"
      ]
    }​
    Unfortunately it's a duplication of the same code. An alternative would be to put it into file but I prefer to keep it in composer.json.

    Finally I created bootstrap.php with following content:

    PHP Code:
    <?php
    
    declare(strict_types=1);
    
    chdir(__DIR__ . '/vendor/espocrm/espocrm/');
    set_include_path(__DIR__ . '/vendor/espocrm/espocrm/');
    
    require_once 'vendor/autoload.php';

    So now my repository contains only of `client/custom/`, `custom/, `public/`, `bootstrap.php` and composer lock and json. One more composer install run to build it all and everything works.

    Benefits:

    - next upgrade (or rollback) will be as easy as changing version in composer.json
    - my repository only contains my modifications (less files, no temptation to hack the core)

    What do you think?
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Hi,

    When you make customizations, are they written in vendor/espocrm/espocrm/custom? If yes, then customizations will be erased when you update the espocrm dependency. The same is actual with data/.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • yuri
      yuri commented
      Editing a comment
      Now I see, Espo writes to vendor/espocrm/espocrm/custom, which is symlinked to custom/.
  • tim
    Junior Member
    • Aug 2024
    • 18

    #3
    Yes. Same for data and client/custom

    Comment

    • yuri
      Member
      • Mar 2014
      • 8440

      #4
      Maybe instead of copying the "public" directory, it's reasonable to use a rewrite rule (in .htaccess for Apache).
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • tim
        Junior Member
        • Aug 2024
        • 18

        #5
        Good point. If nothing else must be put into public, web root can be set to `/path/to/vendor/espocrm/espocrm/public/`

        Comment

        • tim
          Junior Member
          • Aug 2024
          • 18

          #6
          Published it as an article at our company's LinkedIn page - https://www.linkedin.com/pulse/insta...en-hint-ekelf/

          Comment

          Working...