Install Drupal 8 with Composer and Drush 9 on Centos7

Video using composer to download Drupal


  1. Install unzip
    • sudo yum install unzip
  2. Install git
    • sudo yum install git
  3. Install composer
    • sudo yum install composer
  4. Increase memory size on VM to 4GB or add Swap space
    • sudo fallocate -l 2G /swapfile
      sudo chmod 600 /swapfile
      sudo mkswap /swapfile
      sudo swapon /swapfile
  5. Create a directory under htdocs or /var/html to hold the install
    • Note a composer project will be setup in the directory you create, and drupal will be setup in a sub directory call web, the web directory is where your virtual machine should point.
  6. Create a database and user in MySQL
  7. Install Drupal and Drush with composer, if needed change the /var/www/drupal8 to the directory you created in step #5, this is a dev version of the composer config, but will install the latest stable version of Drupal
    • composer create-project drupal-composer/drupal-project:8.x-dev /opt/www/drupal8 --stability dev --no-interaction
  8. Install Drush Globally (so you can run it from any project)

    First, we’ll install Drush with Composer.

    $ composer global require drush/drush

    alias drush='/home/username/.config/composer/vendor/drush/drush/drush'

  9. How to Maintain a Drupal 8 Site Built with Composer  

Preparing to Update Drupal Core

You’ll need to follow the steps below to update your core files if you installed Drupal using the Composer build.

  • Run composer update drupal/core --with-dependencies to update Drupal Core and its dependencies.
  • Run git diff to determine if any of the scaffolding files have changed. Review the files for any changes and restore any customizations to .htaccess or robots.txt.
  • Commit everything all together in a single commit, so web will remain in sync with the core when checking out branches or running git bisect.
  • In the event that there are non-trivial conflicts in step 2, you may wish to perform these steps on a branch, and use git merge to combine the updated core files with your customized files. This facilitates the use of a three-way merge tool such as kdiff3. This setup is not necessary if your changes are simple—keeping all of your modifications at the beginning or end of the file is a good strategy to keep merges easy.
  1. Copy drupal8/web/sites/default/default.settings.php settings.php
  2. Enable writting to settings.php disable SElinux on Centos7
    • # setsebool allow_httpd_anon_write=1
      # chcon -t public_content_rw_t sites/default sites/default/settings.php sites/default/files
  3. Make directory drupal8/web/sites/default/files
  4. Change permissions on settings.php and files to be writable by apache
  5. Change permissions on the directory to allow apache to create files in your directory
    • sudo chgrp apache drupal8 
  6. Create a database and user for drupal
  7. Add apache virutal site config for recipes site to /etc/httpd/conf.d
    • sudo vim /etc/httpd/conf.d/recipes.conf
    • Add the following:
    • <VirtualHost *:80>
          DocumentRoot "/opt/www/recipes/web/"

          <Directory "/opt/www/recipes/web/">
              Options +Indexes +FollowSymLinks
              AllowOverride All

          ErrorLog /var/log/httpd/recipes-error_log
          CustomLog /var/log/httpd/recipes-access_log combined
          # Possible values include: debug, info, notice, warn, error, crit
          LogLevel warn

      <VirtualHost *:443>
          SSLEngine on
          SSLCertificateFile  /etc/letsencrypt/live/
          SSLCertificateKeyFile /etc/letsencrypt/live/

          DocumentRoot "/opt/www/recipes/web/"

          <Directory "/opt/www/recipes/web/">
              Options +Indexes +FollowSymLinks
              AllowOverride All

          ErrorLog /var/log/httpd/recipes-error_log
          CustomLog /var/log/httpd/recipes-access_log combined
          # Possible values include: debug, info, notice, warn, error, crit
          LogLevel warn

      # ServerName: The domain that should match for this virtual host configuration. This should be your domain name.
      # ServerAlias: All other domains that should matchfor this virtual host as well, such as the www subdomain.
      # DocumentRoot: The directory from which Apache will serve the domain files.
      # Options: This directive controls which server features are available in a specific directory.
      # -Indexes: Prevents directory listings.

  8. Restart apache 
    • sudo systemctl restart httpd
  9. localhost/drupal8
  10. Check for errors
    • sudo tail /var/log/httpd/error_log
    • if running SSL check sudo tail /var/log/httpd/ssl_error_log
  11. Select language
    • English
  12. Choose profile
    • Demo: Umami Food Magazine (Experimental)
  13. Enter database, user, and password
  14. Install
  15. Configure site
    • Set site name
    • Create admin user
    • Select country and timezone
    • Save
  16. Login at: http://localhost/drupal8/web/user/login
  17. To add modules to drupal change to the project directory, the one above the /web
    • composer require drupal/<modual_name>
    • drush en <module_name>

To Update Drupal Core

  1. Check to see if outdated
    • composer outdated "drupal/*"
  2. Update Drupaldirectory/composer.json if needed (moving from drupal 8.6 to 8.7) Note: If you are upgrading major version i.e. from 8.5 to 8.6, you need to edit composer.json and replace "~8.5.x" with "^8.6.0" for drupal/core and webflo/drupal-core-require-dev.  I have also been told you can replace 8.6.0 with 8.6, but I have not tested that yet.
    • vi composer.json
    • replace "~8.5.x" with "^8.6.0" for drupal/core
  3. Update drupal/core with dependencies
    • composer update drupal/core --with-dependencies
  4. Update drupal and webflo
    • composer update drupal/core webflo/drupal-core-require-dev --with-dependencies
  5. To allow upgrade to Drupal 8.7.6 had to use this command as webflo is still behind
    • composer update drupal/core webflo/drupal-core-require-dev --with-dependencies 
  6. Update the database
    • drush updatedb
  7. Cache Reset
    • drush cr


This is a list of common pitfalls on using Composer, and how to avoid them.

To display the dependency tree, browsing that might help you determine what requires the packages that need to be updated and inform a decision. You also might find useful, it fixes core dependencies to known good versions which might help you update with more confidence.

  • composer show --tree 

To figure out which dependency was blocking my Drupal core upgrade using the Composer command:

  • composer prohibits drupal/core:8.5.0


Since symfony/config (a dependency of drush and drupal console), I needed to run 

  • composer update drupal/core symfony/config --with-dependencies

I still have no idea how I could've figured out I just needed to add symfony/config in the update command (vs adding all the other symfony components)... but if I do, I'll try to update this answer with that information so others can benefit in the future!