Last updated April 16, 2009. Created by jbrauer on July 14, 2005.
Edited by Chris Johnson, LeeHunter, clemens.tolboom, add1sun. Log in to edit this page.
For Drupal developers, The Drupal API can be an invaluable resource. However, some developers might want to have a local copy of the API if they are unable to access the Internet or if they want a backup just in case Drupal.org goes offline. If you want to keep an offline API for yourself, you can follow these instructions.
This tutorial assumes that you already have a Drupal installation, you already know how to install Drupal, and that you already know how to install and enable modules.
Step 1: Set up the Drupal installation and get some files
The Drupal API runs on the API Module, and you can use this module to create a custom-tailored API with documentation for the Drupal core and contributed modules. At the end of this tutorial, you will have a searchable API for your Drupal installation.
You'll need to do a couple of things:
- Download a fresh installation of Drupal 5.
- Download and install the API module onto that fresh installation. For your convenience, the link is http://drupal.org/project/api.
- Enable the API module. This will give you a new menu item at: Administer > Site configuration > API reference. Leave this alone for now.
Step 2: Get the Developer Documentation (Optional)
If you don't care about the developer documentation, you can just skip this step and move on to step 3.
From this point forward, if you want the Drupal Developer Documentation you will need to download them via CVS. Here's a question for you: Have you used CVS before?
- Yes, I have used CVS before
-
If you already have a CVS client and a CVS account, you probably know what to do. Check out the Developer Documentation under this path:
/contributions/docs/developer. - No, I haven't used CVS before or "What's CVS?"
-
First, you might want to read up on What CVS is and how Drupal uses CVS.
Then, you'll need to download a CVS client. TortoiseCVS is a good one for Windows users.
If you have the Eclipse SDK, you already have a CVS client. You can follow the instructions for the Eclipse SDK, but remember when using "checkout module" you must use "
/contributions/docs/developer".
Step 3: Set up the API
-
If you got the developer documentation in step 2, Head into the folder where you checked out your developer documentation. Go into "Contributions", and copy the "docs" folder to the root folder of your main Drupal installation.

-
First, head to Administer > Site configuration > API reference.

-
Under Short name, enter the version of your main Drupal installation (in this case, it's 5.x). Under Long name , type in "Drupal 5.x".
-
Under Directory name, enter the absolute path (the ABSOLUTE path) to your main Drupal installation. This means the path starting from your root directory! (In my case, it's /home/bt/public_html/drupal-5.3).
If you don't have a main Drupal installation at this point, you can just use the absolute path to your API installation.
-
Under Maximum files to scan per cron run, choose 200 (there may be some memory ramifications; see "Problems" below).
-
Click Save changes.
-
If you have multiple Drupal installations, see the section "Multiple Drupal Installations" below.
-
Scan the PHP manual pages by clicking the button "Index PHP manual pages" (refer to screenshot). In your API files, any references to core PHP functions will have links to them.

-
Click "Reindex".
-
It says it'll be re-indexed the next time you run cron.php, but that will take too long. Click on "cron.php" in the link.

-
Wait. Grab a coffee, because this might take a while. (If you have problems with "Memory Size Exhausted", you may want to check the "Problems" section below.)
-
Once it's done, go back to your API configuation page, and click "Save changes" again (yes, again).
-
Click on "API reference", and... huttah! Your end result should look something like this image.

NOTE:If you didn't install the optional developer documentation, there won't be much on the page. Instead, it'll probably have something like this:
A main page for this branch has not been indexed. A documentation comment with @mainpage {title} needs to exist, or has not been indexed yet. For Drupal core, this is availiable in the developer documentation in the contributions repository.
After this, you may want to set the "maximum files to scan" back to 10.
Step 4 (optional): Extra configuration
The API.module Blocks
You'll probably want to do this. The API module has a couple of blocks. Go to Administer > Site Building > Blocks, and you'll find two: "API navigation" and "API search".
You can put these anywhere you like. Go back to your API reference page, and it should look something like this:

Multiple Drupal installations
What if you have a Drupal 6 or a Drupal 4 installation you would like to index? Head back into the API reference page, and type in the details of your second Drupal installation. In this case, it's a Drupal 6 beta 3 installation.
Note: The Developer Documentation you installed on your main installation will not show up unless you copy it over to your secondary Drupal installation.
Next, click "Save Changes". In the "Default Branch" section, you can select the default page that shows up on your API reference. Reindex, click "cron.php" at the top, and grab another cup of coffee. Click "Save Changes" again, and the end result shoud look something like this:

Problems?
It says "Memory Size Exhausted" when I try to run cron.php. What should I do?
This means that you need to raise your PHP memory limit. If you know where your php.ini file is, open it up and search for "memory_limit". It should have a number next to it. Type in something like "32M".
If you don't know where your php.ini file is, or if you're running on a host that forbids you from setting it, you'll simply need to lower the amount of files indexed in the API configuration page.
Comments
Missing step
I think you missed a step. In order to see anything (when you click on the 'Drupal HEAD' link), you need to copy the developer folder (from docs/developer) to the root of your drupal site. I do this in Step 2, as #3.. in other words, before indexing.
Contribution Repository
From Contributions repository You can get the repository with this command
with the command
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout contributionsJust the docs, ma'am
Or if you don't want all the contributed modules and just want the docs/developer stuff...
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-4-7 -d developer contributions/docs/developerSome notes: You can change
DRUPAL-4-7toHEADif you want head versions instead of 4.7 versions. And the-d developersaves it into a new developer folder instead of the full contributions/docs/developer folder tree.- John (JohnAlbin)
Update this to 5.x?
I was already wondering about the need to replace file_get_contents (which my host blocks as well) with cURL - "doesn't Drupal have it's own http client?" Sure enough, the relevant code in the current api module has since been replaced by drupal_http_request. :)
I have installed api on
I have installed api on Drupal 5.5 and in all cases the section labelled Components for Drupal, the hook section always comes up with Page not Found whenever I click on the links.
What could I be missing?
It is only the links in that section that are not working.
===============================
===============================
Yoga Redux, Yoga for Geeks
A True Story
adding a main page
After installing the module I came across this message
What took me a little while to figure out is that the comment can be in any indexed page - the developer docs have a separate file called index.php - but this isn't required.
The title must be the same as the "Long name" in the api settings.
Also it's important to enable the API search and API navigation blocks (in admin/build/block)
For me it makes sense to have a separate drupal installation for my API documentation - this is configured to index the documentation of the other Drupal installations that exist on the same machine.
Sean Burlington
www.practicalweb.co.uk
London
Sean Burlington
www.practicalweb.co.uk
don't need a separate drupal installation
seanburlington
Instead of pointing to the root of my installation where a lot module that I don't need to make documentation on thus wasting resources on (undestanding your intention of making a separate drupal installation), I simply point to the modules which I need documentation and separate them as in the help text with colons(":").
yes ... but
Absolutely you don't need a separate Drupal install
The reasons I have done this
Sean Burlington
www.practicalweb.co.uk
London
Sean Burlington
www.practicalweb.co.uk
Quick Drupal 6 Instructions
I do not currently have editing rights to this article, so for now will link to this: http://zzolo.org/thoughts/api-module
--
zzolo
Alan Palazzolo