Community Documentation

Create your own API Site in Drupal 6

Last updated May 7, 2012. Created by zzolo on April 7, 2009.
Edited by jhodgdon, mojzis, joachim, Steven Jones. Log in to edit this page.

These instructions are for installing the API Module in a Drupal 6 environment, to build a site similar to http://api.drupal.org.

Note that the API module can parse any documented Drupal code, including contributed modules, independent of Drupal core version. This means the Drupal code you use to run your site need not necessarily be the same as the code you are parsing and displaying. In fact, it is a good idea to keep the code you are parsing and displaying outside of the site running the API module. These instructions are made with that assumption. It also means that although the API module only currently runs with Drupal 6, you can use it to build a site that displays code from Drupal 7, 8, 5, 4.7, etc.

Step 1: Install Drupal and modules

This section assumes you want to have a new Drupal installation for your API site. If you want to use an existing Drupal 6 installation, skip the download/install Drupal steps.

  1. Download Drupal 6 at: http://drupal.org/project/drupal
  2. Install Drupal. See: http://drupal.org/getting-started/install
  3. If you are using API version 6.x-1.6 or earlier, download and install/enable the Job Queue module. For version 6.x-1.7 or later, download and install the Drupal Queue module.
  4. Download and install/enable the development version of the Ctools module.
  5. Download and install/enable version 7.x-1.2 of the Grammar Parser module. (Note that the 7.x version downloads are meant for all core versions of Drupal and other modules. It is not Drupal-dependent, so it doesn't have Drupal compatibility versions.) In grammar_parser.info, you will need edit the "Core compatibility" line to change the version from 7.x to 6.x in order to enable it. Note that version 7.x-1.2 is the last version that is compatible with Drupal 6.x API module versions. You may need to click on "All releases" on the Grammar Parser project page to find this release.
  6. Download and install/enable the API module. You may want to use the Development version to get the most up-to-date code.
  7. Change permissions for the API module as needed at: admin/user/permissions

Step 2: Set-up code "repositories"

Once you have Drupal and the modules installed, you need to download some code to parse and display. There are many ways to do this; here we illustrate how to download the Drupal 6 code base using Git.

  1. Create a place for your code to go. It needs to be in a place that your web server can access (i.e., within your web document root probably):
    mkdir -p /path/to/your/code/repos/
    cd /path/to/your/code/repos/
  2. Create a subdirectory for the Drupal 6 code:
    mkdir drupal-6; cd drupal-6
  3. Get the most recent version of the Drupal 6 code base (see Version control instructions for Drupal 6.x and the Git handbook for help -- if you want to display code from some other project or branch, you can find the relevant git clone command by going to the project page and visiting the "Version control" tab). Here's the command:
    git clone --branch 6.x http://git.drupal.org/project/drupal.git
  4. As an alternative to the previous step, if you don't want to use Git to keep the code updated, you could also just download the Drupal 6 tar.gz or zip archive from http://drupal.org/project/drupal and unpack it into your repository area.
  5. Get the extra developer documentation using Git from the "Documentation" project (http://drupal.org/project/documentation). In Drupal 6, this includes the hook documentation, global variable documentation, the Form API reference, and the API documentation landing page. For later versions of Drupal, hook documentation is included in Core.
    git clone --branch 6.x-1.x http://git.drupal.org/project/documentation.git
    (Again, you can also download this from the project page.)

Repeat these steps to create repositories for Drupal 7, other projects, etc.

Note: The API module will not index code in "hidden" directories (directories whose names start with "."). It also skips directories called "CVS", as it scans your directories and their subdirectories.

Step 3: Set-up API module and index code

The last step is to tell the API module where your code repository is, by setting up a "branch", and then indexing the code so it can be displayed. The API module has concepts of "projects" and "branches". Projects correspond to projects on Drupal.org, such as "Drupal Core", "Views", "Zen Theme", etc. Branches correspond to major versions within a Project, such as "6.x" or "6.x-2.x". In the API module, a code repository is designated as a "branch". Here's how to set that up:

  1. Go to the site you set up in Step 1, and add a new Branch at: admin/settings/api/branches/new/files. Fill out the form with the following values:
    Project Identifier
    Usually you want to use the unique name of the project from Drupal.org, such as "drupal", "views", etc. (this is used in URLs; when adding another branch within the same project, be sure to use the same project identifier so they are connected)
    Project Title
    The capitalized name of the project is appropriate here, such as "Drupal", "Views", etc.
    Branch Identifier
    This is an identifier for this branch within this project, and is used as a URL suffix and in other places. Use "6", "6.x", "6.x-2.x", etc.
    Branch title
    This should include the project name, since it has to stand alone in breadcrumbs and link titles. So it should be something like "Drupal 6", "Views 6.x-2.x", etc.
    Directories
    This is a list of absolute paths to the place(s) where your code is. This is where we put in the value from Step 2. /path/to/your/code/repos/drupal-6

    Click Save Branch.

  2. Make sure your new branch is set to be the default branch.
  3. Run cron (from admin/reports/status) until your new branch is indexed. You can tell this by looking at the Recent Log Entries report (assuming you have the Database Logging core module enabled) -- when your cron run shows that no "Parse" jobs have run in the latest run, indexing is done. Also, if you visit the API administrative settings page, it will tell you how many parsing jobs are waiting (for version 6.x-1.7 and later). If you use drush and API module 6.x-1.7 or later, you can use drush cron to run cron the first time, and then subsequently use drush queue-cron to run the parse jobs. The difference is that the full cron job will scan all your projects for new files that need parsing, while queue-cron just runs the scheduled parsing jobs (which is a lot faster). If you have the Bash shell available, and Drush, and are running API module 6.x-1.8 or later, here is a sample script that will parse all of your code (although you may have to adjust the for loop to run more times if you have a large number of branches/projects):
    #!/bin/bash
    echo 'starting cron'
    drush cron
    for i in {1..60}
    do
    echo "starting queue run $i"
    drush queue-cron
    done
  4. Go to your new api documentation at: api. The content should resemble the content at http://api.drupal.org.

Step 4: Optional steps

  1. Enable the API blocks at: admin/build/block
  2. Use Steps 2 and 3 to create a Branch for Drupal 5, 7, etc.
  3. Use Steps 2 and 3 to create a Branch for contributed modules

Comments

Since this page doesn't cover

Since this page doesn't cover how to add contributed modules to your api site I'll try to explain what I did. If someone knows a better way to do it please let us know in the comments.

I created a new folder under my repos directory: /path/to/repos/contributions. Then I cd to that directory and did:

cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-6--2 -d views contributions/modules/views

To get the version 2 of views.

I added a new branch on the api settings with the path to the contributions. Finally I just copied the file index.php that I found in the contributions/docs/developer to the to /path/to/repos/contributions and made some changes to the text according to the README that you find in the api module.

Finally I had to move the contributions/docs/developer to the root of my site and not only to the drupal-6 directory inside my repos directory. I don't really know if this is correct.

The last step is to run cron like a hundred times :)

Luis

run cron multiple times

I add to run the cron hundred times so I thought this shell script could be useful. I wish the api module (or job queue) had a more optimized way of parsing all the files.

# run cron multiple times
for i in $(seq 100)
do
   wget -O - -q -t 1  http://localhost/d6api/cron.php
done

Another shell script

I'm using Mac OS X 10.5.8 and MAMP for local testing. Because I couldn't use the script scor posted above, I did some search and figured out another script.

for (( i=0 ; i<300 ; i++ ))
do
    curl --silent --compressed http://localhost:8888/drupal-API/cron.php
done

Change the number in the first line ( i<300 ) to any number of times you want to run cron.

Aki Iwata
FOREST & trees
Site building for the rest of us.
I proudly drip Drupal's delicious drops.

Here's a perl one-liner you

Here's a perl one-liner you can run from the commandline:

perl -e 'while (1) { print qx[curl http://YOURSITE/cron.php]; sleep 15;}'

Obviously this runs for ever; just check the job queue page after a while to see how many jobs are left and CTRL-C kill the script.

Empty the cache

You may also want to empty the cache if (with no semaphore entry in the variables table) you get
'Attempting to re-run cron while it is already running.'
if it is clearly not.

I remember that PHP exited once because of memory exhaustion and because of that the cache was probably not updated.

developer examples

If you want example modules (extremely useful), just download http://drupal.org/project/examples and extract it in your repo version of drupal.

Larger and non-Drupal code bases

I've had so much trouble getting other frameworks (Magento and Joomla!) to parse with this but the solution at least thus far is to bulk parse them using the Grammar Parser UI, at least for testing. Otherwise you will continue to get memory issues (unless you have a lot of RAM and I mean infinite), then Grammar Parser will eat up your memory in no time. The job_queue_cron() function really needs revision for this reason, and the module really needs a way to just bulk run with Drush or in the browser.

For GUI-addicts

I use CVS with the Tortoise GUI. I don't understand the CL stuff. Can someone translate them into something I understand and can do with a GUI, please?

Translation for GUI junkies

The steps in part 1 should be fairly easy without a command line.

Step 2:
1) create a directory inside your new drupal 6 installation, called "repos" (I think the name isn't important, but you need to remember it).
2) Get ANOTHER copy of drupal 6 (or what ever version you like), and put it in a directory called "drupal-6" inside the "repos" directory (again, name not important, but remember it).
3) Get a copy of http://drupal.org/project/documentation and extract it inside the "drupal-6" folder, so you have /path/to/your/code/repos/drupal-6/documentation. You might also want to do the same thing with the http://drupal.org/project/examples

(/path/to/your/code is the place where you're installing the API site, eg. /var/www/api, or something. will depend on the system you're setting it up on).

Steps 3 and 4 are independent of the installation method.

By the way, if you're doing any amount of developing you should definitely learn some command line stuff, it ends up be WAY faster, even after just a few days, especially with drush. Don't worry, you don't have to learn vi, or emacs :P

The above mentioned command didn't work for me (Debian lenny):
git clone --branch 6.x http://git.drupal.org/project/drupal.git

Instead, I used:
git clone --origin 6.x http://git.drupal.org/project/drupal.git

I installed GIT simply with
apt-get install git-core

In the standard repository of debian lenny there is only this an older version of git, that you would normally install via
apt-get install git git-core.

To get the latest release of git, please download from git-homepage the source code, and extract the source files. In the directory with the source files you can start compiling like this:

./configure
make
make install

If this fails, you have not installe the neccessary libraries. Get those:
apt-get install build-essential
apt-get install gettext zlib1g-dev

Try again to compile it.

Copy the git-File, that would be the result of compiling: an executable file, to /etc/bin to start git anywhere you want.

enjoy this great documentation tool.

Drupal Contrib API

For anyone not willing or able to jump through these hoops there is http://drupalcontrib.org/

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers
Level
Intermediate, Advanced
Keywords
API

Develop for Drupal

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.