Deploy a Drupal website to a shared host

If you’re a front-end developer, most likely you enjoy making sites. If you’re like me, you don’t enjoy deploying sites. That’s for the Dev Ops person at the company. But most of us don’t have our own Dev Ops person we can hand off a project to -- if only we all had our own private Dev Ops!! No, we have to deploy sites on our own.

Done infrequently enough, it feels clunky and takes extra time to relearn all the necessary steps over again each time.  But it's really not that hard. So I made a checklist of things needed to deploy a Drupal 8 site. In this case I’m deploying to a shared host (Dreamhost).

Drupal 8 website deployment checklist

You’ll need:

  • A hosting provider to host your site code and database
  • SSH access to your hosting server
  • A remote git server (github, gitlab, private server)
  • A Drupal website you’ve developed locally

You’ll also want to read about website deployment using git for an understanding of why we’re doing it this way.

 

Check environment requirements

Drupal 8 requires PHP 5.5.9 or newer. Drupal requirements suggest using at least 5.6. Make sure your web server is configured to use an appropriate version of PHP. Requirements are different for Drupal 7.

 

Add a new database at your hosting provider

Depending on the provider, this may be through the host’s UI or in phpMyAdmin. Or your database may be somewhere else entirely...that's for you to know.

 

Export the local development database and import it into the new server database

 

Push any recent changes from your local dev machine up to gitlab (or gitHub or wherever your remote git host is).

 

Clone the gitlab repo to your hosting server

SSH into the remote server. On a shared host there will typically be a directory for each domain you’re hosting. cd into the directory of the domain you’re deploying then clone the git repo here. Depending on your git deployment method you may clone your repo to somewhere else and symlink domainname.com directory to where you’re pulling your repo.

 

Rsync your files directory or directories

I’m not going to cover this step in detail, but this google search will help you

 

On the server, add a settings.local.php file in default directory

For security reasons we don’t add our database credentials to settings.php and track that file with git. We don’t want that information in our repo. Your server can have its own settings.local.php which Drupal will use to get database credentials and other settings specific to your live server. Add a settings.local.php file and add your db credentials there. Reference your local development file to copy/paste code formatting if necessary.

 

.htaccess edits (If necessary)

How do you make the shared server serve your Drupal site from domainname.com/reponame/src instead of its default location: domainname.com/index.html ? There are a couple ways to do this and it depends on your directory structure. I wrote a guide on changing the directory root on shared hosting.

 

Change your passwords

Change all the passwords you set during local development because they’re probably weak and one of them is probably 'password'.

 

Now you should have all your necessary files, images and database data in place. And your site is up and running. It feels good, right? Nice work!