Skip to main content

Web: Drupal 8 - step-by-step setup using Composer and Drush

Submitted by Stefan Barsuhn on

While the official Drupal 8 setup guide is quite comprehensive, it is also a bit overwhelming. So here I'm sharing my steps:

Notes 

I'm on a Debian Linux Server with Apache2 and PHP 7.0 and assume that those are setup accordingly. 

I also assume that Composer and Drush are already set up in a globally accessible location, e.g. /usr/local/bin (I will write a later article that explains their setup.)

Information you need

  • <path>: subfolder into which composer should download the codebase
  • <youruser>: MySQL user with admin rights
  • <databasename>: Databasename that Drupal should use
  • <databaseuser>: MySQL user that Drupal uses to access <databasename> (you should use a separate databaseuser for every Drupal site!)
  • <databasepassword>: Password of <databaseuser>
  • <sitename>: Title of your new Drupal site (will appear in the Header section of your new site in the standard theme)
  • <adminname>: Username of your Drupal site admin account

Steps

  1. Create a directory on your server, e.g. /var/www/mydrupalsite
  2. cd into this folder and run: 
    composer create-project drupal-composer/drupal-project:8.x-dev <path> --stability dev --no-interaction 
    1. Note 1: stability dev simply allows you to use dev modules - the system still defaults to using stable modules and it does not mean that a non-stable release will be installed. This is also discussed here.
    2. Note 2: If your <path> is "productive" and you run the above command in folder /var/www/mydrupalsite then your codebase will be in /var/www/mydrupalsite/productive
  3. Create database:
    mysqladmin -u <youruser> -p create <databasename>
    mysql -u <youruser> -p
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER,CREATE TEMPORARY TABLES ON <databasename>.* TO '<databaseuser>'@'localhost' IDENTIFIED BY '<databasepassword>';
  4. At this step you have your database and you have your codebase - now you need to run the installer:
  5. cd into the directory created (in the example above: /var/www/mydrupalsite/productive)
  6. Run the following command:
    drush site:install standard --db-url='mysql://<databaseuser>:<databasepassword>@localhost/<databasename>' --site-name='<sitename>' --account-name=<adminname>
  7. When the command runs successfully, your admin password will be displayed
  8. Create a vhost in Apache under your preferred domain. Your DocumentRoot is the web-subfolder, in the example above: /var/www/mydrupalsite/productive/web
  9. Done! You can now login to your site using your admin password displayed in step 6.

I am going to explain the configuration of Drupal (installing modules etc.) in another article.