How to setup Drupal on Codio in minutes
How to setup Drupal on Codio in minutesSep 4th 2015
Installing Drupal on a *local development environment, for the first time, can be a baffling process!
Place this file here, change that setting, connect to some server, something to do with lamp stack etc?
Luckily, with the emergence of cloud based IDEs (integrated development environments) like Cloud 9 and Codio, we can now make this process much simpler, accessible and efficient. For more on Cloud based IDEs, see Martin's post Coding In The Cloud.
In this post I'm going to guide you through a few steps, specific to getting Drupal up and running on Codio in minutes.
*This tutorial assumes that you are comfortable with using a terminal based interface and have a working knowledge of Drupal using the LAMP server stack.
Install Drupal on Codio in minutes
Step 1 - Register with Codio it's FREE!
Before anything else you need to visit codio and sign up to a free account.
Step 2 - Create a project
Once you have a Codio account, visit the dashboard page and choose New Project in the top right corner.
For the available starting point options, choose LAMP.
This will setup a new Codio 'box' - A unique server instance for use with our project, which contains it's own LAMP stack, a new blank MySQL database and an integrated text/code editor.
Add a name and a description for our project, then select the visibility (private projects are a premium feature in Codio so leave it set to public unless you fancy paying for a subscription). Once you're happy, click create.
Step 3 - Install Server Utilities And Software
Just like Blue Peter, here's a script we made earlier
To complete your 'stack' you will need to add various add-on utilities 'to get all the bits talking to each other', these include: php5, php5-apache2, php5-pdo-mysql, php5-gd, mysql and composer.Also before installing Drupal itself, we need to install drush, - an invaluable Drupal developer's shell/utility app which is full of useful commands for interacting with Drupal via the terminal, giving you the ability to install and enable modules/themes/profiles etc, clear site caches and various other tasks. (you can learn more about drush here).
You could install all of these parts manually, but as we are just trying to get to a stage where you can see and use Drupal quickly, I have provided a script below which automate the entire process for us.
So... Open the Codio terminal by going to 'Tools > Terminal' in the main menu and paste the following snippet of code and hit enter:
wget -O - https://raw.githubusercontent.com/sfurley1/codiosetup/master/codiosetup | bash
*To understand what processes exactly are being automated, by the above script, below is a long-hand version of what is happening in the background.
#A bash script is a text file that contains a sequence of commands for a UNIX-based operating system.
#! /bin/bash
#This installs all the parts you need for Drupal to work
parts install php5 php5-apache2 php5-pdo-mysql php5-gd mysql composer
#Installing drush
composer global require drush/drush:6.*
#Start up the apache server
echo "parts stop apache2 mysql ; parts start apache2 mysql" > ~/startup.sh
chmod +x ~/startup.sh
~/startup.sh
#Create a random database password and grant user permissions to the database
pass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
mysql -u root -e"create database codio; create user codio@localhost identified by '$pass'; grant usage on *.* to codio@localhost; grant all privileges on codio.* to codio@localhost"
#Print out the new username and password so a user can view it and use it
echo "user: codio"
echo "pass: $pass"
echo "db: codio"
IMPORTANT!
When the script above has stopped running, look for the database username and password entries in the code. COPY THE PASSWORD! and paste into a text file or similar, we'll need it later.
Step 4 - Download Drupal Core
Close the terminal and reopen it again. - This will refresh our Codio box cache and let it know drush exists.
Let's install Drupal which will be easy with drush.
-
Still in the terminal, move up a folder to the root of our box by using the following command:
cd../
-
Now in the root we can install Drupal. The following command downloads the latest version of Drupal core and renames the parent folder from 'Drupal' to match our Codio environment's 'workspace' folder. Don't worry, this has no baring on you Drupal site name, it just prevents all our Codio urls being appended with /drupal.
drush dl drupal --drupal-project-rename=workspace
-
CD back into our workspace folder (the folder which now contains our Drupal files and the root of our running Codio box):
cd workspace
Step 5 - Giving Drupal Access To Our Codio Database
Nearly there.
You now have our Drupal files all downloaded and ready to go. The only small bit left to do is update the database file.
- In the folder tree on the left of the Codio interface, go to workspace > sites > default.
- Make and in-place copy of the file default-settings.php and rename the new copy to settings.php.
- Our default folder should now containing both default-settings.php and the new settings.php. We do this so that we always have an unedited copy as back-up, should we mess up our custom copy.
- Open the new settings.php file.
- We're going to tell Drupal which database to use and which login credentials to use when accessing it. These settings are for our local environment only. When moving our site to a production environment (or to any other environment for that matter) we will need to update to reflect the database which we want the site to access. Here we're on our Codio box, so we're using our 'codio' database.
- Copy the code below and paste it in, below line 216.
- Replace the password for the one you copied earlier in step 3, then save the file (Ctrl + S). The database name and username will always be 'codio'. It's fine to leave these as they are, as on Codio there is a completely unique LAMP stack per project, therefore no chance of conflicting database names.
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'codio',
'username' => 'codio',
'password' => 'your_password_here',
'host' => 'localhost',
'prefix' => 'main_',
'collation' => 'utf8_general_ci',
);
Step 6 - Install Our Drupal Site
Now to tie all the bits together and actually install the Drupal site from the file downloaded earlier.
- From the top Codio menu, click the dropdown next to project index (static) and select box URL.
- The browser will open a new tab with the new box setup and running.
- Notice the unique server alias url in the address bar (Codio will auto-generate one at random so it could be called literally anything).
- In the address bar, after the url add 'install.php' - for example http://spain-boxer.codio.io:3000/install.php
- Hit enter.
That's it, now just run through Drupal's normal installation process and you are good to go!
Conclusion
Installing Drupal can now be a (relatively) straight forward process without any faff. Plus the joy of Codio and many other cloud based IDE's is you can access them, wherever you have an Internet connection.
Super Charged Install Option
Its important to understand the steps above, but if you are in a real rush and need Drupal set up on Codio as quickly as possible, I'm also including the below automation script, which will automatically (duh!) take care most of these steps for you, including creating and editing our settings.php:
wget -O - https://raw.githubusercontent.com/sfurley1/codiosetup/master/codiosetupmore | bash
To use this speedy set-up script do the following:
- Create a new Codio project only this time select default rather then LAMP.
- Open terminal and run the code above
- Skip to Installing our site like in step 6 - 'Install our Drupal Site'
* Foot Note
Although of course technically cloud based IDEs aren't 'local' to your specific machine (a possible advantage actually, as you can access them from any machine with an internet connection and the correct login), but here were are using Codio as 'local' development environment as opposed to a live production server.
Written by: Steve Furley, Front-end Developer
Microserve is a Drupal Agency based in Bristol, UK. We specialise in Drupal Development, Drupal Site Audits and Health Checks, and Drupal Support and Maintenance. Contact us for for further information.