WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Blog / WordPress farm solution with hard links (4 posts)

  1. briceb
    Member
    Posted 8 years ago #

    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 <bhb@iceburg.net>
    # 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 changes

    tables="${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
    # TODO

    echo "Blog $blog has been added! Please advise user to set it up."

    #
    ##

    exit

  2. briceb
    Member
    Posted 8 years ago #

    Are future version of wordpress going to include ability for multi user/farm setups?

  3. jbhandley
    Member
    Posted 8 years ago #

    Hi There,

    I tried this method, and it copied a bunch of files to a directory, but when I went there it said this to me:

    Warning: main(/home/mwga0330/public_html/sailing/wp-includes/wp-db.php): failed to open stream: No such file or directory in /home/mwga0330/public_html/sailing/wp-settings.php on line 73

    Fatal error: main(): Failed opening required '/home/mwga0330/public_html/sailing/wp-includes/wp-db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/mwga0330/public_html/sailing/wp-settings.php on line 73

    The file wp-settings.php is definately on that path - any idea what is causing this.

    One thought is that it asks for the short name - do I need to use the sql database username that I created to make this work properly? If so, how do I do multiple installs on one database? Thanks for any help with this!

  4. briceb
    Member
    Posted 8 years ago #

    The short name is used as:

    1) the mysql username of this blog*
    2) the directory created for this blog
    3) the mysql table prefix

    so, you want to ensure a unique short name.

    It seems that you have used "sailing" as the short name. Please ensure that the user/group the webserver is running as (usually httpd, www, or apache) has read + execute access (permissions) on all files/directories in your wordpress install.

    I have not enhanced the script yet (I plan on adding validation, an upgrade script, and instructions on allowing users to upload their own themes, etc.), as it seems interest is low & I've been busy with other projects.

Topic Closed

This topic has been closed to new replies.

About this Topic