drupaloid is brought to you by Rudá Maia

Rudá Maia

How to publish a Drupal site on GitHub pages

08/04/2019 - Writen at drupaloid local Drupal installation.

This is going to be the first drupaloid content. I didn't want to pay for hosting to have my own Drupal blog and you probably don't want it too.

  1. Setup a GitHub repo.
  2. Setup a local php/mysql server for your site with a working drush. I recommend the Composer Template for Drupal projects.
  3. With your Drupal site running on your local environment, enable Tome Module.
  4. In your settings.php you are going to setup tome default directory as 'docs' in your repository root:
    $settings['tome_static_directory'] = '../docs';
  5. Run the drush command:  drush tome:static --uri=http://yourdomain.com
    Now you have a 'docs' directory in your repository root with a complete static copy of your drupal site.
    IMPORTANT: This is the folder Github Pages is going to serve as your Website, so, you don't want to change this folder name.
  6. Go the repository settings in Github and make the Github Pages source your 'docs' folder:

I have created a little deploy script to correct the CNAME removal problem that you get if you clear the 'docs' folder, and, to automatically generate and deploy the static copy.

  1. Create a file in your repository root ./scripts/publish_github
  2. Give permission to it using command chmod +x ./scripts/publish_github
  3. Open the file in your favorite editor:
    # Clear the 'docs' folder.
    rm -rf docs/*
    # Generate the static site using tome drush command.
    vendor/drush/drush/drush tome:static --uri=https://drupaloid.dev
    # Recreate the CNAME file that Github Pages use to identify your site custom domain.
    echo "drupaloid.dev" > docs/CNAME
    # Add the whole 'docs' folder for a new commit.
    git add docs
    git commit -m "static site deploy"
    # Push to the repo.
    git push


Read more