Set up a site on Bluehost for development

I started an account on Bluehost many years ago when I wanted to build a profile site. It's not the fastest, but it's cheap and reliable and there are upgrade options if needed. Full disclosure: I don't run any high traffic sites here and would recommend further research if heavy usage is expected.

Here's my quickstart guide for getting up and running with development.

Create a local drupal project with composer:

https://github.com/drupal-composer/drupal-project

composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction

Create a git repo in this directory and check in the files. There should be a .gitignore file that excludes the code managed by composer.

If you want to fire up this site locally, cd into the /web directory and run drush si --account-pass=admin.

This is also a good time to require any modules you want to include, via composer:

composer require drupal/admin_toolbar drupal/config_installer

(You can require multiple modules on one line)

Config Installer is a profile that will load Drupal config when you install a site. Otherwise, it will reject the config from a "different" site if the uuids don't match. We'll want this when deploying the site.

Export your site config with drush cex. Check this into git.

 

2. Set up subdomain and database on bluehost.

In the subdomains section, create a new one, named whatever you want, pointing to the default directory with the same name in public_html.

Use the database wizard to create a new database and user with all privileges. Hang on to the generated password, you'll need this to install Drupal.

 

3. Set up server git and web root directory.

First we're going to delete the directory created by Bluehost. It has some files we don't need since we're using Drupal to handle everything.

Instead, I created a ~/www directory for all of my websites, and create symlinks in ~/public_html to link to the directories. This allows me to have a web root in a subdirectory in my git repo, which is useful for keeping project files out of your web root.

Go ahead and create ~/www/SITENAME

Initialize a git repo within that directory.

CD into ~/public_html and symlink to your site:
ln -s ~/www/SITENAME/web SITENAME

It's important have the path to your webroot (not the repo) and use the same name you set in your subdomain config on Bluehost.

 

4. Push your site to the server.

Set up your git instance on the server as a local remote:

git remote add origin USER@URL:www/SITENAME.

Check out the current branch as dev. You can't push master directly to the server, since it's checked out there.

git checkout -b dev

Push dev to the server:

git push -u origin dev

 

5. Build the site on the server

Run Composer install: 
composer install --no-dev (more info on that flag here: https://www.drupal.org/docs/8/update/update-procedure-in-drupal-8)

 

6. Install the site via UI

Make sure to choose the Config Installer profile. Hope you remembered the password you made for the database :) 

 

Done!

 

Workflow

I do a lot of live development on the site, especially site building. When I first begin a project, I like to experiment and scaffold things out quickly so I can focus on the content and build up features around it. As a project matures, I'll do a lot more local dev and changes will go through QA before being released to production. However to move quickly in these early stages, I need to be able to pull the config down locally and push up changes to the code. To be specific, live site building = yes! live module development or theming = no! Late in the game it's no across the board.

One big caveat here is that I have to add new modules locally. Bluehost is capable of installing composer packages from a lock file, but it crashes when adding a new one. That's why I try to include the base modules I need for a typical site before I push up the initial site.

If I do need to work locally, I log into the server, export config, and check it into git. Locally, I pull that down and merge master into my dev branch, making sure that the dev branch was clean or had no forgotten/incomplete commits. Dev gets done, push up the dev branch, log into server and merge into master. Run composer install --no-dev, drush cex, and drush updb (drush cr if editing templates and code files).

That's pretty much it. It's not very sophisticated, but it gets you up and running quickly and there's room to refine from here.

Get in touch if you have any suggestions for improving this article, or any other tips for developing on Bluehost!