Creating a basic website with Drupal, MySQL, Apache and Bind
These are my notes on the steps you need to take to create a basic website based on Drupal (4.6).
It presumes you already have a domain name registrar (I use www.godaddy.com), somewhere to host the website that already has Apache, MySQL, PHP and Drupal installed (I have my own Virtual Private Server on spry.com) and access to a name server (I run Apache).
First is to register the domain name (I'll be using example.com in this example!)
Then give your name server the details of this new domain. In my case I use bind (9) as my nameserver so I update named.conf to add:
zone "example.com" {
type master;
file "example.com";
};
Then create the file with the domain details in it:
$ORIGIN example.com.
$TTL 86400
IN SOA ns.example.com. root.example.com. (
2006011001 ; Serial
10800 ; Refresh
3600 ; Retry
604800 ; Expire
86400 ) ; Minimum
IN NS ns.example.com.
IN NS ns2.example.com.
IN MX 10 mail.example.com.
IN MX 20 mail2.example.com.
IN A 1.2.3.4
www IN A 1.2.3.4
mail IN A 1.2.3.4
A coupl of hints. For the value for the serial field I the date as YYYYMMDD + VV, the version on that day. Also the third last line give the domain name an address. This means users could type "http://example.com" as a valid website address. Of course this would require extra settings in both the nameserver and webserver. This will be covered in a future article.
Then reload your nameserver so it picks up these details. Since I run Debain linux I do this with:
sh /etc/init.d/bind reload
Next create the new database to house your site under Drupal. If possible do this with phpmyadmin, using its database and priviliges page. Otherwise use the mysql command and enter the following.
CREATE DATABASE `mydatabase` DEFAULT CHARACTER SET latin1 COLLATE latin1_bin;
GRANT ALL PRIVILEGES ON * . * TO 'myusername'@'localhost' IDENTIFIED BY 'mypassword'
WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;
SET PASSWORD FOR myusername@localhost = OLD_PASSWORD('mypassword');
The first statement creates the database. Change mydatabase to a more appropriate name and make a note of it.
The second statement creates a new name and password and associates permissions with it (in ths case 'GRANT ALL'). Change myusername and mypasswd and make a note of it.
The third statemtent is necessary as there is a mismatch between the password handling between PHP and MySQL. If you ever get:
Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in /var/www/drupal-4.6.4/includes/database.mysql.inc on line 31
Client does not support authentication protocol requested by server; consider upgrading MySQL clientConnection closed by foreign host.
Its most likely this password mismatch causing the problem, so rerun that 3rd statement!
Before this database is useful to Drupal we have to create a load of tables and populate some of them with data. To make my life easier I created a simple shell script so I could do this quickly. It MUST contain database.mysql but this should be followed by a line to load the SQL for each additional module that you are using that requires SQL to be added.
#!/bin/sh
user=$1
pass=$2
db=$3
files="database/database.mysql
modules/ecommerce/store/store.mysql
modules/webform/webform.mysql
modules/legal/legal.sql
modules/location/database/uk-zipcodes.mysql
modules/location/database/zipcodes.us.mysql
modules/location/database/zipcodes.uk.mysql
modules/location/location.mysql
modules/taxonomy_access/taxonomy_access.mysql
modules/flexinode/flexinode.mysql
modules/nodewords/nodewords.mysql
modules/gsitemap/gsitemap.mysql
modules/tinymce/tinymce.mysql
modules/img_assist/img_assist.mysql"
for file in $files
do
echo mysql -u $user -p$pass $db \< $file
mysql -u $user -p$pass $db < $file
done
Now run this script passing it the username, password and database name:
sh -x mysqls.sh myusername mypassword mydatabase
Now there is a database we need to tell Drupal about it. Presuming your Drupal installation is in /var/www/drupal and if this is the first site then you will edit drupal/sites/settings.php and change the value of the db_url variable:
$db_url = 'mysql://myusername:mypasswd@localhost/NewDatabase';
Then edit the base url:
$base_url = 'http://www.example.com';
Now you can connect into the site with your favourite web browser!!
The very first step must be to create an initial account (this will be used for site administration). To do this click on the "create new account link". When creating the new account you will be TOLD your password, but don't worry the very next screen will allow you to change it to something more personal.
