Today I am going to show you how to correctly install ApiGen in NetBeans 8 IDE using PEAR. Well, ApiGen is a handy, powerful and customizable code documenting tool which will help you to generate code documentation for your source code. So let’s begin installing ApiGen in to NetBeans.
- First, you need have PHP installed in your machine and environmental variables set for the installed PHP. (If you need any help in installing PHP or setting environmental variable, just drop me a comment below, I will help 🙂 )
- Open up your command prompt in Administration mode (right click and run as administrator) and type this command to enable PEAR auto discovery mode. Auto discovery mode will help you to automate dependency installation. Because ApiGen requires tools such as Texy, Nette and so on. The good thing is when the auto discovery mode is on, it will install all these dependent tools automatically for you.
pear config-set auto_discover 1
- Once the auto discovery is enabled, you can install ApiGen using following command,
pear install pear.apigen.org/apigen
- Once all channels are installed (see the image above), you will be able to import ApiGen in NetBeans.
- Now open up your NetBeans 8 IDE and go to Tools->Options. Now you will see a pop up window. Select PHP then select ‘Frameworks & Tools’ tab from the window.
- From that tab, select ApiGen from the left pane. Then, in that pane, you will see ApiGen Script (apigen or apigen.bat) has been detected automatically. See below,
- If, apigen or apigen.bat has not been selected automatically, you can click the search button and locate it from the appearing popup window (See below). If not, manually give the absolute path to your apigen or apigen.bat file which is usually in C:\wamp\php\apigen or C:\xampp\php\apigen location.
- Now the installation part of the ApiGen is done. Now we can use this tool to generate code documentation.
- Select your php project and right click and choose Generate Documentation. See below,
- As you are running this first time you will get a popup window, asking to give a path to save your documentation files. Give any path, I created a folder called ‘api’ under the same project directory to save the ApiGen generated code documentation. See below,
- As soon as you hit the ok button, you should see few lines appearing in the notification panel of NetBeans. After few seconds (it depends on how big your project is) you should see a success message. See below,
- That’s it. Now if you navigate to the path where documentation has generated, you will see some files have been created by ApiGen. See below,
- Open the ‘index.html’ in a browser to view your completed documentation. I am sure you will love it 🙂
- To customize you ApiGen, simply right click on your project, select ‘properties’ and in the appearing window select ‘apigen’ from the left hand side pane. In this window you can give some customizations such as what to include what to exclude so on and so forth. See below,
- When installing ApiGen from the command prompt if you see an error message or set of error messages at the end saying folder creation failed, you are probably not running the command prompt in administrator mode. So, open it again using administrator mode to solve this problem.
- When running the code documentation in NetBeans you see an error saying cannot find location to ‘Texy’ or you don’t see any error but the ApiGen hasn’t created documentation for you. This is probably because, in the ApiGen’s configuration file (Right click and open C:\xampp\php\apigen file in a text editor), path has incorrectly given to the texy.php file (it should be C:\xampp\php\pear/Texy/src/texy.php not C:\xampp\php\pear/Texy/texy.php, recognize the missing ‘src’). Just correct the path to ‘texy.php’ file. See below,
That’s it for today. Hope you enjoyed my post. Feel free to throw your feedback, suggestions, practically anything, in the comments section below. Thanks 🙂