How to install Composer in Vtiger CRM

How to install Composer in Vtiger CRM

Composer is the most popular package manager. And it is sorely lacking when developing in Vtiger CRM. Today I will tell you my method of connecting this package to the system.

Composer is the most popular package manager. And it is sorely lacking when developing in Vtiger CRM. Today I will tell you my method of connecting this package to the system.

So let's start from the very beginning.

The first thing we need to do is install composer. I will not describe here the installation process in detail, it all depends on your operating system. To install, simply go to https://getcomposer.org/ and follow the instructions.

Now when composer is installed globally, go to the core vtigercrm folder and run the command:

composer install

After that, we just have to connect package manager to the CRM.

To do this, go to the index.php file and before the line

include_once 'vtlib/Vtiger/Module.php';

Just insert this:

include_once 'vendor/autoload.php';

After that vtiger crm should be broken) ... So, let's fix our 500 error.

Now you need to install some packages. Run the following command in the console:

composer require ezyang/htmlpurifier

Then this:

composer require phpoffice/phpspreadsheet

Now change file:

include/utils/VtlibUtils.php

Find this line:

include_once ('libraries/htmlpurifier/library/HTMLPurifier.auto.php');

Change it to this:

include_once ('vendor/ezyang/htmlpurifier/library/HTMLPurifier.auto.php');

Then you need to change file:

modules/Reports/ReportRun.php

Find line

require_once("libraries/PHPExcel/PHPExcel.php");

Change it to:

require_once("vendor/autoload.php");

If you want, you can remove folder libraries/PHPExcel

Now you can try to update smarty:

composer require smarty/smarty

And chage line in file includes/runtime/Viewer.php:

vimport ('~/libraries/Smarty/libs/SmartyBC.class.php');

To this:

vimport ('~/vendor/smarty/smarty/libs/SmartyBC.class.php');

Now you can delete smarty library folder if you want libraries/Smarty/libs

After that, Vtiger should work correctly.

And that's it, composer must be installed on your system. For testing, you can do the following. Try installing a useful debugging tool:

composer require kint-php/kint --dev

This command will install this package: https://github.com/kint-php/kint

Now go to file:

modules/Potentials/models/ListView.php

And before line

return $massActionLinks;

insert this

d($massActionLinks);

Now try to open the list of potentials and you will see a div with debug information in front of the table.

From now, you can safely install any packages via composer into your Vtiger CRM. And they will automatically be connected to the system.