Our Drupal 9 Explained course is move effective when every student does the work along with the videos. Currently, if someone doesn’t have a Drupal environment to practice on, we recommend a Github repository that creates a site at Gitpod.io (https://github.com/imrodmartin/ddev-gitpod).
This repository is a one-click installation of DDEV, Composer, Drush and Drupal 9 (at the time of this writing). It’s really an amazing environment that helps students learn Composer, Drush and Drupal along with our course and it’s completely free! (watch installation video at the link above)
But how can I move the site I build to a live server?
It’s really great to be able to build sites where no-one can see them until they’re ready! However, when you ARE ready, moving a Drupal site isn’t all that straightforward!
What you’ll need:
- A site ready to be transferred at gitpod.io
- SSH or Terminal access at the web host you want to move the site to (We’ll be using HiVelocity as our web host for this tutorial). If you’re on a shared host such as GoDaddy etc, you won’t be able to move your Drupal site via this tutorial. Access to Composer is required.
- A fresh domain/sub-domain, an empty database (usually MySQL) and a way to access them – usually CPanel.
- It’s beyond the scope of this tutorial to explain setting up domains, sub-domains, databases and all the things you’ll need at your live server. If you have questions, please contact your host: hosting environments can be very different one to another.
(If you’d rather watch a video of the following steps – head to the bottom of this post.)
- Make sure the current site and all projects are up-to-date. Head over to Reports->Available Updates to determine if your site is completely current. If it’s not, use the following commands to update your site.
composer update "drupal/*" --with-all-dependencies
- Install the Backup and Migrate module
composer require drupal/backup_migrate
drush en backup_migrate
- Use Backup and Migrate to backup the database and public directory (download these to your computer).
- Go to Configuration->Development->Backup and Migrate->Backup->Quick Backup.
- Select Default Drupal Database and the Download option (these are the defaults).
- Click Backup Now.
- The database will be compressed and downloaded. This should be fairly quick.
- Change the Backup Source to Public Files Directory and click Backup Now. If you have a lot of files, this might take some time.
- If you have Private Files change the Backup Source to Private Files Directory and click Backup Now.
- Head over to your live web host and create a new database. Make sure you record the database, database user and password, you’ll need these later.
- Open a terminal window (in CPanel this should be available if you have enough access. If you don’t, you’ll need to request it from your web host before you proceed.
- Make sure your public_html (or root web directory) is completely empty.
- Create a new Drupal site:
composer create-project drupal/recommended-project public_html.
(replace public_html with the name of your root web folder). This will install Drupal in the root of your website inside a “web” folder.
- In your browser, navigate to the site folder and complete the Drupal site setup in the UI. This is where you’ll need the new database information.
- Install and enable ALL the modules from the gitpod site (including Core Modules)
- using composer and drush (if available)
- OR create a tar file of the modules from Gitpod.io, upload, expand, then enable with drush or the UI. On your Gitpod site, navigate to the modules folder in the terminal window and execute
tar -czvf mods.tar.gz contrib. Download the tar file, upload it to your live server and expand it in the /modules folder.
- If you have custom modules repeat the above :
tar -czvf mods.tar.gz custom
- Restore Database using Backup/Migrate. On your new live site, head over to Configuration->Development->Backup and Migrate->Restore. Upload your database.
- Restore Public Files
- If you’re using a custom theme on your Gitpod site, head back to the terminal, go to the Themes directory and compress the theme. ie: tar -czvf theme.tar.gz name_of_theme (replace name_of_theme). Download this file and upload it to the themes directory on your live server.
- Clear cache from the terminal:
drush cror go to: Configuration->Development->Performance->Clear all caches.
- IMPORTANT: if you used admin/admin as your user on the gitpod site – you should definitely update both: People->edit user 1->enter the current password, change the username and provide a secure password.
If you used the web directory, you’ll need to update the root of your website to point to the web folder.
This is definitely not a quick solution – there just isn’t one! Please comment below with any suggestions or changes that would make this more efficient!
System requirements for Drupal:
Using Composer to Install Drupal and Manage Dependencies: https://www.drupal.org/docs/develop/using-composer/manage-dependencies
How to create tar / zip files:
How to manually install Drush on a Webserver