Yes, it is possible to install PHP Kint Library globally for Drupal Projects without Devel Module installed.
Install Kint Globally
Install PHP Kint Library globally.
composer global require kint-php/kint
Then copy the file path where the composer globally installed. If you are unable to find where the composer global directory, use the below command.
composer config --list --global
And figure out the [home]
directory from the list.
Now go to your settings.local.php
in your drupal project. And include the global autoload file as below.
include_once('/var/www/.composer/vendor/autoload.php');
if (class_exists('Kint')) {
Kint::$depth_limit = 4;
}
Change the /var/www/.composer/
to your home directory.
For example: /home/adharsh/.config/composer/vendor/autoload.php
Usually the settings.local.php
file is gitignored, so there will be no change for your code base and the Kint is now ready to use.
Yeah, its ready to use.
Go to the file you want to debug and use d()
function to debug.
Example: d($variable);
More functions are available in the Kint documentation.
Install in Lando
NOTE: If you are a lando user, you have to ssh (lando ssh
) into lando and globally install Kint. The composer global directory will be in /var/www/.composer
. You may need to reinstall the Kint globally if you are rebuilding Lando.
But you can add the run command in lando file to install the composer on lando build.
services:
appserver:
type: 'php:7.4'
run:
- "cd $LANDO_MOUNT && wget https://getcomposer.org/download/2.3.9/composer.phar"
- "chmod +x composer.phar"
- "php composer.phar install -n"
- "php composer.phar global require kint-php/kint"
- "rm composer.phar"
Replace the https://getcomposer.org/download/2.3.9/composer.phar
composer download link with you specific composer version from getcomposer and save the lando file.