Getting started with Zope for Linux and Solaris

zopeDue to the increased complexity of Web applications, programmers have hit the limit of what can be done with CGI. Zope provides the basic services provided by CGI, such as allowing users to log on to e-commerce web sites and community portals in order to receive personalized content, all while making software development easier. In this article, I will cover what Zope is, how you install it on a Linux or UNIX system, and explain a few of the concepts you’ll need to understand in order to be able to be productive with it.

Let’s face it: It’s become harder and harder to tell the difference between content and software on the web. After all, knowledge databases, search engines, content management systems, Web logs, and even our own discussion forums blur the lines every day. Static content just isn’t enough these days, and with the increased demands placed on those web applications, they’re fast becoming more and more complex.

It used to be that programmers could do whatever they needed with CGI (Common Gateway Interface). Due to the increased complexity of Web applications, programmers have hit the limit of what can be done with it.

Enter Zope.

Zope provides the basic services provided by CGI, such as allowing users to logon to e-commerce web sites and community portals in order to receive personalized content, all while making software development easier. In this article, I will cover what Zope is, how you install it on a Linux or UNIX system, and explain a few of the concepts you’ll need to understand in order to be able to be productive with it. I’ll presume that you’re at least a little bit familiar with object-oriented programming. This isn’t a comprehensive installation and configuration manual - there are already enough of those. This is more of a “what is it and how do I use it to make my life easier/get my boss off my back” article.{mospagebreak title=What is Zope?} Zope is a couple of things. First, it’s a Web application server. It other words, it serves up Web applications, which is what you interact with whenever you submit a comment to a “blog,” or when you put stuff into your e-commerce shopping cart. A Web application is called that because it only requires a Web browser for access. They’re usually pretty ease to use, although programming them is an entirely different matter.

Secondly, Zope is a Content Management Server. It allows an experienced Zope programmer to quickly build a customized content management system (CMS) that, for example, displays selected Zope functions to users, while still allowing other functions to be later programmed in if necessary. An example of this is a website that allows a user to input, format, and post text, such as a press release, without the need of heavy HTML formatting on their part.

Because of the growing complexity of Web applications, it’s becoming increasingly important to mix numerous systems, technologies, and – more importantly – development teams. The database guys need to make sure they’re in sync with the Web guys. The Web guys are asking the application programmers to deliver what they need in order to connect to the database. All the while, the application programmers are still waiting for the specification from both of them. Development teams need a common basis for their work. Zope provides this basis by allowing you to mix HTML, DTML (Zope’s own scripting language), SQL, Python, and maybe even a little Perl into Zope as needed.

Zope’s biggest strength is the fact that, since it’s written in Python, it’s object-oriented. It also comes with an integrated object-oriented database (ZODB) and Web server (ZServer). Since its transaction oriented, it allows users to do things like undo actions and so on. It can be connected with numerous relational databases via its Database Adapters (DAs): Oracle, Sybase, MySQL, Postgres, and Interbase. In addition to all this, the Zope community makes available hundreds of applications just for Zope (known as Zope products), which can be easily implemented by users with no programming knowledge using Zope’s integrated web management system (I’ll talk a bit more about this later).{mospagebreak title=Downloading and Installing} For the sake of simplicity, I’ll be installing Zope from the .tgz packaged binary release available here (Zope.org). At the time of this writing, the most current stable release is Zope 2.6.2. If you’re interested in using prebuilt RPM and DEB releases for Red Hat, SuSE or Debian, check out http://zope.org/Members/medienlabor/packages. Some distributions include Zope as an optional component in their basic install (Red Hat, for example, includes Zope in its Power Tools package). In that case, you should check the included documentation on how to get started with Zope. If you’re using Solaris, make sure that you’re using GNUtar and gunzip, not the default tar program, which can’t handle the length of file paths. You can grab GNUtar from the Solaris Package Archive.

Although I’m doing the installation on Red Hat Linux 9.0, these instructions should be good for most other Linux systems, as well as Solaris. Other operating systems might require that you compile Zope. Again, for the sake of simplicity, I will presume that the user will be you and that you will install and run Zope from your own home directory (in this case, its /home/omar). To extract, open up a console window and type the following (not including the dollar sign or anything before it):

[omar@localhost omar]$ tar xvzf Zope-2.6.2-linux2-x86.tgz
Note that the name of the file will change according to the architecture under which you run it. For example, the source file for Solaris is named Zope-2.6.2-solaris-2.8-sparc.tgz. Untarring the package will unpack Zope into a new directory named according to the file you downloaded, for example, /home/omar/Zope-2.6.2-linux2-x86/. To install the application, type the following:

[omar@localhost omar]$ cd Zope-2.6.2-linux2-x86/
[omar@localhost Zope-2.6.2-linux2-x86]$ 
./install
When Zope installs, it automatically creates the user ‘admin’ and autogenerates a password. We’ll cover how to change that password in the next section. For the moment, you’ll want to keep it somewhere safe. As far as the installation goes - that’s pretty much it. Congratulations!

If you’re running an “unsupported” operating system, or if you just want to install Zope from source, worry not, for the source installation is almost as easy as the binary installation. There are a couple of things you have to be sure of before you go on installing Zope however:
  1. Make sure you have a C compiler, preferably GNU gcc.
  2. Make sure you have a recent version of make, preferably GNU make.
  3. Make sure you have Python installed on your system. To be on the safe side, don’t go with the latest version. In fact, Zope.org recommends Python 2.1.

As for the Python requirement, if you’re compiling Zope from source, you should compile Python as well (check this site for compilation instructions). Python is included in the binary versions of Zope, but not in the source. Also, some vendor-supplied versions of Zope include Python, yet lack the necessary development files to compile Zope from source.

Now that you have all the necessary components, download the latest version of the Zope source from the Zope.org download page. Once you’ve downloaded it to the desired directory (again, I’ll presume this is your home directory), type in the following set of commands:
[omar@localhost omar]$ tar xvzf Zope-2.6.2-src.tgz [omar@localhost omar]$ cd Zope-2.6.2-src/ [omar@localhost Zope-2.6.2-src]$ python wo_pcgi.py ---------------------------------------------------- Deleting '.pyc' and '.pyo' files recursively under /home/omar/Zope-2.6.2-src... Done. ---------------------------------------------------- Compiling python modules ..... chmod 0711 /home/omar/Zope-2.6.2-src/var ---------------------------------------------------- setting dir permissions ---------------------------------------------------- creating default database chmod 0600 /home/omar/Zope-2.6.2-src/var/Data.fs ---------------------------------------------------- Creating start script, start chmod 0711 /home/omar/Zope-2.6.2-src/start ---------------------------------------------------- Creating stop script, stop chmod 0711 /home/omar/Zope-2.6.2-src/stop ---------------------------------------------------- creating default inituser file Note: The initial user name and password are 'admin' and 'zM8fQy0k'. You can change the name and password through the web interface or using the 'zpasswd.py' script. chmod 0600 /home/omar/Zope-2.6.2-src/inituser ---------------------------------------------------- Done!
Note that in Zope, the build directory and the install directory are one and the same. Congratulations! Any which way you decided to do it, Zope is now installed. Hazzah! {mospagebreak title=Starting Zope} After the system finishes installing, provided there are no errors, go ahead and start Zope by firing up the start script.
[omar@localhost Zope-2.6.1-linux2-x86]$ ./start ------ 2003-09-10T15:59:50 INFO(0) zdaemon Started subprocess: pid 4364 ------ 2003-09-10T15:59:52 INFO(0) ZODB Opening database for mounting: '143968976_1063223992.338720' ------ 2003-09-10T15:59:52 INFO(0) ZODB Mounted database '143968976_1063223992.338720' at /temp_folder ------ 2003-09-10T15:59:54 INFO(0) Zope New disk product detected, determining if we need to fix up any ZClasses. ------ 2003-09-10T15:59:55 INFO(0) ZServer HTTP server started at Wed Sep 10 15:59:55 2003 Hostname: localhost.localdomain Port: 8080 ------ 2003-09-10T15:59:55 INFO(0) ZServer FTP server started at Wed Sep 10 15:59:55 2003 Hostname: localhost.localdomain Port: 8021 ------ 2003-09-10T15:59:55 INFO(0) ZServer PCGI Server started at Wed Sep 10 15:59:55 2003 Unix socket: /home/omar/Zope-2.6.1-linux2-x86/var/pcgi.soc

Notice the TCP port used; Zope will default to 8080. This might be different under some configurations which use nonstandard ports for Zope. Open up your web browser of choice and in the address/location bar, type in http://localhost:8080 (or whatever port number was defined). You should see the Zope Quick Start page. Congratulations! If you installed Zope from a DEB, RPM, or from the included version on your system disk, check the included documentation on how to start Zope. For other problems, check out the #zope IRC channel in OpenProjects.net as well as http://www.zope.org/Resources for mailing lists and FAQs. Finally, there’s the Zope corporate support contract. You can find out more about it on Zope.com.

Now, if you want to do anything even remotely interesting with Zope, you’ll have to enter the manage screen by going to http://localhost:8080/manage. Otherwise, you’ll simply be looking at a welcome screen wondering whether what you have is a Ferrari or a Yugo. Trust me, it’s a Ferrari (actually, it’s more like a high Lexus, but that’s a-whole-nother can of worms). When you go to the address, you’ll be prompted for the User Name and Password that you were given at installation. If you’ve forgotten the password already, and didn’t follow my advice to keep it somewhere safe then open up a command prompt and type in the following (again, without the dollar sign or anything before it):

[omar@localhost Zope-2.6.2-linux2-x86]$ python zpasswd.py access

Username: 
admin
Password:
Verify password:
 
Please choose a format from:
 
SHA - SHA-1 
hashed password (default)
CRYPT - UNIX-style crypt password
CLEARTEXT - no protection
 
Encoding: SHA
Domain restrictions:
 

The Domain restriction specifies from which domain the user is allowed to access Zope. Leaving that field blank indicated that the user can logon to and administer Zope from any location. Go ahead and logon to http://localhost:8080/manage page. When you do, and you successfully put in your user name and password, you’ll be greeted by the Zope Management Interface (ZMI). {mospagebreak title=Z-M-I. Z-M-I run. Run, M-I. Run.} Before I go on to explain the ZMI, keep in mind that Zope is object-oriented. Because of this, Zope does not “serve up” HTML files stored on your hard drive, which is what a Web server like Apache or IIS will do. These objects, however, are not objects that are stored in your hard drive with .html extensions. Instead, Zope stores those objects in the Zope Object Database (ZODB), in a file called Data.fs. Now, the primary way to interact with these objects will be the ZMI, although there are other methods, such as FTP and WebDAV.

The ZMI’s basic interface uses three browser frames: the Navigator frame, Workspace frame, and Status frame.
  1. The Navigator frame on the left allows you to look into the Root Folder, which contains almost everything which is meaningful in your Zope instance. Keep in mind that since Zope is object oriented, almost every link or button in the ZMI is an action taken against an object.
  2. The Workspace frame on the right shows the object you’re managing at the moment. The tabs across the top show you different views of the current object, each allowing you to perform a different management function on that object.
  3. The Status frame at the top both shows you you’re logged in as and lets you select various actions via the drop down menu
    • Zope Quick Start: Presents the Quick Start page which has links to documentation and community resources.
    • Preferences: Allows you to set the default preferences for your ZMI. Note that the information here is associated with your browser via a cookie, not with your Zope user account.
    • Logout: Self evident. What isn’t self evident is that some browsers have problems with this function due to the way basic HTTP authentication works. If you experience any problems, try simply closing and reopening your browser.

Now that you have that under your belt, let’s create our first user.
  1. Click on acl_users (User Folder) on the Navigator frame.
  2. Click Add on the next screen.
  3. Enter a user name (say, ZopeZealot), password, and confirm.
  4. Select “Manager” to create a user with access to all Zope functions. You can ignore the Domain field.
  5. Click Add to add the user.
  6. Click on the drop down menu at the right hand side of the Status frame and logout. Log back in as the user you just created.

Alright, now let’s go ahead and try adding a folder.
  1. Go to the folder where the new folder is to be located, for example, the Root Folder.
  2. Click on the drop down menu on the upper right hand side of the Workspace frame. Select Folder and click on Add.
  3. On the Add Folder window, enter the ID for the folder in the Id field, for example “Test_folder”. Note that every folder needs an ID because it’s how Zope identifies objects.
  4. Enter a descriptive title on the Title field. This field is optional, but in it you can provide a more detailed description of a folder. For now, enter “My test folder”.
  5. Check the Create public interface box if you want to make this folder browser viewable. Checking this box will create the necessary index_html file. Likewise, check the Create user folder in order to define users who have access this only this folder and its subordinate objects. Both of these options can be added at a later time. For now, we’ll choose both.
  6. Click Add to create the folder.

You’ll now see it listed under the Root Folder page, along with the given Title description, for example Test_folder (My test folder). To test out the folder, go ahead and type the following into you browsers address bar: http://localhost:8080/Test_folder. You should get the following message:

My test folder

This is Page Template index_html.

Congratulations! Now, feel free to edit the HTML by clicking on the folder ID from the Root Folder page, then clicking on index_html. Feel free to test out Zope’s included example applications by going to http://localhost:8080/Examples. {mospagebreak title=Extending Zope} As I mentioned before, Zope object oriented. As such, one of its biggest strengths is its ability to reuse code. Zope has the ability, through its components, to extend its functionality. ZClasses, TML, Z SQL Methods, Python products, and Python scripts are all different ways of working with Zope.
  • ZClasses allow the developer to define new objects. These can be based on common Zope objects, like a folder or DTML document, but can be extended any way. ZClasses can be created and managed with nothing more than Zope’s Web interface. In other words, no Python is required.

  • Z SQL Methods allow database developers to program directly via Zope’s Web interface. The methods become available when he has compiled the Database Adapter (DA) for the database Zope is supposed to open a connection. Z SQL methods also make it easy for developers to switch from a development database to a production database by simply changing the connection object so that it connects Zope with the actual working database.

  • DTML, or Document Template Markup language, is Zope’s built in scripting language. Like PHP, DTML tags are embedded in a web page and, when the page is called via a web browser, the tags are executed. DTML is not designed to be a primary language in the development of Zope applications, but rather it is meant to be more of a glue, which connects dynamic data., regardless of where it’s held. In addition, DTML can serve as a template defining the visual appearance of the web site and how the dynamic data should be represented.

  • Zope Products are applications specifically written for Zope.

  • Python Modules: Because Zope is mostly written in Python and, therefore, is object oriented, it is very easy to use existing Python modules to augment or enhance your web applications. If you’re using Zope for a project, then make sure to check out Python.org on a regular basis. There’s a good chance that your project requirements have already been met by a Python library. Also, make sure to check out The Python Image Library (PIL) and The ReportLap Library, which is capable of creating dynamic Adobe Acrobat PDF files.

As I’m sure you can tell, Zope is an extremely powerful tool. I hope that this introduction has given you a good starting point into understanding Zope. Although there is much to learn, having a clear understanding of how Zope works will help you make this one of your favorite tools.

Google+ Comments

Google+ Comments