:rocket: Composer template for Drupal projects. Quick installation via "composer create-project drupal-composer/drupal-project"
This project template provides a starter kit for managing your site
dependencies with Composer.
[!IMPORTANT]
Drupal 11 branch is available!
web
directory.vendor/autoload.php
is used instead ofweb/vendor/autoload.php
provided by Drupal core.drupal-module
) will be placed in web/modules/contrib
directory.drupal-theme
) will be placed in web/themes/contrib
directory.drupal-profile
) will be placed in web/profiles/contrib
directory.settings.php
and services.yml
.web/sites/default/files
directory.vendor/bin/drush
..env
file.[!NOTE]
The instructions below refer to the global Composer installation.
You might need to replacecomposer
withphp composer.phar
(or similar)
for your setup.
Create your project:
composer create-project drupal-composer/drupal-project:10.x-dev some-dir --no-interaction
The composer create-project
command passes ownership of all files to the
project that is created. You should create a new Git repository, and commit
all files not excluded by the .gitignore
file.
Use composer require
to include and download dependencies for your project.
cd some-dir
composer require drupal/devel
By default, this project is set to install only stable releases of dependencies,
as specified by "minimum-stability": "stable"
in composer.json
. If you need
to use non-stable releases (e.g., alpha
, beta
, RC
), you can modify the
version constraint to allow for such versions. For instance, to require a beta
version of a module:
composer require drupal/devel:1.0.0-beta1
Alternatively, you can globally adjust the stability settings by modifying
composer.json
to include the desired stability level and explicitly allow it:
{
"minimum-stability": "beta",
"prefer-stable": true
}
This configuration ensures that stable releases are preferred, but allows the
installation of non-stable packages when necessary.
You can manage front-end asset libraries with Composer thanks to the
asset-packagist repository. Composer will detect
and install new versions of a library that meet the stated constraints.
composer require bower-asset/dropzone
The installation path of a specific library can be controlled by adding it to
the extra.installer-paths
configuration preceding web/libraries/{$name}
.
For example, the chosen
Drupal module expects the chosen
library to be
located on web/libraries/chosen
, but composer require npm-asset/chosen-js
installs the library into web/libraries/chosen-js
. The following configuration
overrides installation it into the expected directory:
{
"extra": {
"installer-paths": {
"web/libraries/chosen": [
"npm-asset/chosen-js"
],
"web/libraries/{$name}": [
"type:drupal-library",
"type:npm-asset",
"type:bower-asset"
]
}
}
}
For more details, see https://asset-packagist.org/site/about
This project will attempt to keep all of your Drupal Core files up-to-date; the
project drupal/core-composer-scaffold
is used to ensure that your scaffold files are updated every time drupal/core
is updated.
If you customize any of the “scaffolding” files (commonly .htaccess
),
you may need to merge conflicts if any of your modified files are updated in a
new release of Drupal core.
Follow the steps below to update your Drupal core files.
composer update "drupal/core-*" --with-dependencies
to update Drupal Core and its dependencies.git diff
to determine if any of the scaffolding files have changed..htaccess
or robots.txt
.web
will remain incore
when checking out branches or running git bisect
.git merge
to combine theComposer recommends no. They provide argumentation against but also
workarounds if a project decides to do it anyway.
The Drupal Composer Scaffold
plugin can download the scaffold files (like index.php
, update.php
etc.) to
the web
directory of your project. If you have not customized those files you
could choose to not check them into your version control system (e.g. git).
If that is the case for your project, it might be convenient to automatically
run the drupal-scaffold plugin after every install or update of your project.
You can achieve that by registering @composer drupal:scaffold
as post-install
and post-update
command in your composer.json
:
"scripts": {
"post-install-cmd": [
"@composer drupal:scaffold",
"..."
],
"post-update-cmd": [
"@composer drupal:scaffold",
"..."
]
},
If you need to apply patches, you can do so with the
composer-patches plugin included
in this project.
To add a patch to Drupal module foobar
, insert the patches
section in the
extra
section of composer.json
:
"extra": {
"patches": {
"drupal/foobar": {
"Patch description": "URL or local path to patch"
}
}
}
There are 2 places where Composer will be looking for PHP version requirements
when resolving dependencies:
require.php
version value in composer.json
.config.platform
version value in composer.json
.The purpose of require.php
is to set the minimum PHP language requirements
for a package. For example, the minimum version required for Drupal 10.0 is
8.0.2
or above, which can be specified as >=8
.
The purpose of config.platform
is to set the PHP language requirements for the
specific instance of the package running in the current environment. For
example, while the minimum version required for Drupal 10 is 8.0.2
or above,
the actual PHP version on the hosting provider could be 8.1.0
. The value of
this field should provide your exact version of PHP with all 3 parts of the
version.
This project includes drupal/core
which already has require.php
added. Your
would inherit that constraint. There is no need to add require.php
to your
composer.json
.
config.platform
is a platform-specific. It is recommended to specify
config.platform
as a specific version (e.g.8.1.19
) constraint to ensure
that only the package versions supported by your current environment are used.
"config": {
"platform": {
"php": "8.1.19"
}
},