Home Development Tools composer Introduction to configuration information in composer.json

Introduction to configuration information in composer.json

Oct 12, 2019 pm 02:11 PM
composer

Introduction to configuration information in composer.json

Config

The following is a tutorial column using the composer command Let me introduce you to the configuration-related information in composer.json.

process-timeout request process timeout setting

The default request timeout is set to 300 seconds. Like when using Git for Clone operations, Composer can continue until the request times out. Run until installation is complete. If your network speed is not fast enough, or there is a lot of content to be loaded, you can set the timeout higher.

use-include-path Use include path settings

The default setting is false. If set to true, the Composer autoloader will automatically find classes included in the PHP path.

preferred-install installation preference settings

The default setting is auto mode, which can be set to source, dist or auto mode. This option allows you to set Composer to your preferred mode. For more precise settings of installation preferences, hash mode can be used.

{
    "config": {
        "preferred-install": {
            "my-organization/stable-package": "dist",
            "my-organization/*": "source",
            "partner-organization/*": "auto",
            "*": "dist"
        }
    }
}
Copy after login

Please note: The order in which option modes are set is important. The precise setting mode should be used before the broad setting mode, so that the precise setting mode will take effect. In global and package settings, string setting items are converted to * mode when setting using a mix of strings and hashes.

store-auths

The action taken after the authentication pop-up box, there are three options:

true to store authentication information forever;

false does not store authentication information;

"prompt" will require re-authentication every time, this is the default option.

github-protocols

Default is ["https", "ssh", "git"]. Priority list of protocols used when cloning from github.com. The git protocol is not an encrypted transmission, so only when the secure-http option is set to off, the git protocol will be used first for cloning. If you want to set the remote Push URL to use the HTTPS protocol instead of the SSH (git@github.com:...) protocol, you can just set ["https"] so that Composer will stop rewriting the Push URL to the SSH protocol.

github-oauth

A list of domain names and Oauth Keys. For example: using {"github.com": "oauthtoken"} as the value of this option will use oauthtoken to access private repositories on github and bypass IP-based API usage. Click here for information on how to obtain an OAuth token for GitHub.

gitlab-oauth

A list of domain names and Oauth Keys. For example: using {"gitlab.com": "oauthtoken"} as the value of this option will use oauthtoken to access private repositories on GitLab. Please note: If your code is not hosted on gitlab.com, you also need to configure this parameter - gitlab-domains.

gitlab-token

A list of domain names and Private Tokens. For example: Using {"gitlab.com": "privatetoken"} as the value of this option will use privatetoken to access private repositories on GitLab. Please note: If your code is not hosted on gitlab.com, you must also specify this parameter - gitlab-domains.

disable-tls

Default is false. If set to true, all HTTPS URLs will be replaced with HTTP and network layer encryption will not be used. Enabling this option may cause security risks, so it is not recommended. A better way is to enable the php_openssl extension in php.ini.

secure-http

Default is true. If set to true, only HTTPS URLs are allowed in Composer. If you're really sure you need to use HTTP to access something, you can turn it off, but using a provider like Let's Encrypt to get a free SSL certificate will is a better choice.

bitbucket-oauth

A list of domain names and usernames. For example, use {"bitbucket.org": {"consumer-key": "myKey", "consumer-secret": "mySecret"}}. See for details on how to create a user in BitBucket.

cafile

The location of the authentication certificate in the local file system. In PHP 5.6 you should set this via openssl.cafile in php.ini, although in PHP 5.6 this will be obtained automatically.

capath

If the certificate file is not specified or the certificate is not found in that location, the system will look for a suitable certificate in the file specified by capath. capath must be a directory where a properly hashed encrypted certificate exists.

http-basic

A domain name and a list of usernames and passwords required for storage authentication. For example, using {"example.org": {"username": "alice", "password": "foo"}} as its value will cause Composer to use the specified username and password to authenticate example.org.

Note: Authentication-related settings such as http-basic and github-oauth can also be defined in the auth.json file, separate from composer.json. This way you can tell Git to ignore it, and each developer can store their own authentication credentials.

platform

Lets you disguise platform extensions (PHP and its extensions) to simulate a production environment and define your target platform in the settings. For example: {"php": "7.0.3", "ext-something": "4.0.3"}.

vendor-dir

The default is vendor. You can also install required dependencies in a different directory. $HOME and ~ in vendor and all *-dir directories below will be replaced with your HOME directory.

bin-dir

The default is vendor/bin. If a project contains executable files, they will be symlinked in this directory.

data-dir

The default in WIndows is C:\Users\\AppData\Roaming\Composer, in unix systems that comply with the XDG directory definition in $XDG_DATA_HOME/composer, in other unix systems it will be $home. Now it is only used to store old versions of composer.phar files in case of rollbacks. See COMPOSER_HOME for details.

cache-dir

The default in WIndows is C:\Users\\AppData\Local\Composer, in unix systems that comply with the XDG directory definition in $XDG_CACHE_HOME/composer, in other unix systems it will be $home/cache. Stores all cache files used by Composer. See COMPOSER_HOME for details.

cache-files-dir

The default is $cache-dir/files. ZIP archive that stores all expansion packs.

cache-repo-dir

The default is $cache-dir/repo. VCS repository that stores metadata of composer type repositories and svn, fossil, github, and bitbucket type repositories.

cache-vcs-dir

The default is $cache-dir/vcs. Stores files cloned from all git/hg type repositories to speed up installation.

cache-files-ttl

The default is 15552000 (6 months). Composer caches all files (zip, tar, ..) built by extension packs that it downloads. By default, it will be cleared if not used for 6 months. This setting allows you to change this expiration time in seconds or set it to 0 to disable it completely.

cache-files-maxsize

The default is 300MiB. Composer caches all files (zip, tar, ..) built by extension packs that it downloads. This is the maximum amount of space it allows cached files to occupy while it performs periodic garbage collection. Older or infrequently used caches will be cleared.

bin-compat

The default is auto. Determines the compatibility required for executable file installation. If set to auto, only .bat files will be installed on Windows. If set to full, in addition to .bat, the script files required by the unix system will also be installed. This is mainly to deal with the situation where Composer is executed and the system where the project is running is inconsistent.

prepend-autoloader

The default is true. If set to false, Composer's autoloader will not be preloaded into an existing autoloader. This can sometimes be used to fix problems caused by sharing with other loaders.

autoloader-suffix

The default is null. A string that will be used as a suffix for the Composer autoloader. If empty, a random set of strings will be generated.

optimize-autoloader

The default is false. If set to true, optimizations will always be performed when generating the autoloader.

sort-packages

The default is false. If set to true, the extension package names in the composer.json file will always be arranged in alphabetical order when executing the require command.

classmap-authoritative

The default is false. If set to true, the Composer autoloader will only load classes in the classmap. This option enables optimize-autoloader.

apcu-autoloader

The default is false. If set to true, the Composer autoloader checks APCu and uses it to cache found and not found classes when the extension is enabled.

github-domains

The default is ["github.com"]. A list of domain names to use in gitHub mode. This may be used by GitHub Enterprise.

github-expose-hostname

The default is true. If set to false, OAuth tokens created for accessing the Github API will have a date instead of a hostname.

gitlab-domains

The default is ["gitlab.com"]. A list of domain names for GitLab servers. This may be used if you use the gitlab repository type.

notify-on-install

The default is true. Composer allows a repository to define a notification URL to receive notifications when an extension package based on this repository is installed. This entry allows you to disable this behavior.

discard-changes

默认是 false 并且可以被设为 true,false 或 "stash"。此项允许你设置在升级过程中发生冲突时的默认行为。true 会放弃 vendors 中的更改,而 "stash" 尝试着去暂存以便于恢复。如果你的 CI 服务器或部署脚本可能会更改 vendors,那么可以使用该设置。

archive-format

默认是 tar。Composer 允许你设置在工作流需要创建特定格式压缩包时的默认压缩格式。

archive-dir

默认是 .。Composer 允许你设置在工作流需要创建特定格式压缩包时的默认压缩文件存储路径。也为了模块间的开发变得更加容易。

举个例子:

{
    "config": {
        "archive-dir": "/home/user/.composer/repo"
    }
}
Copy after login

htaccess-protect

默认是 true。如果设为 false,Composer 不会在 COMPOSER_HOME、cache、和数据目录创建 .htaccess 文件。

The above is the detailed content of Introduction to configuration information in composer.json. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Improve Doctrine entity serialization efficiency: application of sidus/doctrine-serializer-bundle Improve Doctrine entity serialization efficiency: application of sidus/doctrine-serializer-bundle Apr 18, 2025 am 11:42 AM

I had a tough problem when working on a project with a large number of Doctrine entities: Every time the entity is serialized and deserialized, the performance becomes very inefficient, resulting in a significant increase in system response time. I've tried multiple optimization methods, but it doesn't work well. Fortunately, by using sidus/doctrine-serializer-bundle, I successfully solved this problem, significantly improving the performance of the project.

Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Apr 18, 2025 am 09:24 AM

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

How to quickly build Fecmall advanced project templates using Composer How to quickly build Fecmall advanced project templates using Composer Apr 18, 2025 am 11:45 AM

When developing an e-commerce platform, it is crucial to choose the right framework and tools. Recently, when I was trying to build a feature-rich e-commerce website, I encountered a difficult problem: how to quickly build a scalable and fully functional e-commerce platform. I tried multiple solutions and ended up choosing Fecmall's advanced project template (fecmall/fbbcbase-app-advanced). By using Composer, this process becomes very simple and efficient. Composer can be learned through the following address: Learning address

Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundle Apr 18, 2025 am 11:48 AM

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

How to simplify email marketing with Composer: DUWA.io's application practices How to simplify email marketing with Composer: DUWA.io's application practices Apr 18, 2025 am 11:27 AM

I'm having a tricky problem when doing a mail marketing campaign: how to efficiently create and send mail in HTML format. The traditional approach is to write code manually and send emails using an SMTP server, but this is not only time consuming, but also error-prone. After trying multiple solutions, I discovered DUWA.io, a simple and easy-to-use RESTAPI that helps me create and send HTML mail quickly. To further simplify the development process, I decided to use Composer to install and manage DUWA.io's PHP library - captaindoe/duwa.

How to use Composer to resolve JSON Schema verification issues How to use Composer to resolve JSON Schema verification issues Apr 18, 2025 am 11:51 AM

I'm having a tricky problem when developing a Symfony-based application: how to effectively validate JSON data format. Initially, I tried using manual verification code, but this was not only complicated, but also error-prone. After some exploration, I discovered a Composer package called ptyhard/json-schema-bundle, which brought great convenience and efficiency to my project.

How to use Composer to improve the security of Laravel applications: Applications of wiebenieuwenhuis/laravel-2fa library How to use Composer to improve the security of Laravel applications: Applications of wiebenieuwenhuis/laravel-2fa library Apr 18, 2025 am 11:36 AM

When developing a Laravel application, I encountered a common but difficult problem: how to improve the security of user accounts. With the increasing complexity of cyber attacks, a single password protection is no longer enough to ensure the security of users' data. I tried several methods, but the results were not satisfactory. Finally, I installed the wiebenieuwenhuis/laravel-2fa library through Composer and successfully added two-factor authentication (2FA) to my application, greatly improving security.

See all articles