I need to run composer on my ddev project and don't have it on my Windows machine. For example, the project requires a composer install
before startup. How can I use composer in this environment, especially on Windows?
Updated 2023-08-07 with ddev composer
command
There are several ways to run composer for your project, see docs
ddev composer
and ddev composer create
commands. These run composer inside the container, so you're guaranteed to get composer behavior that matches the in-container hosting environment.
ddev composer require swiftmailer/swiftmailer
ddev composer update
ddev composer install
ddev composer create drupal/recommended-project
Note that ddev composer create
is not exactly the same as composer create-project
so you don't have to understand complexities of the underlying filesystem. There are many examples in the docs.
Nothing here prevents you from using any composer technique that you're comfortable with, but this is a great way to get predictable on-linux in-container composer builds. It should be hugely important for people using traditional Windows, where composer is less available and has some unpredictable behavior.
ddev composer install -d /var/www/html
will do a composer install in the root of your repository, exactly the same as ddev composer install
. You can also do ddev ssh
and operate on the command line in the container. hooks:
post-start:
- composer: install