Make a database & user

Here is lots of information about creating the database for a Drupal site. Lately I use this shell script: create_drupal_db.sh

#!/bin/bash

EXPECTED_ARGS=3
E_BADARGS=65
MYSQL=`which mysql`

Q1="CREATE DATABASE IF NOT EXISTS $1;"
Q2="GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON $1.* TO '$2'@'localhost' IDENTIFIED BY '$3';"
Q3="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}"

if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: $0 dbname dbuser dbpass"
  exit $E_BADARGS
fi

$MYSQL -e "$SQL"

Find a web accessible home for the site

You can put the Drupal site in the web server's document root or your public HTML directory, or you can put a symbolic link there that points to the site.

bash> cd /kansas
bash> mkdir my_cute_cat
bash> echo "Hello World" > my_cute_cat/hello.txt
bash> cd /libweb/sites/development.library.cornell.edu/htdocs
bash> ln -s /kansas/my_cute_cat kitty

Now http://development.library.cornell.edu/kitty/hello.txt will show a page containing

Hello World 

You can delete /kansas/my_cute_cat/hello.txt and put the Drupal site where hello.txt was.

Use drush to grab Drupal

Replace the 'public' directory of your capistrano drupal development directory with a drupal install.

bash> cd <your capistrano dev directory>
bash> drush dl drupal-7.23
bash> rm -r public
bash> mv drupal-7.23 public

Use drush to install Drupal

Install drupal using your new database and user

bash> cd public
bash> drush si --db-url="mysql://dbuser:dbpass@localhost/dbname"
You are about to create a sites/default/files directory and create a sites/default/settings.php file and DROP all tables in your 'dbname' database. Do you want to continue? (y/n): y
No tables to drop.                                                                                                                        [ok]
Starting Drupal installation. This takes a few seconds ...                                                                                [ok]
Installation complete.  User name: admin  User password: 3MYjwzeo9A                                                                       [ok]

Note the user #1 user name and password returned from this last step!

Select and enable modules

Grab and enable some modules that will be using on this site

bash> drush dl admin_menu views devel
bash> drush en admin_menu views devel

Make the installation profile

Create an installation profile for this site (This works for Drupal 7 sites. For Drupal 6 sites there is a manual process /admin/settings/profiler_builder .)

bash> drush dl profiler_builder
bash> drush en profiler_builder
bash> drush distro my_cute_cat --untar
bash>

The installation profile contains the drush make file, and a list of what modules are enabled, and possibly more. We use one of these to create sites when we deploy on a server for the first time.

  • No labels