How To Move a Drupal Site From Gitpod.io To A Live Server
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:9.5 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
This article is very useful! Gitpod is a game changer.
Let’s assume I have my site live in a web server and my development site in gitpod and I have made a new section in my dev site. Meanwhile in the live site I have also modified pages. Which is the method you suggest to deploy the new section in the live server without losing the modified pages?
Thank you Rod, you rock!
Thanks for your kind comment. Gitpod is definitely a game changer!
So you’re now talking about the difference between Configuration Entities and Content Entities. You can synchronize configurations between sites, but not content.
Take a look under Configuration -> Development -> Configuration Synchronization (admin/config/development/configuration/full/export). You can export things like Content Types (but not content), Vocabularies (but not terms), Views etc. This is why I always use Devel on a dev/test site and not waste time creating real content.
Then import them on your production site.
There’s more information at https://www.drupal.org/docs/configuration-management/managing-your-sites-configuration. Definitely something you want to practice a bit first – start with a simple export (I usually do a view) and import – them move on to bigger ones.
Hope that helps
Thankyou Rod. I’ve been waiting so long for this, searching for a tutoral like this in every posible corners online and in forums all over the net. I cant understand why there is so little out there about this, it’s not a straight forward thing and for people like me who are not a computer genus it’s hard to figure out all steps here. You deserve a huge thanks for doing this, and I hope you keep up your good work with making tutorals here. Best regards JON
thanks for your kind words!
Yeah – it’s pretty amazing there’s not much more. It’s still a new tech so hopefully more coming. I have a couple more tutorials coming on this over the next bit…