This tutorial is a rough set of instructions for installing Drupal (a content management system) on your free, shared web space on uoregon.edu (for University of Oregon students).

This tutorial will probably never be polished or comprehensive.

For a more detailed, clean explanation, see my guide for installing Wordpress on shell.uoregon.edu. Many parts of this tutorial are snagged from there.


Contents

[edit] Getting Started

SSH into your shell account. My username is jblancha, so I entered this command into my terminal.

ssh [email protected]
[email protected]'s password: [enter the password]

If you are on a Mac running OS X you can just use the built in terminal to do this. If you are on windows, you can use WinSCP.

Note: If you had any index.html or index.php files in your public_html folder previously, you need to delete or rename those before continuing with this tutorial.

[edit] PHP

We have to do some special stuff to get shell to recognize that our files are PHP files. These helpful instructions come from the EMU marketing department In your public_html directory, create a file called .htacces...

nano .htaccess

... and put this into the file ...

RemoveHandler .php
AddType application/my-httpd-php .php
Action application/my-httpd-php /~USER_NAME_HERE/php.cgi
[Press Ctrl+X to exit the "nano" text editor; press Y and enter to save]
Note: Line 3 looked like this for me: Action application/my-httpd-php /~jblancha/php.cgi

Now create a file called php.cgi in your public_html directory in the same fashion...

nano php.cgi

... and put this into the file ...

#!/usr/local/bin/php5
<?php
$pwuid = posix_getpwuid(posix_geteuid());
if (is_file($_SERVER['PATH_TRANSLATED']) &&
      ($pwuid['name'] === 'nobody' ||
       $pwuid['name'] === 'apache' ||
       fileowner($_SERVER['PATH_TRANSLATED']) == posix_geteuid())) {
    chdir(dirname($_SERVER['PATH_TRANSLATED']));
    include(basename($_SERVER['PATH_TRANSLATED']));
}
?>
[Press Ctrl+X to exit the "nano" text editor; press Y and enter to save]

Now give these files the proper permissions by entering this command into the terminal:

chmod 0755 .htaccess php.cgi

[edit] MySQL

This is the tricky part and might get a bit technical. I've broken it into sections. Whenever I mention editing or creating a file, do it using nano the same way you did above.

[edit] Preparation

Go to your home directory and make a directory called mysql:

cd ~
mkdir mysql

Now we need to grab two important bits of information.

First, we need to pick a port to run MySQL off of. Pick a 4-digit number that is over 5000. Anywhere you see XXXX in the rest of this guide, replace it with that 4-digit number (port number). Check that the port number you selected is available:

netstat -lt | grep XXXX
  • If nothing showed up when you ran that command, great! Just write down your port number.
  • If something did show up, then you need to keep changing your port number until you find one that returns nothing. Now write it down.

Now we need to get the full path to your user directory.

cd ~
pwd

Write it down! Anywhere you see /homeN/USER_NAME_HERE in the rest of this guide, replace it with what you just wrote down (the path to your user directory). And the same goes for anywhere that you see user=account_name_here ... You should replace the part after the equals sign with your account name (aka: DuckWeb ID).

[edit] Configuration File

Now make a file (using nano like we did before) called .my.cnf (in your home directory, not your public_html directory!) and put the following in it:

Note: Don't forget to put the proper information in for each line!
[mysqld]
datadir=/homeN/USER_NAME_HERE/mysql/
socket=/homeN/USER_NAME_HERE/mysql/mysql.sock
port=XXXX
user=USER_NAME_HERE

[mysql]
socket=/homeN/USER_NAME_HERE/mysql/mysql.sock
port=XXXX
user=USER_NAME_HERE

[mysql.server]
user=USER_NAME_HERE
basedir=/homeN/USER_NAME_HERE/mysql/

[client]
host=127.0.0.1
socket=/homeN/USER_NAME_HERE/mysql/mysql.sock
port=XXXX
user=USER_NAME_HERE

[safe_mysqld]
pid-file=/homeN/USER_NAME_HERE/mysql/mysql.pid
err-log=/homeN/USER_NAME_HERE/mysql/safe.log

Save the file!

[edit] Starting MySQL

Now you need to initialize your database. This should only ever be done one time!

/usr/bin/mysql_install_db

Now run the MySQL daemon:

cd /usr ; /usr/bin/mysqld_safe &

This will "freeze" your terminal because that's what daemon's do. It's not really frozen, but go ahead and close it, reopen your terminal and SSH into your account again like we did at the beginning of this tutorial.

[edit] Setting a root password for MySQL

It is unsafe to leave the "root" account without a password (as it is right now). Enter the following commands into the terminal to set a password.

Note: Replace PASSWORD with the password you'd like to use. Write it down.
/usr/bin/mysqladmin -u root password 'PASSWORD'
/usr/bin/mysqladmin -u root -h sftp password 'PASSWORD'

[edit] Making a database for Drupal

Now we need to create a user and password for the database that Drupal is going to use.

First, run MySQL from the terminal as the "root" user:

mysql -u root -p
Enter password: [Enter the PASSWORD you chose a few lines ago]

You are now in a "terminal inside a terminal". This is the MySQL terminal and it should say mysql> right before your cursor. To exit it, type quit and press enter.

Now you need to run the following commands inside the MySQL terminal to be create a new database and user. Replace DIFFERENT_PASSWORD with a password that is different from the one you selected in the last section. Write it down and mark it as "password 2" because we will need it later!

CREATE DATABASE drupaldb;
USE drupaldb;
GRANT ALL PRIVILEGES ON *.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'DIFFERENT_PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'drupaluser'@'webserv1' IDENTIFIED BY 'DIFFERENT_PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'drupaluser'@'webserv2' IDENTIFIED BY 'DIFFERENT_PASSWORD';
FLUSH privileges;
quit

[edit] MySQL Daemon Cron Job

If shell ever needs to be restarted, your MySQL Daemon will go down! You need a cron job set up so that every 30 minutes, a script will check to make sure MySQL is still running.

Create the script that the cron job will run. This does the checking and runs mysqld (the MySQL daemon) if it isn't already running. Create a file named mysqld.sh in your home directory (~) and put the following lines in the file:

if ! mysqladmin ping > /dev/null ; then
       mysqld_safe &
fi

Now you need to add the cron job itself to your "crontab". Run the following commands

chmod 0755 mysqld.sh
crontab -e

You are now in a text editor. Add the following line to the file, then save and exit the editor like you have every other time you have edited a file in this tutorial.

15,45 * * * * ./mysqld.sh


[edit] Migration instructions

These are actually totally separate instructions for moving a site over to shell.

Super sloppy at the moment. I haven't actually tested them since I wrote it, and I may be missing some steps.

Dev site: http://asuo.auzigog.com/ Test bed site (on shell): http://www.uoregon.edu/~asuo/

Note: This is a very sloppy approach and could be improved in many areas

Helpful guide: http://darkwing.uoregon.edu/~tony/?q=node/1

[edit] Old site

  1. zip up your sites directory (I used the file manager in cpanel since i don't have SSH access on the original server)
  2. download the zip
  3. gather any other modified files you want to take with you (.htaccess perhaps)
  4. Clear your cache
  5. export your database as an sql. Make sure you use the "enclose in transaction" option or you will get a max_allowed_packet error later


[edit] New site

  1. SSH into the account
  2. Get PHP and MySQL up and running my installer script: http://auzigog.com/2009/02/01/easy-website-on-your-university-of-oregon-web-space/
    1. Copy all usernames, ports and passwords (all output from the script) to a safe place. you will need them later.
  3. Delete all the wordpress files in public_html
    1. Note, this script adds php.cgi to public_html. Never delete php.cgi
  4. Extract a fresh install of Drupal to public_html (or Acquia Drupal if you are lazy like me)
  5. Rename the current sites directory to sites-orig
  6. Upload the zip of your sites directory. unzip it
  7. Go to sites/default/settings.php (might need to change the permissions to have access)
  8. Change the database connect string to look something like this
    1. mysql://wordpressuser:[email protected]:5548/wordpressdb
    2. Make sure you change the port to the unique port that was assigned to you when you ran the above script
  9. Upload your SQL dump file (unzip it if you zipped it originally)
  10. remove all wordpress tables
    1. i lost my root password, so i used this script (again, because I'm lazy): http://www.cyberciti.biz/faq/how-do-i-empty-mysql-database/
    2. Alternatively, you could just make a new user and db for drupal
  11. import your database
    1. mysql --max_allowed_packet=500M -u wordpressuser -p wordpressdb < drupal_dump.sql
  12. edit the .htaccess file in your site root
  13. add the following lines to the top
    1. RemoveHandler .php
    2. AddType application/my-httpd-php .php
    3. Action application/my-httpd-php /~asuo/php.cgi
  14. comment out the following lines near the top of the .htaccess (wish I knew how to get around this, but if they aren't commented, I get a 500 internal server error)
    1. #Options -Indexes
    2. #Options +FollowSymLinks
  15. find the "RewriteBase /drupal" line in the .htaccess file
    1. uncomment it and change "/drupal" to "/~yourusername" ... For example, mine was /~asuo
  16. go to sites/default/files
    1. edit the htaccess file in there
    2. comment out both the lines that start with "Options"
  17. launch the site
  18. clear the cache again
  19. go to "file system" and make sure it's configured to a directory that exists

This is definitely sloppy and should be compacted into it's own script.