How to Install Kint Globally Drupal - Without Devel Module - drupal

I was trying to setup an easy way to debug the Lando Drupal installations using Kint module. But I don't want to install the Devel and Devel Kint Extras modules in each Installations.
What I have initially done is installed the Kint globally in my local.
composer global require kint-php/kint
But it is not possible to access the functions inside a Lando installation by requiring the global autoload file to the settings.local.php
include_once('/home/username/.composer/vendor/autoload.php');
The same is working on local Drupal installation, but not inside Lando installations.

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.

Related

Running composer installation in a Symfony 3.2 project on a machine that shares 2 environments

I have in the same server in 2 differents directories, like this:
/var/www/pre.myproject.com/
/var/www/myproject.com/
pre.myproject.com is a full copy from production myproject.com
When I am trying to run the command composer install inside the folder /var/www/pre.myproject.com/ with this:
composer install --no-dev --optimize-autoloader
I see the following errors:
Cannot create cache directory /var/www/myproject.com/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /var/www/myproject.com/.composer/cache/files/, or directory is not writable.Proceeding without cache
Why is it trying to make changes in myproject.com if I am currently at pre.myproject.com?
What files should I change in my folder pre.myproject.com to enable a new environment in Symfony3? And so the composer can install correctly for this environment and within this directory?
What you trying to do is having a new installation of an existing Symfony project with an existing composer.json file containing all your dependencies.
What you should do is not composer install but composer update as the composer.json file should already exist, it'll just read it and download the dependencies packages
composer update :
The update command reads the composer.json file from the current
directory, processes it, and updates, removes or installs all the
dependencies.
This is what I am using on my production server when I import a new feature from my development branch.
Edit
You should add --no-cache option to bypass the cache.

Can't create a new Symfony project

I can't create a new Symfony project as described in the Symfony Documentation: https://symfony.com/doc/4.3/setup.html
This is the command I use: symfony new --full my_project
Output:
$ symfony new --full my_project
WARNING The current directory seems configured for as a SymfonyCloud project, but it is not linked yet.
You can link this directory to an existing project: symfony link [project-id] (get project IDs via symfony projects)
* Creating a new Symfony project with Composer
unable to find composer, get it at https://getcomposer.org/download/: exec: "composer": executable file not found in
$PATH
I don't understand why the command can't find the composer executable.
When I just enter $ composer in my terminal, composer is executed.
This is my Symfony CLI version: Symfony CLI version v4.6.1
In my .bash_profile file, I have an alias for composer:
alias composer="php /usr/local/bin/composer.phar"
My /etc/paths:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
What is wrong in my config?
Most likely, it's because you didn't rename composer.phar.
First, do this:
mv /usr/local/bin/composer.phar /usr/local/bin/composer
It will rename composer.phar to composer.
Then you can also delete your alias.
Alias are for connected users. Executable and installer don't read your aliases, which is why symfony installer isn't finding composer.
If it doesn't solve your problem, you can try to install your Symfony project with composer directly:
composer create-project symfony/website-skeleton my_project
You can also check what php version is that your symfony is using
In my case it was linked to php 5 and by changing to php 7 problem has been resolved
To check php version linked use :
symfony local:php:list
And then to edit your php version create a .php-version file then write the version that you want to use

Command composer require symfony/apache-pack doesn't create .htaccess file

When I execute the command:
composer require symfony/apache-pack
It doesn't create an .htaccess file as it is cited in the documentation here.
How can I fix this problem ?
If apache-pack is installed in your project and you later remove the .htaccess file from the /public directory, running composer require apache-pack will not re-install the .htaccess file.
You must first remove apache pack.
So, first run composer remove symfony/apache-pack
And then run composer require symfony/apache-pack
As explained here : https://github.com/symfony/recipes-contrib/issues/676#issuecomment-519959252
The solution is :
1-removing symfony/apach-pack from required in compoer.json
2- run command
composer update
which delete apach-pack from project.
3-run again the command for installing apach-pack as cited in the documentation here:
composer require symfony/apache-pack
4- when asked this question :
Do you want to execute this recipe?
type :
Yes
5- That's it now the file .htaccess exists
I was having the same issue as Dan where composer was not asking me to execute any recipes. it turns out I needed to install Symfony Flex which wasn't present in my microkernel application. I used "composer req symfony/flex" to install it and then afterwards a remove/require of symfony/apache-pack asked me to run the recipe. You can also type "composer recipes" to see your recipes and their status, once flex is installed.
I tried to remove the package and reinstall it but didn't work so I tried to execute the same commands on another console and it works for me
git bash terminal : didn't work
windows terminal: it works (https://learn.microsoft.com/en-us/windows/terminal/)

ignore dev dependencies in php composer

I have developed a composer laravel based project that I need to install on a remote production server. The problem is I have limited permission/ access so my option is to "archive" the package( using composer archive) and unpack on the production.
What folders do I need to archive and how can I ignore the dev dependencies of the package as well as vendor dev dependencies?
composer archive is likely not to help you, because this command creates an archive of a defined version of a package.
You probably want to upload the whole working application, and not only one package. You should create a little script that will create the archive file for you, which should do:
checkout the application from the repository in a new directory
run composer install --no-dev to install all required dependencies without dev-dependencies
optionally delete files that are not necessary on the server, like documentation, the .git folder, and other stuff
create the archive file from all these files
optionally upload that archive to the target server and unarchive there
optionally check basic functions and switch to the new uploaded version on the server

How do I setup Drupal Console on Windows 7?

How do I install/setup Drupal Console on Windows 7? In the video by the author, the environment used is Linux.
I tried to install it on Windows 7, but I wasn't able to use it to generate a module code.
You can download the drupal console either using Git Bash
$curl https://drupalconsole.com/installer -L -o drupal
Or using windows command prompt
c:\>php -r "readfile('https://drupalconsole.com/installer');" > drupal
After downloading this file, place it beside php.exe file within your php folder (not project folder), restart your terminal/cmd-prompt and type
$drupal
to get started.
Besides downloading Drupal Console .phar file, you can also install Drupal Console using composer on windows.
First Download and install composer in your system.
Then on your windows command prompt or git terminal
$composer global require drupal/console:#stable
Create a file called drupal.bat
#php "%~dp0drupal.phar" %*
Here's the full list of steps I took:
php -r "readfile('https://drupalconsole.com/installer');" > drupal.phar
added installation location to the global PATH
created a drupal.bat file in the same directory as drupal.phar. drupal.bat contains: #php "%~dp0drupal.phar" %*
Now you can call >drupal from any location. I would upvote #Nate's answer, but this is a new account.
Open Git bash (or any terminal with curl capability)
Run curl https://drupalconsole.com/installer -L -o drupal.phar
Create file drupal.bat with content #php "%~dp0drupal.phar" %*
Copy both files (drupal.phar and drupal.bat) into C:\WINDOWS
Open new Command prompt window then try typing drupal list.
This steps assume:
Your PHP is on Path environment variables and you can run php --version.
You have Git for Windows installed.
you can install drupal console using composer
open the command line on windows then go to :
cd /path/to/drupal8.dev
now you can install drupal console :
composer require drupal/console:~1.0 --prefer-dist --optimize-autoloader
after that you installed drupal console you can use it from drupal root directory where composer.json exist as follow:
vendor/bin/drupal <the_command>
you should replace <the_command> with one of the drupal console commands. you can see complete list of the commands here: drupal console commands
Find a php.exe
Add this path to the environnement variable path
from terminal run
php -r "readfile('https://drupalconsole.com/installer');" > drupal.phar
i then use php-storm IDE :
file/settings/command line
add tool based on symfony console
fill php path and drupal.phar path
console is now set
tools/run command
drupal list
if you have php and composer all setup
make sure you're in your drupal root folder..open powershell (anyother cli) and do '
composer require drupal/console
'after this add.
'C:\<path to your drupalwebsite root folder>\vendor\bin'
to your paths Environment variables
and you have composer installed: Remember to install and add composer to path variables for every local drupal installation.

Resources