tobias.kochs-online.net

[lang_en]Multiple blogs with a single WordPress installation[/lang_en][lang_de]Mehrere Blogs mit einer einzigen WordPress-Installation[/lang_de]

| 4 Kommentare

[lang_en]When I started setting up the blogs some days ago, I began to create subdomains and subdirectories on the server where I could install WordPress. Soon I discovered, how complicated and prone to errors this procedure can be and started to think about alternatives allowing me to run several separate blogs while administrating and maintaining only a single software installation. You can find some more or less complex hacks for this floating around the net. In addition there exists a special multi user/multi blog version of WordPress called WordPress µ, but it seems it is turned mostly towards very large projects and uses a number of modifications of the original variant for this purpose. On the other hand there is an approach by Strider which is called Virtual Multiblog and looks quite feasible. However this looks a bit intricately at first glance because it seems to require an additional WordPress plugin.

Finally I discovered a very elegant way by myself: Because WordPress stores all settings of a blog – including articles, comments and users – in the MySQL tables defined in the file wp-config.php, it would be sufficient to use different configuration files depending on the used subdomain. So I modified the wp-config.php to simply evaluate the used subdomain and load a configuration based on the result. Which looks like this:[/lang_en]

[lang_de]Als ich mich dieser Tage daran begab, die Blogs einzurichten, begann ich zunächst für jedes Blog eine Subdomain und dann ein Verzeichnis auf dem Server zu erstellen, wohin ich das WordPress installierte. Dabei fiel mir schnell auf, wie umständlich und fehlerträchtig so ein Vorgehen ist und ich überlegte auf Alternativen herum, die es erlauben mehrere getrennte Blogs zu führen, während man jedoch nur eine einzelne Software-Installation administrieren und aktuell halten muss. Im Netz finden sich hierzu mehr oder minder komplexe Hacks für WordPress. Zudem gibt es eine explizite Multiuser-/Multiblog-Version von WordPress mit dem Name WordPress µ, die sich aber offensichtlich eher an sehr große Projekte wendet und entsprechende Änderungen an der zugrundeliegenden WordPress-Variante mit sich bringt. Relativ gut umsetzbar wirkt hingegen der Virtual Multiblog-Ansatz von Strider. Aber auch das erschien mir auf einen ersten schnellen Blick hin mit dem zu installierenden WordPress-Plugin als etwas zu umständlich.

Schließlich kam ich selber auf eine überaus elegante Lösung: Da WordPress alle Einstellungen eines Blogs – samt der Einträge, Kommentare und Benutzer – in den MySQL-Tabellen ablegt, die in der Datei wp-config.php angegeben sind, würde es ausreichen, abhängig von der verwendeten Subdomain verschiedene Konfigurationsdateien einzusetzen. Also habe ich die wp-config.php so modifiziert, dass sie lediglich die aufgerufene Subdomains auswertet und anhand des Ergebnisses die gewünschte Konfiguration lädt. Das sieht dann so aus:[/lang_de]

<?php
if ($_SERVER['SERVER_NAME'] == 'blog1.example.com')
{
require('wp-config.blog1.php');
}
else if ($_SERVER['SERVER_NAME'] == 'blog2.example.com')
{
require('wp-config.blog2.php');
}
?>

[lang_en]The files wp-config.blog1.php and wp-config.blog2.php are just standard WordPress configuration scripts without a single line of extra code. Using different prefixes for the MySQL tables it even would be sufficient to have a single database to store all blogs. As simple as it is, as low-maintenance it is too, because WordPress updates don’t overwrite the new wp-config.php or the newly created configuration files. At the same time all blogs benefit from the update, of course.

[Update: It just caught my eye, that you might run into difficulties if you are running multiple blogs with the same plugin. If an upgrade of that plugin requires an update of the plugin’s database table, you have to pay attention to update all of those tables (for every blog using the plugin)!][/lang_en]

[lang_de]Bei den Dateien wp-config.blog1.php und wp-config.blog2.php handelt es sich dabei um ganz normale WordPress-Konfigurationsskripte, die ohne eine Zeile Extra-Code auskommen. Verwendet man darin unterschiedliche Präfixe für die MySQL-Tabellen, so reicht sogar eine einzige Datenbank aus, um alle Blogs zu speichern. So simpel, wie das ist, ebenso pflegeleicht ist es auch, da bei einem WordPress-Update weder die neue wp-config.php noch die angelegten Konfigurationsdateien überschrieben werden. Gleichzeitig kommen natürlich alle Blogs in den Genuss des Software-Updates.

[Update: Mir fiel soeben auf, dass man Schwierigkeiten bekommen könnte, wenn man in mehreren Blogs dasselbe Plugin verwendet. Falls nun ein Update dieses Plugins eine Aktualisierung der Plugin-Datenbank-Tabellen erfordert, so muss sichergestellt werden, dass die Tabellen aller Blogs, die das Plugin einsetzen, aktualisiert werden!][/lang_de]

Autor: Tobias

Hallo, ich bin Tobias. Meine Leidenschaft gilt alten Autos. Je ausgefallener desto besser. Im Alltag schwöre ich auf meinen treuen '88 Volvo 745 und im Laufe der Zeit sammelten sich daneben in der Garage noch ein '79 AMC Pacer, ein '70 Chrysler 300 Hurst, ein '90 Toyota Sera und ein '94 Mazda 121 Ginza. Wenn ich gerade nicht an den Autos herumschraube, lasse ich den Nerd raushängen und schreibe hier irgendwas zu Online- und IT-Themen, Filmen oder Musik. Ihr findet mich auch .

4 Kommentare

Schreibe einen Kommentar zu Tobias Antworten abbrechen

Pflichtfelder sind mit * markiert.