How to Develop Locally in Drupal and Host Static Files on your Website
Background
Say you have an old website on Drupal 7 with plugins that don’t work with the latest versions of Drupal. You now cannot migrate over to Drupal 9 or 10 without doing a lot of manual work and or losing the functionality of your current plugins. If your requirements are still fulfilled by the old Drupal 7 website, there’s a solution to keep using it.
Summary of the post below:
- Install DDEV on WSL (Windows), then setup your Drupal 7 site inside DDEV (https://ddev.com).
- Migrate your existing Drupal site using Backup and Migrate Plugin (https://www.drupal.org/project/backup_migrate).
- Then use Static Generator plugin (https://www.drupal.org/project/static) to render static files and upload them to say Cloudflare Pages! (https://pages.cloudflare.com)
This way, you can keep updating content on the Drupal 7 system without any fear of being hacked or corresponding software becoming obsolete while still maintaining the website.
The software stack that makes it possible are WSL, Docker, DDEV and of course Drupal.
Steps
Install WSL2 with Ubuntu.
- Just follow this tutorial - https://www.drupal.org/docs/develop/local-server-setup/windows-development-environment/installing-drupal-with-ddev-in-wsl2-on-windows/installing-wsl2-ubuntu
Install Docker and DDEV
- Follow this tutorial until “Keep DDEV up to date” heading - https://www.drupal.org/docs/develop/local-server-setup/windows-development-environment/installing-drupal-with-ddev-in-wsl2-on-windows/installing-docker-ddev-drupal-in-wsl2
Install Drupal Project
- Under “Install a Drupal Project” heading - run the following steps from the above tutorial:
- mkdir sites
- cd sites
- mkdir my-drupal7-site
- cd my-drupal7-site
- ddev config –project-type=drupal7 –docroot=web
- ddev start
- Now, ddev composer create drupal/recommended-project:9.5.11 will fail. So skip that. We’ll go manual from here.
- Open my-drupal7-site/.ddev/config.yaml in an editor. For Drupal 7, change the “php_version” to “7.0”. Save it.
- Download and unzip your version of Drupal from drupal.org (https://www.drupal.org/docs/7/install/step-1-download-and-extract-drupal); use the “From the command line” instructions.
- After the extraction is complete, run ‘ddev launch’ in the browser. Grab the URL and add /install.php to its end to start the install. The database part is already setup so all you have to do is setup the first user (admin) account.
- You now have a locally working Drupal site.
Migration of the existing Drupal 7 site
- Install Drupal Backup and Migrate plugin. Export the database.
- Install Drupal Backup and Migrate plugin on your DDEV instance. Restore from the SQL database from your existing Drupal site using the Backup and Migrate plugin.
- Now copy over the contents (all files and folders) of the existing Drupal site into the DDEV one.
- Your DDEV instance should now be a clone of the existing one.
Note: If your existing Drupal site is less than 100MB gzipped, you can use the Backup and Migrate plugin to fully restore your existing website into DDEV.
Exporting to static site
- Follow this on your DDEV instance. (https://sanjayregmi.com/posts/create-static-website-using-cloudflare-pages)
Benefits to this approach of hosting a website
- Security Your CMS is not exposed to the internet, only static pages are loaded into your internet facing webserver.
- Stop endless cycle of upgrade You can keep using old software and why not if they’re serving your purpose!
- Cheaper hosting You can now host your site on a much cheaper plan because it’s all static content. There are free hosting options like Cloudflare Pages(https://sanjayregmi.com/posts/create-static-website-using-cloudflare-pages), Netlify, Github, Vercel to name a few.
💛