Home >Development Tools >composer >A brief introduction to Composer usage tips
The following column composer usage tutorial will give you a brief introduction to Composer usage skills. I hope it will be helpful to friends in need!
I recently used Composer, a tool for managing dependencies in the world's best language PHP. I took a few notes to make a memo. If there are any mistakes, please point them out.
Installation
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');"
The above code comes from the official website.
Partial installation
After the execution of the above code is completed, only the composer.phar file is downloaded, which can be used through php Execute composer.phar at any location.
Global installation
Global installation just installs composer.phar under PATH. It can be like the following:
sudo mv composer.phar /usr/local/bin/composer
domestic mirror Acceleration
Use the China full image provided by Composer Chinese website for acceleration.
Single project acceleration
Enter the project directory (that is, the directory where the composer.json file is located) and execute:
composer config repo.packagist composer https://packagist.phpcomposer.com
This command will add the image acceleration configuration at the end of the composer.json file:
"repositories": { "packagist": { "type": "composer", "url": "https://packagist.phpcomposer.com" } }
Global acceleration
Can be executed directly:
composer config --global repo.packagist composer https://packagist.phpcomposer.com
Configuration
Refer to the official configuration document.
Because composer, by default, will generate a .composer folder in the user's home directory to store configuration-related information, so we can configure these parts.
composer config --global data-dir /www/.composer composer config --global cache-dir /www/.composer # cache-files-maxsize 也可以稍微大一点, 还有缓存时间
Auth related
Gitlab token can be viewed at https://docs.gitlab.com/ee/api/README.html#oauth-2-tokens
Notes
When the type is configured as gitlab, github, etc., the authentication information will be selected for verification through the configuration in the .composer/auth.json file. If the Auth authentication related issues are not solved, you can use ordinary vcs such as git to use.
The above is the detailed content of A brief introduction to Composer usage tips. For more information, please follow other related articles on the PHP Chinese website!