Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Installation

Drupal is installed through Composer — the program that downloads PHP packages. Composer creates the project folder, downloads core and later updates it and the modules.

What you need

  • PHP 8.3 or newer with the pdo, gd, mbstring, xml extensions;
  • Composer 2;
  • a database: MySQL, MariaDB, PostgreSQL or SQLite.

Creating the project

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

The site folder now holds the composer.json file, the vendor folder with packages and the web folder — the root of the future site. All commands in the course are run from the site folder.

Installing Drush

Drush is a console program for managing the site. It is added to the project as an ordinary package:

composer require drush/drush

The program appears at vendor/bin/drush.

Installing the site

Create an empty database, for example drupal, and run:

vendor/bin/drush site:install standard --db-url=mysql://root:secret@localhost/drupal --account-name=admin --account-pass=admin

standard is a set of starting settings: it already contains the Article content type the course needs. --db-url holds the database user, password, server and database name. The command creates the tables and the admin administrator.

SQLite is enough for a learning project — then no separate database server is needed:

vendor/bin/drush site:install standard --db-url=sqlite://sites/default/files/.ht.sqlite --account-name=admin --account-pass=admin

Starting

vendor/bin/drush runserver

The site opens at http://127.0.0.1:8888. Log in at /user/login with the name admin and the password admin.

Development mode

Drupal caches templates and finished pages, so changes are not visible at once. During development this is switched off in the panel: Configuration → Development → Development settings, the address /admin/config/development/settings. Tick "Do not cache markup" and "Twig development mode".

Detailed error output is switched on at Configuration → Development → Logging and errors: choose "All messages".

Common mistake

The site root is the web folder, not the project folder. If the web server points at site, visitors get access to vendor and composer.json, and the site does not open. And the other way round: composer and vendor/bin/drush are run from site, not from web.

Thanks for reading!

Donate to the site — we work hard for you.