Code to Display text only on WordPress Blog Home Page

Cut and past php code to determine if it is the wordpress blog home page (and only the home page itself).

<?php if (is_home() && !is_paged()): ?>

Example, to print john if it is a “homepage” templated page and jill otherwise:

<?php if (is_home(); ?>

  if($name == 'john'){
    echo 'Hi John';
  }else if($name == 'jill'){
    echo 'Hi Jill';
    echo 'Hi';

Using scp (secure copy) to Copy Files Between Computers

Copy a file from your local computer to a remote host using secure copy, scp (which uses ssh for data transfer and provides the same security as using ssh).

scp [filename] [username]@remotehost:[location]

scp file_to_copy.txt

copy a directory to your home computer from the remote computer.

scp -r directory_to_copy

copy a directory from a remote server to the current directory on your computer.

scp -r folder [username]@remotehost:[location] .

scp -r .

If you don’t have automated keys setup you will be asked for the password for that user.

An example for copying a MySQL database. Including the : without a location puts the file in the home folder.

mysqldump database_name -uroot > database_dump.sql
scp database_dump.sql

Then ssh into the remote server and open the mysql prompt

mysql -uroot -p
 mysql> create database database_name;
 mysql> exit

Then run the mysqldump file

mysql database_name -uuser -p < database_dump.sql

Remember to create the database user on the new machine (this has to match what is in the wp-config.php file).

Ubuntu/Linux cli syntax

Command line interface syntax for various actions

Make new directory, make [directory_name]

sudo mkdir new_directory

Remove (file or directory)

rm [name]

rm -i file_to_remove.txt

Using -i prompts you to confirm the deletion.
Remove directory and all of its contents without having to confirm. Obviously be careful.
[/bash]sudo rm -r directory_to_remove[/bash]

Move a file

mv [name] [new_location]

mv file.txt new_sub_directory/file.txt

Rename a file (similar to moving)
mv [name] [new_name]

mv file.txt new_file_name.txt

Copy a fold

cp -r [folder]/* [new_location]

cp -r folder/* /some_place/else/

Keep ssh sessions live

If you want to stop your SSH sessions from being shut down you can add the following line to /etc/ssh/ssh_config on your local machine.

sudo gedit /etc/ssh/ssh_config

Then add:

ServerAliveInterval 30

This does remove the security feature of closing your session in case you leave your computer, but you may decide to take that risk. This sends a SSH package every 30 seconds so your server doesn’t close the connection due to inactivity.

Edit DNS Name Server

Set the DNS name server to use for your machine.

sudo nano /etc/resolv.conf

Then you can use for example ( is Google public DNS, is OpenDNS):

sudo lshw

will provide infor on your system, CPU types, 32 v 64 bit…

Checklist: Moving WordPress site to a New Host

Checklist for moving an existing WordPress site to a new web host

A checklist for moving an existing WordPress site to a new VPS web host, when you have full admin rights over the server.

  1. Set DNS TTL’s down to 5 minutes (a few days prior to the move). This will allow the nameserver update to propagate more quickly.
  2. Set up new domain on the new host (Checklist for setting up a new domain on your VPS)
  3. Install WordPress on new host
  4. Copy old content directory to new WordPress host
  5. Copy old database to new host (how to use secure copy to copy database to new server)
  6. Update wp-config on new host
  7. Enable mod_rewrite in Apache on the new server. From the command line:
  8. a2enmod rewrite

  9. Restart apache
    /etc/init.d/apache2 restart

  10. Test that everything works (you can change your host file to test things out easily)
  11. Update registrar to point domain to the nameservers for the new host

Related: create a new database and run .sql fileDisplay text based on if it is the WordPress blog home page

If WordPress is up to date you could also just copy over everything for steps 1 and 2. I am using this for several sites I have had for years, I figure starting with a clean install of WordPress is a good idea, but it is not necessary.

MySQL cli Syntax

Some MySQL cli syntax examples

How to create a MySQL database and import tables, data… from a sql file.

Login to the MySQL command line interface

mysql -u<username> -p
mysql -uroot -p
  mysql> create database some_database;
  mysql> use some_database;
  mysql> source some_database.sql;

The third line runs the named sql file for the database you names.

Create a new user

mysql -uroot -p
  mysql> USE 'some_database';
  mysql> CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'user_password';
Query OK, 0 rows affected (0.00 sec)
  mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON some_database.* TO 'new_user'@'localhost';

For some reason MySQL chooses to say 0 rows affected, when it succeeds and ads a row for the user. Anyway if you get that message, it worked.

Change password for a user

mysql -uroot -p
  mysql> SET PASSWORD FOR 'username'@'localhost' = PASSWORD('new_password');

Restart mysql:

sudo /etc/init.d/mysql restart

Adding a Model in Ruby on Rails

for Rails 2.*
Not for Rails 3

How to add a model in rails

  • ./script/generate resource MODELNAME
  • ./script/generate resource article
  • edit migrate file
  • edit model.rb – to add associations and validations
  • edit controller.rb – add the 7 rest methods
  • rake db:migrate – to run the new migration
  • If you have to add a table (like a join table) you can do something like, for example
  • ./script/generate migration add_join_table_for_articles_and_authors

Update to the routes file should be taken care of by generate resource, but might want to check).