macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Installing a Wiki on Your iBook

by Giles Turnbull
06/05/2003

The following conversation between Mac DevCenter writer Giles Turnbull and software developer Matt Hunt (a FreeBSD fan who's very happy with the way Mac OS X turned out) walks you through a Wiki installation on Mac OS X. It's really easy to follow, and we hope you'll give it whirl.

Giles: Hi, Matt. I've been researching how to install a Wiki on my iBook. I thought there'd be a bunch of how-to documents online somewhere, but I searched all over the place and came up with not much. Could you help me out?

Matt: Yeah OK. Had you thought about which one you'd like to install? There are literally several to choose from.

Giles: Well, I've used PHPwiki before and I quite liked it. Plus the documentation says that installation is a snap.

Matt: The documentation would say that, but it is worth trying out. The first step is to download the source package. The latest source download is probably the best thing to get.

Giles: OK, I've got that, what's next?

Matt: Unpack it in the Sites directory of your home directory, tar zxf phpwiki-1.3.4.tar.gz, and enter the newly create directory.

Giles: I did that, and went to http://localhost/~myusername/phpwiki/, and Safari just downloaded a file. What went wrong?

Matt: Whoa, there! Nothing's ever quite that simple. You need to make sure that your web server is loading the PHP module and that it will use PHP documents as index pages. You'll need to edit your Apache configuration.

Giles: That's just a text editor job, right?

Matt: Right. Edit /etc/httpd/httpd.conf in your normal command-line text editor (vi, emacs, pico, whatever).

Giles: I tend to use vi.

Matt: Fine, you'll have to edit the file with an administrator account or with the root account; try sudo vi /etc/httpd/httpd.conf and make sure that you uncomment (remove the # symbol from the start of the line) these lines:

LoadModule php4_module        libexec/httpd/libphp4.so

AddModule mod_php4.c

They're not together in the file so you'll have to search for them. Whilst you're in there editing the httpd.conf, find the line that specifies:

DirectoryIndex index.html

and add a few more entries to it. Mine reads:

DirectoryIndex index.html index.php index.htm index.php3 index.cgi

and finally, you'll also need to tell Apache how to identify PHP files; add these lines:

AddType application/x-httpd-php .php 
AddType application/x-httpd-php-source .phps

Add them just after the comment about AddType (# AddType allows you to tweak...) That ought to do the trick.

Giles: Hmm, OK, that wasn't too hard.

Matt: Don't forget to restart Apache when you're done. You can start and stop it from the "Sharing" panel in "System Preferences", but that would also automatically open the firewall to the outside world, which you might not want at the moment. If Apache's running already you can run:

sudo apachectl restart

from the terminal; if not you'll have to run:

sudo apachectl start

Giles: So now I'll go see my shiny new Wiki in my browser at 127.0.0.1/~myusername/phpwiki .... oh. It doesn't work. I'm getting an error. It says

Fatal error: Call to undefined function: dba_open() in /Users/gilestur/Sites/phpwiki/lib/DbaDatabase.php on line 32

Related Reading

Learning Unix for Mac OS X
By Dave Taylor, Brian Jepson

Matt: Oh, that's just a fatal error. You need to store the content somewhere. The default is to use DBM files, but I find it's better to use MySQL as a datastore. It's more flexible. Do you have MySQL installed?

Giles: Nope. Tell me it's not complicated.

Matt: It's not complicated. You can download a package for it from the Apple downloads site. MySQL version 4 should do the job admirably, so get that and install it.

Giles: This is more like it. A nice easy package that I can just double-click on ... I've downloaded and installed it, and everything seems to have gone smoothly. It's put itself in /usr/local/mysql, which I suspect is a good place for it.

Matt: Yeah, did it start the database server?

Giles: How would I know that it had?

Matt: You can ask it: /usr/local/mysql/bin/mysqladmin status

Giles: Ah right. I've asked it and it says that various things are happening--one thread, 34 questions, 6 open tables, and so on.

Matt: That sounds just fine, if it hadn't you'd have had to start the server, that is, sudo /usr/local/mysql/bin/safe_mysqld &.

Giles: Figures. So, I've got MySQL working ... now I guess I need to tell it to start a database for the Wiki.

Matt: You're getting the hang of this now. But first you have to set a password for the "root" account on your database server. /usr/local/mysql/bin/mysqladmin -u root password sniggle will do that, but you should choose a different password to "sniggle". As an aside, that MySQL package also contains a directory called MySQL.prefPane. If you drag that into /Library/PreferencePanes you'll get a MySQL entry on your System Preferences, which will let you start and stop the server as well as setting the master (root) password.

Screen shot.
The CompleteMySQL preferences panel.

Once you've done that, you can set up a user in MySQL for your Wiki--do this in your terminal:

/usr/local/mysql/bin/mysql -uroot -p mysql

This starts up the MySQL command line client. Now, do this in the client:

> grant select, insert, update, delete, lock tables on wiki.* to wiki@localhost identified by 'password';
> create database wiki;
> \q

You should probably choose a different password to "password" there as well. Once you've done that, you have an empty database in MySQL just ready for your Wiki content, and a new user with permission to access and change the database.

Giles: Cool. After each of those commands, the MySQL client responded with some simple information about what had happened. Nothing too frightening. What's the next step? Something to do with PHP?

Matt: Not quite yet. There's a little bit more database stuff to do, and then a bit of PHPwiki stuff, and then it should work. First, for the database, in the PHPwiki distribution that you unpacked there's a directory called "schemas". Go there and issue this command: /usr/local/mysql/bin/mysql -uroot -p[password you just set in mysql] wiki < mysql.sql.

That sets up the database structure for the Wiki so that it's ready for the content, make sure you specify the password you set for the root account here.

Giles: Yikes, I'm getting confused about all these passwords. There's the sniggle one, and the password one--which one do I use when?

Matt: OK, the first thing to be clear on is that these accounts are just MySQL accounts, they're not related to the Mac OS X accounts. They have passwords stored in the database server and their permissions relate to what they can do on the database server. We're just concentrating on two accounts here, the "root" account has privileges to alter all parts of all databases that MySQL knows about: it's the "superuser". The "wiki" account that we just created has very limited privileges, it can select, update, delete, and insert data only in the Wiki database. So it can't create the tables, nor delete (in SQL terms, drop) them.

Giles: Aha, so in terms of the examples we've been using so far, the "root" account password was the "sniggle" one, and the "wiki" account password was the "password" one, right?

Matt: Right.

Giles: Now I get it. Things are getting clearer. We must be nearly done now.

Matt: Yes, we're on the last lap. You can connect to the Wiki database as the Wiki user and check that your tables are there if you like:

/usr/local/mysql/bin/mysql -uwiki -ppassword wiki
> show tables;

It should show something like this:

Screen shot.
The CompleteMySQL preferences panel.

Giles: Yes, that's exactly what I get.

Matt: Great, now we just need to get PHPwiki to connect to it and we're away. There's a configuration program provided with PHPwiki--you could try http://localhost/~yourusername/phpwiki/configurator.php, but it didn't work when I tried it.

Giles: Hmm, so there's another way?

Matt: Yes, you can edit the index.php file directly.

Giles: Fine. Which bits do I need to change and where?

Matt: All these changes are to the index.php file in the directory of PHPwiki source that you unpacked. You have to set the admin username and password options, otherwise your Wiki will give you a warning to set them when you view pages. Set them to something convenient to you (sorry, that's yet another password to remember). The lines that you're looking for are:

if (!defined('ADMIN_USER')) define('ADMIN_USER', "");
if (!defined('ADMIN_PASSWD')) define('ADMIN_PASSWD', "");

just add the username and password between the quote marks at the end of the lines. For example,

if (!defined('ADMIN_USER')) define('ADMIN_USER', "wikiadm");
if (!defined('ADMIN_PASSWD')) define('ADMIN_PASSWD', "admpassword");

The other important thing to do is to let the Wiki know where it can find the database. Find these two lines in the file:

    //'dbtype' => 'SQL',
    'dbtype'   => 'dba',

and change them to:

    //'dbtype' => 'dba',
    'dbtype'   => 'SQL',

Finally, find:

//'dsn' => 'mysql://guest@:/var/lib/mysql/mysql.sock/test',

and add this line below it:

'dsn' => 'mysql://wiki:password@localhost/wiki',

Change that to match the details of the user that you created earlier. For example, replace the first "wiki" with the username, "password" with that user's password and the final "wiki" with the name of the database, if you changed it.

And that should be all you need. You can find the line containing define('THEME', 'default'); and change 'default' to 'MacOSX', if you'd like your Wiki to blend in a little.

Giles: Great. So having made all those changes, my Wiki will now work?

Matt: Yes, it should. Try it.

Giles: OK, so all I need to do is start up my browser--I'll use Safari--and send it to http://localhost/~myusername/phpwiki ... and it works! I've got myself a wiki home page (see below).

Screen shot.
A brand new wiki, ready for use.

Matt: Phew! Remind me why you wanted one again?

Giles: After all that, I've forgotten. No, only kidding. I wanted to investigate using a Wiki for all sorts of things. There's a lot of discussion on the original wiki about using the Wiki concept for knowledge management (and more) on a local disk.

Matt: I've used Wiki to support collaboration before, for instance to support discussion on programming projects and share documentation on a company Intranet, but I never really thought to use it as my personal data store.

Giles: There's been talk about the idea of a personal wiki and various contributors have added their own suggested uses: recipe storage, journal writing, even as a private weblogging system. You can put a Wiki to use as a to-do list, and there are calendar plug-ins available for those who see the Wiki as a replacement for their normal PIM software.

Matt: I like that, maybe I'll use one on my desktop at work to replace the battered collection of notepads I have to search through when I need to remember something.

Giles: Yes, I can sympathize with that. One thing I'm interested in doing with my Wiki is using it as a bookmark manager. Although Safari remains my default browser, I still use Camino, Phoenix, and Mozilla quite regularly, and it would be good to be able to reach my bookmarks from within any of them.

Another possibility is keeping a journal, not just a personal diary but a record of everything I write. Because the Wiki is searchable, I can throw pieces of text into it and I don't have to worry too much about categorizing them or sorting them into any kind of hierarchy. As long as I know roughly what the text was about, I'll always be able to find it again.

Of course, it's worth pointing out that there are simpler alternatives to the process we've just outlined. One of the simplest is VoodooPad, a simple-to-install app for Mac OS X 10.2 and later, which operates just like a Wiki, but without the need for setting up any databases or meddling with MySQL and PHP.

Personally speaking, I'm a big fan of the whole Wiki concept. The idea of having a web page that anyone can edit sounds pretty strange when you first encounter it, but Wikis do work well as collaborative environments. The simplicity of their interface--edit, save, that's all there is to it--is what makes me want to use it on my own computer too.

Matt: Yes, you've given me some ideas there too.

Giles: Couldn't have done it without your help. Thanks!

Matt: No problem, well, apart from the problems. You can buy me a beer when I see you next. Cheers.

Giles: It's a deal. Bye.

Giles Turnbull is a freelance writer and editor. He has been writing on and about the Internet since 1997. He has a web site at http://gilest.org.


Return to the Mac DevCenter.