Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 37 ยท Concepts and Installation

Installing Drupal with Composer and Drush

Install Drupal with composer create-project, run the web installer or Drush site:install, add modules with Composer and log in for the first time.

Drupal is installed and maintained with Composer, PHP's package manager. The recommended project template pulls in Drupal core, its dependencies and a sensible folder layout in one command. After that you run the installer, either in the browser or with the command-line tool Drush. This lesson covers both, then shows how to add a module and handle the first login.

The commands below are real and run on your own computer; they cannot run in this page. Run them in the environment you prepared in System Requirements and a Local Setup.

Step 1: create the project

Terminal
composer create-project drupal/recommended-project my-site
cd my-site

Composer downloads core into web/core, creates web/index.php, web/sites/default, and puts libraries in vendor/. The generated composer.json is yours: you change it with composer require and commit it.

Add Drush, which you will use constantly:

Terminal
composer require drush/drush

Run Drush with vendor/bin/drush, or with ddev drush if you use DDEV.

Step 2a: install in the browser

Open the site's URL. The installer walks through:

  1. Choose a language.
  2. Choose an installation profile: Standard (common content types and settings), Minimal (almost nothing), or Demo content if offered.
  3. The requirements check; fix anything in red or yellow.
  4. Database configuration: type, name, user, password and host.
  5. Site configuration: site name, email, and the first administrator account (user 1).

Pick a long, unique password for user 1 and store it in a password manager. This account bypasses permission checks.

Step 2b: install with Drush

The same steps in one command:

Terminal
vendor/bin/drush site:install standard \
  --db-url='mysql://drupal:[email protected]/drupal' \
  --site-name='My Site' \
  --account-name=admin \
  --account-pass='use-something-long-and-random' \
  -y

Drush prints the account name and a success message. Use a separate, non-guessable password in real projects, and never put real passwords in shell history on shared machines.

To log in without a password the first time, generate a one-time link:

Terminal
vendor/bin/drush user:login

What the installer created

  • Tables in the database for entities, configuration, cache, users and sessions.
  • web/sites/default/settings.php with your database credentials.
  • A web/sites/default/files directory for uploads.
  • The default configuration for the chosen profile (content types, roles, a theme, blocks).

You will look at these files in The Drupal Project Structure and Configuration Management Basics.

Adding a module

Contributed modules also come through Composer. The name is drupal/<machine_name>.

Terminal
composer require drupal/pathauto
vendor/bin/drush pm:install pathauto -y

The first command downloads the code (and records it in composer.json and composer.lock); the second enables it. In older guides you may see a download from a zip file; avoid that, because Composer tracks dependencies and updates for you.

Updating

Terminal
composer update "drupal/core-*" --with-all-dependencies
vendor/bin/drush updatedb -y
vendor/bin/drush cache:rebuild

Composer fetches the new code, updatedb runs any database changes the new version needs, and the cache rebuild clears stale compiled data. Always back up first, and read the release notes.

Mapping the steps

flowchart LR
    A["composer create-project"] --> B["composer require drush/drush"]
    B --> C["site:install or web installer"]
    C --> D["drush user:login"]
    D --> E["composer require modules"]
    E --> F["drush pm:install"]

Code arrives through Composer; state in the database changes through Drush or the UI.

A pipeline you can simulate

The next stand-in models the install as a pipeline of steps that stop at the first failure. This is only a sketch of the control flow, not Drupal's installer.

JS Stand-in: an install pipeline

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Set dbReachable to true and rerun to see the whole pipeline finish.

First login and a sanity check

After installation, log in as the administrator and visit /admin/reports/status. Look for:

  • No red errors.
  • Trusted host patterns are configured (needed on production).
  • Cron has run or is scheduled.
  • The files directories are writable.

Common problems

  • "Unable to connect to the database": wrong host, port, or credentials; with DDEV use the values from ddev describe.
  • White screen: PHP error; check the web server error log and PHP's log.
  • Clean URLs not working: the web server's rewrite rules are not enabled.
  • Memory limit errors during install: raise memory_limit.

A second stand-in makes it easy to see which Composer command maps to which task. Again it is only a lookup table for learning.

JS Stand-in: task to command lookup

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which command creates a new Drupal project from the recommended template?

    The recommended-project template sets up core, dependencies and the folder layout.
  2. 2. What does drush user:login do?

    It prints a single-use URL that logs you in, which is handy after installation or when you forget a password.
  3. 3. Why use Composer to add modules instead of unzipping them?

    composer.json and composer.lock record exactly what is installed, so every environment can match.
  4. 4. What should you run after updating code to apply schema changes?

    updatedb runs the database update hooks that new code may require.

Summary

  • Create projects with composer create-project drupal/recommended-project.
  • Install through the browser installer or drush site:install; guard the user 1 password.
  • Add modules with composer require drupal/name and enable them with Drush or the Extend page.
  • After updates run drush updatedb and rebuild caches.

Next: The Drupal Project Structure