Multiple Blog / WordPress farm solution with hard links
-
I setup a wordpress “farm” @ my server using hard links. The reasons I chose this method:
A) One single wordpress install (that can be easily upgraded)
B) Not necessary to edit any of the PHP files / create custom hacks (will be overwritten in an upgrade unless reapplied).
C) Allows users to have their own .htaccess &/or index.php and plugins.
D) one database is used, users data is seperated via table prefix
E) Allows the user to “install” their blog. ie. the first steps where blog name, admin email and password are set.
F) This solution should work for people on virtual servers (w/o root access).I’m new to WordPress & haven’t done too much research in multiblog scripts/hacks… and I’m sure there’s some nice solutions out there, and that I’ve re-invented the wheel. Regardless,
does anyone have any feedback on this method? is it a good way to go?I’m attaching my addblog.sh script… feel free to use it, but do check back here as I hope to include input validation and a deleterblog, upgradeblogS(*plural) script that will only update blogs that haven’t customized any PHP, and output the ones that have so you can contact their administrator.
~ Brice Burgess
——
#!/bin/sh# WordPress Farm Script(s) by Brice Burgess <[email protected]>
# version 0.01# addblog.sh – Adds a wordpress blog to your farm.
############################
# Database Settings
# note: Script intended for MySQL server on localhost# MySQL wordpress or root user (must have all privileges on wordpress database)
myuser=”root”# MySQL wordpress or root user’s password
mypass=”your_password”# MySQL wordpress database name
mydb=”wordpress”############################
# Directory Settings# path to blogs [where new blog dir will be created] (exclude trailing slash)
blogs=/home/www/vhost/blogs# path to wordpress files [where wordpress is extracted] (exclude trailing slash)
wordpress=/home/www/vhost/blogs/wordpress############################
# Program Execution – no editing necessary beyond this point…
# note: …unless necessary of course!## Get name and password of blog to add
#-a
echo “Enter short name of blog to add: “
read blog
echo
echo “Enter a MySQL password for this blog: “
read password
#
#### Validate all parameters
# TODO#
#### Add permissions to wordpress database
# note: the below tables may need to be updated if wordpress schema changestables=”${blog}_categories
${blog}_comments
${blog}_linkcategories
${blog}_links
${blog}_options
${blog}_post2cat
${blog}_postmeta
${blog}_posts
${blog}_usermeta
${blog}_users”sql=””
for i in $tables
do
sql=”$sql GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER ON ${mydb}.${i} TO ${blog}@localhost WITH GRANT OPTION;”
done
sql=”$sql SET PASSWORD FOR ${blog}@localhost = OLD_PASSWORD(‘${password}’);”
cat <<EOF | mysql -u $myuser -p$mypass
$sql
EOF
#
#### Create Blog Directory, Link it to main install
#
mkdir ${blogs}/${blog}
cd ${blogs}/${blog}
ln $wordpress/* . &>/dev/null# call traverse with a the main wordpress directory
traverse()
{
ls “$1” | while read i
do
if [ -d “$1/$i” ]; then
# strip $wordpress path from $1/$i
newdir=echo $1/$i | sed ''s:${wordpress}::''
mkdir ${blogs}/${blog}${newdir}
cd ${blogs}/${blog}${newdir}
ln $1/$i/* . &>/dev/null
traverse “$1/$i”
fi
done
}
traverse $wordpress
#
#### Generate wp-config.php
#
echo “<?php
// ** MySQL settings ** //
define(‘DB_NAME’, ‘${mydb}’); // The name of the database
define(‘DB_USER’, ‘${blog}’); // Your MySQL username
define(‘DB_PASSWORD’, ‘${password}’); // …and password
define(‘DB_HOST’, ‘localhost’); // 99% chance you won’t need to change this value// You can have multiple installations in one database if you give each a unique prefix
\$table_prefix = ‘${blog}_’; // Only numbers, letters, and underscores please!// Change this to localize WordPress. A corresponding MO file for the
// chosen language must be installed to wp-includes/languages.
// For example, install de.mo to wp-includes/languages and set WPLANG to ‘de’
// to enable German language support.
define (‘WPLANG’, ”);/* That’s all, stop editing! Happy blogging. */
define(‘ABSPATH’, dirname(__FILE__).’/’);
require_once(ABSPATH.’wp-settings.php’);
?>” > ${blogs}/${blog}/wp-config.php
#
#### Update Permissions/Cleanup
# TODOecho “Blog $blog has been added! Please advise user to set it up.”
#
##exit
- The topic ‘Multiple Blog / WordPress farm solution with hard links’ is closed to new replies.