Category Archives: Linux

Backing up a WordPress site

I created this to have something simple to schedule backups of my WordPress site.
It’s tested OK on CentOS 5.5 and 5.6. It creates 2 bzip2 tarballs with timestamps, one for the website and one for the database. And it’s run once a day. It’s then shipped off to another system using Rsync and SSH.

You will need to edit the variables before running it. If you make copies of the script, you can use it to create backups of multiple sites. I hope this will be useful for more than myself.

#!/bin/bash
## DO NOT EDIT
DATE=`date +%d-%m-%Y`
## EDIT BELOW - Configuration parameters

WPSITE=/var/www/html/wordpress
WPSITE_NAME=mywebsite
WPBACKUP=/mnt/wordpress_backup

## STOP EDITING - Configuration parameters

if [ ! -d "$WPBACKUP" ]
then
        mkdir $WPBACKUP
fi

# Grabs the necessary MySQL information from the wordpress site.
DB_NAME=`echo "<?php require_once(\"${WPSITE}/wp-config.php\"); echo DB_NAME;" | php`
DB_USER=`echo "<?php require_once(\"${WPSITE}/wp-config.php\"); echo DB_USER;" | php`
DB_PASSWORD=`echo "<?php require_once(\"${WPSITE}/wp-config.php\"); echo DB_PASSWORD;" | php`
DB_HOST=`echo "<?php require_once(\"${WPSITE}/wp-config.php\"); echo DB_HOST;" | php`

# Dump the database
mysqldump --user=${DB_USER} --password=${DB_PASSWORD} --host=${DB_HOST} $DB_NAME | bzip2 -c > $WPBACKUP/$WPSITE_NAME-db-$DATE.sql.bz2

# Tarballs the database and wordpress files with bzip2
tar -jcvf $WPBACKUP/$WPSITE_NAME-backup-$DATE.tar.bz2 --exclude cache $WPSITE/

// CrashMAG

How to set up RHEL or CentOS 5.5 with Apache, MySQL, PHP 5.3 and WordPress

This is just a short how-to on what I did to set up WordPress on my VPS server. This assumes you’re running RHEL, CentOS or Scientific Linux 5.5.

These instructions assume that you know how and when to use root. Whether it be via sudo or not.

Rather than going with the minimum requirements(*) from WordPress I went with PHP 5.3.

PHP version 4.3 or greater
MySQL version 4.1.2 or greater

Installing MySQL and Apache

1) Install MySQL and Apache

# yum install mysql-server httpd

2) Add MySQL and Apache to the appropriate run levels

# chkconfig --level 345 mysqld on
# chkconfig --level 345 httpd on

3) Adding the PHP 5.3 repository

# rpm -ivh http://repo.webtatic.com/yum/centos/5/`uname -i`/webtatic-release-5-0.noarch.rpm

4) Installing PHP 5.3 via YUM

# yum --enablerepo=webtatic install php php-mysql

Set up MySQL

1) Start MySQL.

# service mysqld start

2) Set the root password.

# mysqladmin -u root password 'your password'

The 5th step is to set up the database and database user for WordPress 

1) Log in to mysql

# mysql -u root -p

Enter your password when prompted.

2) Create the database

> CREATE DATABASE wordpress CHARACTER SET = utf8 COLLATE = utf8_general_ci;

3) Create the database user and assign appropriate rights. In the example the user is called “wp”.

> CREATE USER 'wp'@'localhost' IDENTIFIED BY 'db_passwd';
> GRANT ALL PRIVILEGES ON wordpress.* TO 'wp'@'localhost' IDENTIFIED BY 'db_passwd';
> FLUSH PRIVILEGES;

The 6th step is to download and install WordPress

1) Download

# wget http://wordpress.org/latest.tar.gz

2) Create the wordpress folder.

# mkdir /var/www/html/wordpress

3) Extract

# tar -xzvf latest.tar.gz -C /var/www/html

4) Modify folder ownership.

# chown apache:apache /var/www/html/wordpress -R

-R, –recursive change files and directories recursively

5) Go to http://your site/wordpress and follow the on screen instructions.



// CrashMAG