wordpress

Setting up WordPress Multisite on Debian 5.0 (lenny)

This post explains how to install WordPress 3.x on a Debian lenny and to set up a multisite installation on your Debian server.

All the blogs will log into the same file /var/log/apache2/access.log; the first column will be the blog host and port (see the LogFormat configured below).

This chapter is based on information collected at http://codex.wordpress.org/Create_A_Network and in /usr/share/doc/wordpress/README.Debian.

All WordPress blogs will use the same shared PHP code in /usr/share/wordpress.

Assumptions

  • Main website will be http://domain.com
  • Blogs will be under http://${blogname}.domain.com

File uploaded into the main blog (www.domain.com) will be stored in /srv/www/wp-uploads/domain.com/%year/%month/

Files uploaded into the *.domain.com blogs will be stored in /usr/share/wordpress/wp-content/blogs.dir/${blog_id}/files/%year/%month/, where ${blog_id} is the numeric id of the blog, as managed by the Multisite feature.

Configuration of Debian lenny-backports repository and installation

WordPress 3.x is not in lenny so we have to use the backport repository.
Excute this as root:

echo "deb http://backports.debian.org/debian-backports lenny-backports main" >> /etc/apt/sources.list

cat < /etc/apt/preferences
Package: *
Pin: release a=lenny-backports
Pin-Priority: 200
EOF

apt-get update
apt-get -t lenny-backports install wordpress

Installation of non free swf plugin

As stated in /usr/share/doc/wordpress/README.Debian WordPress originally comes with a Flash-based tool that allows to upload files. However, that tool violates the Debian Policy, as stated in the
bug #591195. That is why this tool is not shipped with the Debian package anymore. If you want to enable this feature, you need to install the Flash file yourself with the following command:

   
wget -O /usr/share/wordpress/wp-includes/js/swfupload/swfupload.swf http://core.svn.wordpress.org/branches/3.0/wp-includes/js/swfupload/swfupload.swf

Configure your DNS server

Add the following records in your zone (I suppose you know how to deal with your DNS zone):

; wp multisite
$ORIGIN        IN A       ${IP}
www            IN A       ${IP}
*.domain.com.  IN CNAME   www

Apache configuration

Configure the vhost_combined log format in /etc/apache2/apache2.conf modifying the default one:

   
LogFormat "%{Host}i:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined

Configure apache in /etc/apache2/sites-available/wordpress-multisite :


UseCanonicalName    Off

ServerAlias *.domain.com domain.com
ServerName www.domain.com
DocumentRoot /srv/www/domain.com/

Options All
ServerAdmin you@domain.com

# Store uploads of www.domain.com in /srv/www/wp-uploads/$0
RewriteEngine On
RewriteRule ^/wp-uploads/(.*)$ /srv/www/wp-uploads/%{HTTP_HOST}/$1


        Options FollowSymLinks
        AllowOverride All


CustomLog /var/log/apache2/access.log vhost_combined

# this is needed when activating multisite, WP needs to to a 
# fopen("http://randomname.domain.com") to verify
# that apache is correctly configured
php_admin_flag allow_url_fopen on


Configure /etc/wordpress/htaccess:


RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
## uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
## real files dealt directly
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
## other go through index.php
RewriteRule . index.php [L]

Enable the config executing this as root:

a2ensite wordpress-multisite
a2enmod rewrite && a2enmod vhost_alias
/etc/init.d/apache2 restart

Setting some permissions

# required to allow the main site to upload content
chown www-data /srv/
chown www-data /srv/www/

# required to allow subdomains site to upload content
chgrp www-data /usr/share/wordpress/wp-content/blogs.dir/
chmod g+w /usr/share/wordpress/wp-content/blogs.dir/

# required in order to be able to install/update themes/plugins 
# from the webgui (only on the main site)
chown -R www-data:www-data /usr/share/wordpress/wp-content/
chown -R www-data:www-data /usr/share/wordpress/wp-admin/ 

Creating main site

At this stage we can create the main site using this bash script:

bash /usr/share/doc/wordpress/examples/setup-mysql -n main domain.com

This script creates the DB & tables and it also creates a file called /etc/wordpress/config-domain.com.php.

You should end up with the following files:

  • /etc/wordpress/config-domain.com.php
  • /srv/www/domain.com symlink to -> /usr/share/wordpress
  • /srv/www/wp-uploads/domain.com/

Activating Network (aka multisite)

At this stage you should log into http://domain.com and follow the on screen instructions.
Once you are in the backend you can than click into the “Tools -> Network” link and enable the mulsite, this will create some tables in your db and it will ask you to copy&paste some lines into /etc/wordpress/config-domain.com.php:

define( 'SUBDOMAIN_INSTALL', true );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'domain.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

define( 'AUTH_KEY', 'blabla' );
define( 'SECURE_AUTH_KEY', 'blabla' );
define( 'LOGGED_IN_KEY', 'blabla' );
define( 'NONCE_KEY', 'blabla' );
define( 'AUTH_SALT', 'blabla' );
define( 'SECURE_AUTH_SALT', 'blabla' );
define( 'LOGGED_IN_SALT', 'blabla' );
define( 'NONCE_SALT', 'blabla' );

define( 'MULTISITE', true );

# for debugging purposes only
# define('WP_DEBUG', true);

After that you’re ready to go 😀

Logging as super admin and going into the SuperAdmin webgui area you can create new subdomains (blogs), and users, when you can create blogs an email is sent to the owner, you can personalize templates, decide how much storage space you want to assign to every single blog, etc, etc.

At this point you should be able to also install/upgrade plugins and themes straight from the web gui.
Note that define('WP_CORE_UPDATE', false); in your config file will disable the auto update, your wordpress update cycle will be managed using Debian apt tool.

That’s it folks, any question please comment 🙂

Plugin wordpress per ordinare come si vuole i post d’archivio

Avviso ai blogghisti utilizzatori di wordpress.

Dopo l’ultimo post sui due anni mi sono reso conto che wordpress di default non sia molto fruibile per leggere i post in cronologia, ho trovato questo plugin che potrebbe essere utile a molti di voi:

http://moshublog.com/2007/10/30/custom-query-string-reloaded-for-wordpress-23-with-tag-support/

A chi usa ancora blogger dico solo che hanno tutta la mia compassione 😀

Migliorare la pagina “archive” di WordPress.

E’ venerdi’. Che cosa fa uno Venerdi’ in Irlanda? Va a riempirsi di birra! Per poi finire cosi’:

Beh io questa volta passo. 😀
Mi avevano invitato indirettamente ad un leaving party al Pravda ma ho deciso di rimanere a casa, per vari motivi, uno di questi motivi e’ che mi trovavo in the middle di una sezione di hacking molto proficua di wordpress.

Ieri sera ero in chat con una amica che vuole trasferirsi, e le ho detto di consultare il blog per consigli, scorrendo le pagine mi sono ricordato di cose successe anni fa, e anche di curiosi foto ritocchi, specie gli ultimi post prima di partire. 🙂

Questa situazione mi e’ servita da inpulso oggi pomeriggio, mentre ero al lavoro, per installare, fra un cosa e l’altra da fare, un nuovo plug-in per la pagina archive. Si chiama smartarchives.

Che cos’e’? Niente di meglio della descrizione sulla home page ufficiale:

Smart Archives is a rather simple WordPress plugin that will allow you to display your archives in a much “cleaner” format. You can see it in action on my archives page. You’ll notice that everything on the page is hyperlinked (years, months, posts) and that all of the respective links are future-proofed.

Il problema di questo plug-in e’ che mantiene le stesse impostazioni del blog, quindi nel mio caso 5 post per pagina, e ordinamento discendente. Io volevo, solo per la pagina /archive/, un ordinamento normale, ascendente, e nessun limite sul numero di post. In piu’ volevo anche la data accanto ad ogni post che si vede nella root page di /archive.

Cosa ho fatto?

Dopo qualche oretta di lettura di documentazione per gli sviluppatori di wordpess, che tralaltro ho trovato molto completa (rispetto a quando ho iniziato ad usare wordpress nel 2005), ho prodotto le seguenti linee di codice che ho inserito nel file functions.php del mio tema.

function pallotron_nopaging($query) {
   if ( !is_home() && !is_feed() && '' == $query->get('nopaging') ) {
      $query->set('nopaging', 1);
      $query->set('order', 'asc');
   }
}

add_action('parse_query', 'pallotron_nopaging');

Per completare l’opera ho dovuto fare anche un po’ di modifiche al plugin, cambiando delle clausole di order by da DESC ad ASC (il default):

ORDER BY post_date");

E due cicli for che diventano cosi’ (commentato la vecchia linea):

//for ($currentMonth = 12; $currentMonth >= 1; $currentMonth--) {
for ($currentMonth = 1; $currentMonth <= 12; $currentMonth++) {

Adesso i lettori possono navigare la pagina archive e vedere tutte le cazzate scritte da Ottobre 2005 a ora.

References:

http://codex.wordpress.org/Query_Overview
http://justinblanton.com/projects/smartarchives/
http://codex.wordpress.org/Developer_Documentation
http://codex.wordpress.org/Conditional_Tags