Monday, August 11, 2014

Ubuntu 14 and Apache and MoinMoin! Oh my! (Part 1)

Greetings, weary tech[no] traveler!

Sure has been a while since the last post, hasn't it?   I could go on about why I haven't posted in a while, but why?  You're here to find out how to serve up a wiki, right? 

Recently I had to set up and configure and a wiki site, complete with https and SSL certificates.  For this task, I decided to use what I called the MUA (MoinMoin, Ubuntu, Apache) stack.  We're all familiar with the greatness of Ubuntu and Apache, but out of all the wiki solutions that are available why did I choose MoinMoin?  MoinMoin is a free and open source wiki solution, that is easy to install, configure, and use.  Plus, it's written in python.  As a python fanatic, I have a bias for anything python related.

So, let's get down to it!  Log into your shinny new Ubuntu 14.04 server and install Apache, as well as MoinMoin and the mod_wsgi apache module:

sudo apt-get install apache2 python-moinmoin libapache2-mod-wsgi -y

Once Apache, mod_wsgi, and MoinMoin are finished downloading and installing, enable mod_wsgi by running the following command:

sudo a2enmod wsgi

Next, let's configure MoinMoin.  You can name your wiki site anything you want, but for the sake of example let's call the wiki in this example, humboldt.  In the interest of modularity, let's configure MoinMoin so that we can serve more than one wiki later on down the road.  At the command line, create a directory for our wiki site, and copy our wiki config and wsgi config files:

sudo mkdir /usr/share/moin/humboldt
sudo cp /usr/share/moin/config/wikiconfig.py  /usr/share/moin/humboldt
sudo cp  /usr/share/moin/server/moin.wsgi   /usr/share/moin/humboldt

Next, we'll configure our wsgi file for humboldt.  Open /usr/share/moin/humboldt/moin.wsgi in a text editor of your choice.  Once opened change the following line:

sys.path.insert(0, '/etc/moin')

to:

sys.path.insert(0, '/usr/share/moin/humboldt')

Now, let's configure our wiki config file, wikiconfig.py.  This is the file that you will edit to make configurations that are specific to humboldt only.  For now, let's change the site name and interwiki name for humboldt.

Using vim, I made the following changes to wikiconfig.py:

sitename = u'Humboldt Wiki'
interwikiname = u'HumboldtWiki'

There are lots of ways to configure MoinMoin.  However, the details of wikiconfig.py is not within the scope of this post since I'm only going to cover how to install MoinMoin as well as serve it with Apache, using mod_wsgi.  I'll talk more about that in a future post.

We need to add our configuration of humboldt to MoinMoin.  First, we must create a config file specifically for humboldt.  To do that:

cd /etc/moin
sudo cp mywiki.py humboldtwiki.py

Then edit humboldtwiki.py.  Change it so that the class Config looks something like this:

class Config(FarmConfig):

    # basic options (you normally need to change these)
    sitename = u'HumboldtWiki'
    interwikiname = u'HumboldtWiki'

    # name of entry page / front page [Unicode], choose one of those:

    # a) if most wiki content is in a single language
    #page_front_page = u"MyStartingPage"

    # b) if wiki content is maintained in many languages
    page_front_page = u"FrontPage"

    data_dir = '/usr/share/moin/humboldt/data'

    data_underlay_dir = '/usr/share/moin/humboldt/underlay'


Save and close the humboldtwiki.py.  Then within the same directory, open and edit the wikis variable, in file the farmconfig.py, to look like this:

wikis = [
    ("
humboldtwiki", r"^http://humboldtwiki\.example\.com/.*$"),
]


Adding our wiki to the wikis variable in this fashion will allow us to add another wiki instance in the future (if we so choose), with little effort.  It never hurts to plan ahead!

Save and close the farmconfig.py file.

Now that we've done the initial setup and configuration of our MoinMoin wiki site, let's move onto creating and configuring our apache config file for it.  At the command line:

cd /etc/apache2/sites-available
sudo vim humboldtwiki.conf

Again, you don't have to use vim.  Just use whatever text editor you like.

In your new, blank, apache config file add the following:

# create some wsgi daemons - use these parameters for a simple setup
WSGIDaemonProcess moin user=www-data group=www-data processes=5 threads=10 maximum-requests=1000 umask=0007 display-name=wsgi-moin

# use the daemons we defined above to process requests!
WSGIProcessGroup moin


<VirtualHost humboldtwiki.example.com:80>
  ServerName humboldtwiki.example.com
  ServerAdmin webmaster@example.com

  WSGIPassAuthorization On


  DocumentRoot  /usr/share/moin/
humboldtwiki

  WSGIScriptAlias / /usr/share/moin/
humboldtwiki/moin.wsgi

  <Directory />
    Options FollowSymLinks
    AllowOverride all
    Allow from All
    Require all denied
  </Directory>

  <Directory /usr/share/moin/humboldtwiki>
    AllowOverride All
    Allow From All
    Require all granted
  </Directory>

  ErrorLog /var/log/apache2/humboldtwiki-error.log

  LogLevel warn

  CustomLog /var/log/apache2/humboldtwiki-access.log combined
</VirtualHost>


We're almost done.  Now we need to create a symlink in Apache's "sites-enabled" directory, to the config file we just created.  After that, we'll need to restart Apache.  At the shell prompt, enter the following commands:

cd /etc/apache2/sites-enabled
sudo ln -s ../sites-available/humboldtwiki.conf .
sudo service apache2 restart

Voilà!  Now you're serving up a MoinMoin wiki site, using Apache and mod_wsgi!

However, if you plan on keeping data sensitive wiki pages, you'll want to force https on the users.  If you're interested in using https with MoinMoin, check out Part 2 of Ubuntu 14 and Apache and MoinMoin! Oh my!

2 comments:

Unknown said...

Epic-Curean , Thanks for the great post. I am having trouble getting the wiki to display I get a page not found error. I have followed your steps and not sure of the URL to see the wiki page. Can you post the URL you used to test the wiki?

Thanks
Scott Van Caster

Epic-Curean said...

Hi Scott,

It could be an issue with your apache config file for your MoinMoin site. Can you post that apache config file (into http://pastebin.com/ and post the link in your reply), so I can see the URL you have defined?