search
HomeDevelopment ToolscomposerIntroduction to configuration information in composer.json

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\\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"
    }
}

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
This article is reproduced at:learnku. If there is any infringement, please contact admin@php.cn delete
Composer with AI: Code Suggestions and InsightsComposer with AI: Code Suggestions and InsightsApr 22, 2025 am 12:05 AM

ComposerwithAI is a tool that uses AI to improve the programming experience. 1) It provides real-time suggestions and bug fixes by analyzing code structure, syntax and pattern. 2) Advanced features include code refactoring, performance optimization and security checking. 3) When using, you can adjust the configuration, provide feedback and combine other tools to solve common problems.

Composer: An Introduction to the PHP Dependency ManagerComposer: An Introduction to the PHP Dependency ManagerApr 21, 2025 am 12:02 AM

Composer is a dependency management tool for PHP, which is used to manage libraries and packages required by projects. 1) It defines dependencies through composer.json file, 2) installs and updates using command line tools, 3) automates the dependency management process, improves development efficiency, 4) supports advanced functions such as dynamically adding dependencies and automatic loading, 5) Ensures consistency of the team environment through composer.lock file.

The Purpose of Composer: Managing Dependencies EfficientlyThe Purpose of Composer: Managing Dependencies EfficientlyApr 20, 2025 am 12:04 AM

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json and composer.lock files. 1. Create the composer.json file and run the composerinstall installation dependency. 2. Use composerrequire to add new dependencies. 3. Configure autoload to implement automatic loading of classes. 4. Use composerdiagnose to check the health status of the project. 5. Optimize dependency management: specify the package name update, use composerdump-autoload-o to optimize the autoloader, use composerinstall--no-d in the production environment

Composer and AI: New Possibilities in PHP DevelopmentComposer and AI: New Possibilities in PHP DevelopmentApr 19, 2025 am 12:03 AM

The combination of AI and Composer can improve PHP development efficiency and security. Specifically reflected in: 1. Dependency analysis and optimization: AI can predict dependencies and reduce conflicts. 2. Automated security checks: AI can identify security vulnerabilities, and it is recommended to update them. 3. Code generation and optimization: AI can automatically generate and optimize related code.

Using Dicr/Yii2-Google to integrate Google API in YII2Using Dicr/Yii2-Google to integrate Google API in YII2Apr 18, 2025 am 11:54 AM

VprocesserazrabotkiveB-enclosed, Мнепришлостольностьсясзадачейтерациигооглапидляпапакробоглесхетсigootrive. LEAVALLYSUMBALLANCEFRIABLANCEFAUMDOPTOMATIFICATION, ČtookazaLovnetakProsto, Kakaožidal.Posenesko

How to use Composer to resolve JSON Schema verification issuesHow to use Composer to resolve JSON Schema verification issuesApr 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.

Use Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundleUse Composer to solve the dilemma of recommendation systems: andres-montanez/recommendations-bundleApr 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 quickly build Fecmall advanced project templates using ComposerHow to quickly build Fecmall advanced project templates using ComposerApr 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

See all articles

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

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool