Setup Mediawiki Upload Files on AWS S3

From Bonus Bits
Jump to: navigation, search


This article gives the steps to setup Mediawiki to use Amazon Web Services Simple Storage Solution (S3) as it's file repository. This can enable a High Availability (HA) Configuration paired with a shared database solution such as Relational Database Service (RDS). Meaning multiple Mediawiki servers can be stood up behind an Elastic Load Balancer (ELB), shared files from S3 and shared a database on RDS. This example is for RHEL/CentOS 6.


  • AWS Account

Setup and Mount S3 Bucket

HowTo: Mount AWS S3 Bucket on CentOS EC2 Instance

Copy Existing Files to S3

  1. Copy the files using the regular file system copy methods. the aws s3 command tends to botch up permissions.
    cp -R /var/www/html/wiki/uploads /var/www/html/wiki/s3mnt

Config Mediawiki

After verifying the files and access it's time to switch from local to S3 in the LocalSettings.php

  1. Edit LocalSettings.php
    vim /var/www/html/wiki/LocalSettings.php
  2. Change uploads directory
    $wgUploadPath = "{$wgScriptPath}/s3mnt";t
  3. Restart Apache
    service httpd restart


  • Manually Mount with Fuse Debug Mode on (Unmount first)
  • sudo s3fs -f -o multireq_max=5,allow_other,use_cache=/tmp/cache bucketname /mnt
  • A few times I had the mount not work on boot when creating a new instance based on an AMI. To fix it all I had to do was unmount and re-mount the S3 bucket as root.
    umount /var/www/html/wiki/s3mnt
    mount -a
  • Another issue I ran into was ownership and permission metadata not transferred completely to when copying to the S3 bucket
    • Set directory permissions
      chmod 755 /var/www/html/wiki/s3mnt/thumb
    • Set file permissions
      chmod 644 /var/www/html/wiki/s3mnt/*
    • Set ownership
      chown -R apache:apache /var/www/html/wiki/s3mnt/
    • Restart Apache
      service httpd restart