Developing Drupal sites on your computer
This guide is primarily for people who participated in the Digital Democracy Workshops. During the workshops, Drupal 8 sites were created on cPanel using Installatron.
To download your site and continue to work on it on your computer, you will need three things:
- A downloaded copy of your site with the site files and the database (we’ll use Backup and Migrate)
- Software on your computer to run the code files and database (we’ll use Acquia Dev Desktop)
- Software to open and edit code files (there are lots of free & open source options available - the example uses Sublime Text)
Downloading your site with Backup and Migrate
The easiest way to download your site is by using the Backup and Migrate module. Download the latest Drupal 8 tar.gz file, then log on to your site and install the module - Extend > Install new module. (Remember to tick the box on the module list to complete the install process.)
Once installed, go to the Backup and Migrate module screens - Configuration > Development > Backup and Migrate.
Select Entire site as Backup Source and Download as Backup destination. Click Backup now. This will download your code files and database as a tar.gz file. You now need to install Acquia Dev Desktop to run the site.
Running your site on your computer with Acquia Dev Desktop
(Once Dev Desktop is installed, you can use it to install Drupal on your computer or to run the downloaded site.)
Download Acquia Dev Desktop and follow the install process.
This will create a devdesktop folder on your computer (you can specify where you want this folder to be during the install process).
Move your downloaded site into the devdesktop folder and open the g.zip file. The folder will contain a docroot folder with all your code files and database.sql (your database). You will need to be able to find and select both during the import process.
Return to Dev Desktop and click ‘Start with an existing site located on my computer’. (The options should appear automatically on install, or you can click the + sign at the bottom left to bring up the options.)
Click ‘Change’ to select your local codebase folder. Important: This is the docroot folder not the top level unzipped folder.
Give your site a local site name.
Select PHP 7.1.12 (versions of PHP beginning with 5 will not be supported from March 2019).
For database, select ‘Start with MySQL database dump file’ and then use ‘Browse’ to select database.sql.
Click OK. A warning is likely to appear. Click Yes to proceed.
Click the local site link to visit your site.
If you see the Drupal install screen, it is likely your database is not being found.
This is because easy install options (like Installatron) often add a prefix to database table. If this is the case, you will need to add a line of code to one of the code files – setting.php.
Editing code files with Sublime text
(There are lots of other free and open source options available, just search for free code editors)
Download the current version of Sublime Text and follow the installation process.
Find settings.php and open it using Sublime Text.
Scroll all the way down to the bottom of the page and paste the following line of code as the very final line.
$databases['default']['default']['prefix'] = 'drup_';
Make sure the prefix name after the equals sign matches the prefix name listed above. If it doesn’t match, change it to match (make sure it is exact, including any underscores, and that you don’t delete the apostrophes around the name). NB If no prefix is named above, you won’t need to add any code.
Save the file (you will probably need to click to 'Overwrite' the existing file).
Return to Dev Desktop and click again on the Local site link. Your site should now load.
Many thanks to SOMDUG, Somerset Drupal User Group for finding the prefix problem and writing the code to solve it!
If you’re near Glastonbury and continuing with Drupal, they have great Meetups every month. You can sign up at https://www.meetup.com/DrupalSomerset/