Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Sorry, I forgot that the .pl extension will try to execute as a cgi-program,
    but EXEC-CGI is turned off for that directory.
    I have renamed the file to https://www.doulos.at/makeblog.pl.src, just download
    and then rename to makeblog.pl.

    I use just the same setup, since I run an English and a German blog, and didn’t want to maintain two sets of users.
    The table names are set in wp-settings.php, by concatenating the table prefix from wp-config.php and the table-specific names.
    In my case, I first configured my English blog, with a table prefix of “wp_wnp_en_”, and created a number of users.
    Then I configured my German blog with a table prefix of wp_wnp_de, and AFTER RUNNING INSTALL, I made the following changes:
    1. In the wp-config.php file for the German blog I added this line under the line setting the table prefix:

    $tableusers = "wp_wnp_en_users" ;

    2. In the wp-settings.php file, I wrapped the line

    $tableusers = $table_prefix . 'users';

    in an if-statement which only sets it here if it hasn’t been set yet:

    if ( $tableusers == "" )
    {
    $tableusers = $table_prefix . 'users';
    }

    Two important observations:
    — when setting up a new blog, DO THIS AFTER running php-admin/install.php. Otherwise install.php will bomb
    on the attempt to create the already existing table.
    — be aware that everyone in this usertable will have the same rights on all blogs thus modified, so this is really only good for multiple blogs run by the same person (as in my multilingual scenario).

    O.K., I spent some more time on this.
    Unfortunately the script as posted last night does not do the trick, because
    it turns out that even when the directories are real (not symlinks), the reference “..” refers back to the REAL parentdirectory of the file.
    So I now have a modified version (all it really does is replace
    the “symlink” function call with “link”) which creates the directory
    structure and then hard links all of the files. This way everything seems
    to work (tested it quite extensively). It still makes index.php, wp-config.php and wp-layout.css separate local files.
    One other change I made was to optionally set $tableuser in wp-config.php and wrap the corresponding line in wp-settings.php in an ‘if ( $tableusers == “” )’ — this way one can use ONE usertable for
    multiple related blogs (i.e., I have an English and a German blog).
    To answer the questions posed by JMF (sorry, I forget that people have different levels of acquaintance with code :-):
    1. Since links are a UNIX feature, this will only work on a UNIX-like OS (i.e. any real UNIX, Linux, BSD, etc).
    2. Yes, BLOGSRC and BLOGBASE need to be changed to reflect
    your setup; WEBUSER is the user under which your Apache webserver runs, not YOUR account. Usually it will be something like “apache” or “web” or “httpd”. If you put the following code into a file in your web root, say “getinfo.php” and then view it with your browser, you can scroll down to the “APACHE” section and find the User/Group values about six rows down:

    <?php
    // Show all information, defaults to INFO_ALL
    phpinfo();
    ?>

    3. Download the PERL script from https://www.doulos.at/makeblog.pl, edit it as described above and upload it to your webserver (make sure you save it in UNIX format, i.e. only newlines rather than CR/NL at the end of lines). Then make it executable with “chmod +x filename”.
    4. It is advisable to think carefully about any mods to the distributed wordpress which you want to have in ALL blogs, and to make these to the master copy before creating “clones” with makeblog.
    5. Call the script at the commandline as
    “makeblog.pl NEWBLOGNAME”
    which will put the new blog into a subdir called NEWBLOGNAME in the BLOGBASE directory, and will also modify the new blog’s wp-config.php to use wp_NEWBLOGNAME_ as the table prefix.
    6. Run the new blog’s wp-admin/install.php and you’re done.
    7. I suspect that after an upgrade (minor upgrades at least) to WordPress
    you can just save any modified index.php, wp-layout.css, and wp-config.php files for each blog, delete the individual blog subdirs, and then re-create them from the updated master with makeblog. If you used the same NEWBLOGNAME, you then just need to copy your saved
    files back, and the blog should work with the new code and the old database tables without running install.php again.

    The problem with the symlink method of creating multiple blogs is that wp-login.php finds the wp-config.php file by doing a dirname(__FILE__) call and then appending “wp-config.php”.
    This gets the REAL directory where that file resides, not the directory
    where the currently used symlink is located — and voila, we’re messed up.
    So right now I am trying this out with dirname(__FILE__) removed from
    wp-login.php; since wp-login.php is in the same directory as wp-config.php this should not really matter.
    Another potential problem is that references with “..” refer to the REAL parent directoy rather than the symlink; so at least the directories must not be symlinks but actual directories. I’m appending a perl script which does this; make sure you adjust some of the vars at the top. And remember to remove the call to dirname at teh top of wp-login.php.
    Wolf Paul
    makeblog script:
    —- cut here —-
    #!/usr/bin/perl
    # Turn this off if you don’t want output
    $Debug = 1 ;
    # This should be the directory of the original WP installation
    $BLOGSRC = “/var/www/html/wordpress” ;
    # This should be the directory in which you want to create the new blog
    $BLOGBASE = “/var/www/html/blogs” ;
    # this is the user who should own all the files in the new blog
    $WEBUSER = “apache” ;
    die “Usage: $0 new_blog_name\n” unless $ARGV[0] ;
    # New blog name is specified on the commandline
    $NEWBLOG = $ARGV[0] ;
    # perl chown needs numeric args
    $webuid = (getpwnam($WEBUSER))[3] ;
    $webgid = (getpwnam($WEBUSER))[4] ;
    # create new blog dir
    mkdir(“$BLOGBASE/$NEWBLOG”) ;
    # go to original blog
    chdir($BLOGSRC) ;
    # get a list of all subdirs — sorry, I’m too lazy to do this in perl
    open(DIRS, “find . -type d -print|”) ;
    while ( <DIRS> )
    {
    chomp ;
    s/^\.\/// ; # that’s cosmetic, it would work anyway
    $dir = $_ ; # that’s also just for comprehension, we could use $_ directly
    print “DIR is $dir\n” if $Debug ;;
    mkdir(“$BLOGBASE/$NEWBLOG/$dir”) unless $dir eq “.” ; # “.” already exists, so we dont need to make it
    chown($webuid,$webgid,”$BLOGBASE/$NEWBLOG/$dir”) ;
    @files = <$BLOGSRC/$dir/*> ;
    foreach $file ( @files )
    {
    if ( -f $file ) # discard subdirs
    {
    $basefile = $file ;
    $basefile =~ s/$BLOGSRC\/$dir\/// ;
    print “\tLinking $file\n\t\ttto $BLOGBASE/$NEWBLOG/$dir/$basefile\n” if $Debug ;
    symlink($file, “$BLOGBASE/$NEWBLOG/$dir/$basefile”) ;
    }
    }
    }
    close DIRS ;
    # These three files are good to have locally (in fact, wp-config.php cannot be a symlink)
    foreach $file ( “index.php”, “wp-config.php”, “wp-layout.css” )
    {
    print “Unlinking $BLOGBASE/$NEWBLOG/$file\n” if $Debug ;
    unlink(“$BLOGBASE/$NEWBLOG/$file”) ;
    print “Copying $BLOGSRC/$file\n\tto $BLOGBASE/$NEWBLOG/$file\n” if $Debug ;
    &copy(“$BLOGSRC/$file”, “$BLOGBASE/$NEWBLOG/$file”) ;
    chown($webuid,$webgid,”$BLOGBASE/$NEWBLOG/$file”) ;
    }
    sub copy
    {
    ($src,$targ) = @_ ;
    open(SRC, $src) or die “cannot open $src for reading” ;
    open(DST, “>$targ”) or die “cannot open $targ for writing” ;
    while ( <SRC> )
    {
    # this adjusts the table prefix to include teh name of teh new blog
    if ( /^\$table_prefix = / )
    {
    print DST “\$table_prefix = ‘wp_${NEWBLOG}_’; // example: ‘wp_’ or ‘b2’ or ‘mylogin_’\n” ;
    next ;
    }
    print DST ;
    }
    }
    —- cut here —-

Viewing 4 replies - 1 through 4 (of 4 total)