Home > Article > Development Tools > 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" } } }
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\be1cdaf6779910b92a0a47fc24e82b4f\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\be1cdaf6779910b92a0a47fc24e82b4f\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" } }
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!