Drupal Site Quickstart

By Matthew Davidson, 4 September, 2022

Works with Drupal: ^8 || ^9

Create Database and User

mysql -u [user] -p

Where [user] has ALL PRIVILEGES globally

CREATE DATABASE [dbname];
GRANT ALL PRIVILEGES ON [dbname].* TO [dbuser]@localhost IDENTIFIED BY '[password]';
FLUSH PRIVILEGES;

Install Drupal Core from Composer

See Using Composer to Install Drupal and Manage Dependencies.

cd /var/www/
mkdir [dirname]
composer create-project drupal/recommended-project [dirname]

Install Drupal Core from a Git Repo You've Already Created*

* See below.

cd /var/www/
git clone [repo URI]

Rename this directory as required.

cd /var/www/[dirname]
composer i

Configure Apache

Config file template:

<VirtualHost *:80>
        ServerAdmin [you@domain]
        ServerName [fqdn]
        #ServerAlias www.[fqdn]
        
        RewriteEngine on
        RewriteCond  %{HTTP_HOST}  !^[fqdn]          [NC]
        RewriteCond  %{HTTP_HOST}  !^$
        RewriteRule  ^/(.*)        http://[fqdn]/$1  [L,R]

        #Uncomment if production server with HTTPS
        #RewriteCond %{SERVER_NAME} =[fqdn] [OR]
        #RewriteCond %{SERVER_NAME} =[fqdn]
        #RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

  
        DocumentRoot /var/www/[dirname]/web
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/[dirname]/web>
                RewriteEngine on
                RewriteBase /
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

</VirtualHost>

 

Drupal initial setup

cd /var/www/[dirname]
mkdir -p config/sync
mkdir db
cd /var/www/[dirname]/web/sites/default/
mkdir files
cp default.settings.php settings.php

Set this value in settings.php:

$settings['config_sync_directory'] = '/var/www/[dirname]/config/sync';

Also set trusted hosts.

sudo chown www-data:www-data files/ settings.php

Run Drupal installer

sudo chown [you]:staff settings.php
sudo chmod 664 settings.php
composer require drush/drush drupal/devel drupal/admin_toolbar

See also Drush Launcher.

sudo -u www-data drush en devel admin_toolbar media_library layout_builder

(Running as www-data because media module needs to create a directory in 'files'.)

SSL Certificate

sudo certbot --apache

(On live sites only, obviously.)

[Todo: git stuff.]

Database

Backup

drush sql:dump | gzip > /var/www/[dirname]/db/[whatever].sql.gz

Restore

drush sql:drop
drush sqlq --file=/var/www/[dirname]/[whatever].sql.gz

Tags