How to install Drupal 8 using Composer on a Linux server
First you need to create the site directory by navigating to the web root directory (ex: www) and run the following command
mkdir your_site_directory
Then navigate inside this directory
cd your_site_directory
Then run the following command to install Drupal via composer
composer create-project drupal/recommended-project sitename
Then after Drupal finishes installing the files you need to prepare the settings.php file, by running the command
cp sitename/web/sites/default/default.settings.php sitename/web/sites/default/settings.php
The set the permission for settings.php to be writable by the install script
chmod 777 sitename/web/sites/default/settings.php
Then you need to create the files directory and make it writable by the web server
mkdir sitename/web/sites/default/files chmod 775 sitename/web/sites/default/files sudo chown apache:owner_username sitename/web/sites/default/files
Then you need to create a the mysql database and user and give the user full privilages on the database, you can do that anyway you want, we will do it through the terminal
To create a new database you need to login to mysql as root
mysql -u root -p
Then press enter and when prompted type your mysql root password, then run the following command to create a new database
create database database_name;
Then run the following command to create a database user and give it full privilages over the new database
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'@'localhost';
You then need to make sure that your domain or subdomain is pointing to the web directory inside your Drupal install folder
After you point the domain/subdomain correctly navigate to the url from the browser, you should see the following Drupal install screen
Choose your Language and Click Save and Continue, Then select Standard and click Save and Continue
Then enter the database name and user and password you created, then Click Save and Continue
Wait for the Install to finish
After Drupal finishes installing fill in the site information and click Save and continue to proceed to your Drupal site
Then you need to secure your settings.php file by running the following command
chmod 444 sitename/web/sites/default/settings.php
Then install the Admin Toolbar module so you can better manage the site, first navigate to the site directory that contains the composer.json file and run the following command
cd sitename composer require drupal/admin_toolbar
Then Navigate to Yoursite.com/admin/modules and Install the Admin Toolbar module
You also need to configure the Trusted hosts setting in your settings.php file, copy the commented lines and remove the comments and modify it to fit your site domain name
Then Navigate to Yoursitename.com/admin/reports/status and you should see an all green state
I hope you’ve enjoyed this tutorial and I look forward to helping you achieve more with Drupal