From Segfault
Jump to navigation Jump to search

The other day this box went down and I could not access my Mediawiki installation. The box was meant to come back online later on but I really wanted to read the wiki. Luckily I had somewhat fresh backups from the mediawiki installation - so why not using them? Just to see how quickly a full restore would take.

So I fired up an openSUSE 12.1 installation, running in a virtual machine. The base system was already installed, a few more packages were needed now:

zypper install nginx mysql-community-server php5-fpm php5-mysql php5-intl php5-gd

Note: Mediawiki likes to utilize object caching, such as xcache or APC. However, PHP modules for openSUSE like php-APC or php5-xcache are only available via extra repositories. For the sake of simplicity, let's skip those now.

With these packages installed, their configuration comes next. This may be a bit openSUSE centric and other distributions may work differently.

For PHP-FPM, only the following parts were changed from its original configuration:

$ cp -p /etc/php5/fpm/php-fpm.conf{.default,}
$ cat /etc/php5/fpm/php-fpm.conf
pid       = /var/run/
error_log = /var/log/php-fpm.log

listen    = /var/run/php5-fpm.sock
user  = nobody
group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35

Enable and start PHP-FPM:

chkconfig php-fpm on && service php-fpm start

Next up is nginx:

$ cat /etc/nginx/nginx.conf
user                    nginx;
worker_processes        1;
error_log       /var/log/nginx/error.log;
pid             /var/run/;

events {
       worker_connections      1024;
       use                     epoll;

http {
       include         mime.types;
       default_type    application/octet-stream;
       access_log      /var/log/nginx/access.log;

       # This will access our PHP-FPM installation via a socket
       upstream php5-fpm-sock {
               server          unix:/var/run/php5-fpm.sock;

  server {
       listen          80;
       server_name     suse0.local;
       root            /var/www;
       index           index.html index.php;
       autoindex       on;
       access_log      /var/log/nginx/suse0.access.log;

       location ~ \.php?$ {
               try_files $uri =404;
               include fastcgi_params;
               fastcgi_pass php5-fpm-sock;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               fastcgi_intercept_errors on;

Enable and start nginx:

chkconfig nginx on && service nginx start

By now we should have a working webserver, able to serve PHP pages. Now to the actual Mediawiki installation:

cd /var/www

Import their GPG keys and verify the signature:

wget -O - | gpg --import 
gpg --verify mediawiki-1.20.0.tar.gz.sig 


tar -xzf mediawiki-1.20.0.tar.gz 
ln -s mediawiki-1.20.0 mediawiki
cd mediawiki

With that in place, we could go to http://suse0.local/mediawiki/ and use the install wizard to install a basic, but empty Mediawiki. Once this is done, we restore a few things from our backup:

tar -C ../backup/mediawiki/ -cf - LocalSettings.php extensions images | tar -xvf -
bzip2 -dc ../backup/DB_wikidb.sql.bz2 | mysql -D wikidb

In our case, a few modifications to LocalSettings.php had to be made:

# We have not yet set up any rewrite rules so short urls 
# won't work for now
# $wgArticlePath               = "/wiki/$1";

# Disable this one for now
# $wgServer              = "";

# Our database details are different of course:
$wgDBtype           = "mysql";
$wgDBserver         = "";
$wgDBname           = "wikidb";
$wgDBprefix         = "mw_";             # Our original database used a table prefix!
$wgDBuser           = "root";
$wgDBpassword       = "s3cr3t";

# no APC/Xcache for openSUSE just now
$wgMainCacheType       = CACHE_ACCEL;

Also: check those extensions or disable them if things don't work as expected.

Now, let's run the update.php script, to address any version differences of our new Mediawiki instance:

php maintenance/update.php --conf `pwd`/LocalSettings.php

Done! The Mediawiki installation should now work. If it doesn't, try to set a few more things in LocalSettings.php:

# At the very top:
error_reporting( E_ALL | E_STRICT );
ini_set( 'display_errors', 1 );

$wgShowExceptionDetails        = true;
$wgShowSQLErrors               = true;