How to set up Wordpress on a University of Oregon shell account


If you would like to see the comprehensive, final, working version of this guide, check out my blog post.

NOTE: shell.uoregon.edu is now sftp.uoregon.edu

Every wanted to have your own website? Well you can! Your address will he at http://uoregon.edu/~jblancha (you can see the final product of mine right here) ... Except that is mine, but just replace jblancha the username you use for blackboard or your email (aka: your DuckWeb ID).

Contents

[edit] With the script

  • Open a terminal window and SSH into your account.
ssh jblancha@sftp.uoregon.edu
jblancha@uoregon.edu's password: [enter the password]
wget http://auzigog.com/perm/wordpress_shell.sh
chmod 0755 wordpress_shell.sh
./wordpress_shell.sh

Enter "n" for the first question and press enter! DONE!

If you enter "y" to say that you are an advanced user, then you need to enter two passwords.

  • The first password if for your root mysql account, which you can access using "mysql -u root -p" and then the password.
  • The next one is for the "wordpressuser" mysql account. Same deal.

[edit] The really long way

This is everything that the script does for. Step by step. Seriously... Just use the script above instead.

These steps can also help you set up Drupal, Joomla, MediaWiki or any other PHP/MySQL powered application.

[edit] Getting Started

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

ssh jblancha@sftp.uoregon.edu
jblancha@uoregon.edu'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 Wordpress

Now we need to create a user and password for the database that Wordpress 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 wordpressdb;
USE wordpressdb;
GRANT ALL PRIVILEGES ON *.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'DIFFERENT_PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'wordpressuser'@'webserv1' IDENTIFIED BY 'DIFFERENT_PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'wordpressuser'@'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] Wordpress

We are now ready to actually get Wordpress installed!

[edit] Files

Download and extract Wordpress in your public_html directory

cd ~/public_html
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
cd wordpress
mv * ..
cd ..
rm latest.tar.gz
rmdir wordpress

Now change some permissions on a couple folders and their contents:

chmod -R 0755 wp-admin wp-content
touch .htaccess
chmod 0755 .htaccess

[edit] Configuring Wordpress

Edit the configuration by entering the following commands into the terminal:

cd ~/public_html
mv wp-config-sample.php wp-config.php

Now use nano to edit your wp-config.php file and edit these 4 lines. Replace things in all capital letters with the stuff we figured out earlier including your port number and the second password you chose called DIFFERENT_PASSWORD.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpressdb');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'DIFFERENT_PASSWORD');

/** MySQL hostname */
define('DB_HOST', 'sftp.uoregon.edu:XXXX');

A couple lines further down you should see something that looks like this:

define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');

Just change each put your unique phrase here to some random combination of numbers, letters and other characters that is moderately long. All 4 should be different.

Now save the file and exit nano.

[edit] Running the Wordpress installation script

You should now be able to access http://uoregon.edu/~USER_NAME_HERE

If all went to plan, Wordpress will prompt you for an Blog Title and your email address (which needs to be real! It's where your password will be sent). Enter those bits of information and press Install Wordpress

Note: If you weren't prompted for those two bits of information, post a comment here and I'll do my best to help you resolve any issues.

Take note of your user name (admin) and password! Press Login and use that user name/password to access the Wordpress control panel! It's a good idea to change your password after you login.

[edit] The End: Themes and Plugins

You can now start posting and now when you go to http://uoregon.edu/~USER_NAME_HERE you should see your blog!! You did it! Now go find a theme and some plugins. A maintain a list of my favorite themes and some useful plugins.


[edit] Bonus

See all the other accounts that are running MySQL. This means they have Wordpress, Drupal or some other fancy system running! Some of them are worth a gander. Check it out!

netstat -an | grep -i mysql

[edit] References

University of Oregon Stuff

Other stuff

Computer Science Department Server Stuff

Various Computer Groups on Campus