Within this section is discussed the installation procedure for WebPython prerequisites. Each step of this procedure is given its own subsection, but detailed installation instructions for the necessary libraries and servers are outside the scope of this document. However, these applications all have excellent installation instructions of their own available, to which I suggest you turn should you have difficulty installing them.

2.1.1 Apache

WebPython depends on having the Apache web server running and properly configured. More specifically, a version from the 2.0 branch (preferably the latest version) is required. This is because WebPython runs on top of the the 3.x (currently, 3.1.x) branch of mod_python, which gives a large speed increase over plain CGI, mostly because mod_python embeds a Python interpreter in the server process, rather than spawning an external process for every request.

Installing and setting up the Apache HTTP server is beyond the scope of this document. However, the Apache HTTPD home page contains plenty of documentation material. But I will say this: WebPython needs mod_rewrite, so be sure to enable it in your build by using the "--enable-rewrite" option when running the "./configure" script.

All right, Apache installed and configured? If so, it is now time to install mod_python. If not, then take a look at the httpd.conf file for my workstation (which doubles as my WebPython test server) if you are having trouble. This file includes mod_python directives, as well as some application-specific rewrite rules, which you can safely ignore for now.

2.1.2 mod_python

mod_python is the key technology upon which WebPython depends. Some people, for some reason, have reported difficulties in installing mod_python, but I have never found this to be the case. Download the latest version of mod_python (3.x branch) and while you are at the site, read the documentation. Or at least read the section of the mod_python 3.1 docs entitled "Installation." Doing so will save one endless trouble and aggravation.

There is one more change we need to make to the httpd.conf file after the LoadModule directive mentioned in the documents. We need to configure the web server to treat any sub-sub-directory named "code" (that is, the last part of the URL http://server.fake/blah/code) as containing any and all Python code for a given project. In other words, we need to set up Apache to call mod_python to serve Python files from a code directory. So add the following code after the DoumentRoot </Directory> tag (in my http.conf I have this directive at line 372):

<Directory "/path/to/document/root/*/code">
	SetHandler mod_python
	PythonHandler mod_python.publisher
	PythonDebug On
</Directory>

Of course, you will want to replace "/path/to/document/root/" with your actual DocumentRoot.

So that should do the trick for mod_python (but do not forget to add the LoadModule directive). Now we need to install (and configure, naturally) MySQL.

2.1.3 MySQL

First, a note on database selection. Many people feel that MySQL is a "toy" database, lacking the features and stability of more mature and robust database systems. While MySQL certainly has some quirks and is not as failsafe as, say, Oracle, it is undoubtedly the most user-friendly SQL database server in existance. This is the reason I have selected it for our tutorial. However, if you want a more robust database, WebPython is also compatible with PostgreSQL, an excellent open-source database server. Simply have PostgreSQL running and configured, then connect to your server using the pgsql module. See the reference for more details.

That said, we must now look to the installation of MySQL. I recommend the latest version from the 4.1 branch. Because of compatibility issues with MySQLdb (the low-level MySQL Python interface that WebPython uses) WebPython will not work with any version from the 5.0 branch. However, be careful. When you install MySQLdb (more on that later) if you compile it against the libraries of MySQL 4.0.x, then you absolutely must set the passwords for your database users using the OLD_PASSWORD() function. See the MySQL documentation for more information.

Which leads us to our next task. Installing MySQL can be very easy, provided there is a pre-compiled binary for your platform. If there is, I suggest that you use it, but still read the installation instructions. If there is not, then you will need to compile an installation from source. But it is not too difficult; the MySQL developers and maintainers have excellent documentation.

Once you have MySQL installed and running, you need to change the password for the root user. Do this by executing the following command (using the mysql client, as root):

SET PASSWORD = OLD_PASSWORD('this_is_a_fake_password');

Replacing "this_is_a_fake_password" with the pasword you desire to use, of course.

2.1.4 More on PostgreSQL

Installing PostgreSQL is much like installing MySQL. However, you do not need to change the password for any user; PostgreSQL has not recently changed the password-hashing mechanisms as MySQL has. You simply need to install pygresql, the Python interface to PostgreSQL. Installation is simple, though the documents do not make it look so. Provided you have Python and a C compiler installed on your system, just run the following commands (to build and install, respectively):

/path/to/PyGreSQL-3.6.2$ python ./setup.py build
/path/to/PyGreSQL-3.6.2$ su -c "python ./setup.py install"

Where "/path/to/PyGreSQL" is, of course, the source directory of PyGreSQL. And, of course, the second command will ask you for your root password to execute the installation; be prepared!

2.1.5 MySQLdb

MySQLdb is the Python interface to MySQL. WebPython depends on it to access MySQL databases. The latest version as of this writing is 1.2.0, which will work with both the 2.3 and 2.4 branches of Python. Grab it from its sourceforge page. Installation is straightforward (it installs like any other Python package) and there is good documentation. There really is not much for me to say here, except that you need to be sure to use the old password hashing on any MySQL users used from Python.