Saturday, April 7, 2012

NetBeans 7.1.1 Per Project PHP Include Path

I wrote the tutorial on how to add PHP libraries to the NetBeans include path assuming it would add it to the PHP include path at the same time. When I ran my test script this was not that case. To resolve that problem a custom php.ini has to be used.

It’s not ideal because it makes adding a library a two part ordeal where mistakes can occur between the NetBeans include path and the php.ini. I might have to do some more research but this appears to be the way it is in NetBeans.

To load a custom php.ini with a custom include path, first copy your current php.ini into your project directory. On Ubuntu 11.10 the php.ini for cli is “/etc/php5/cli/” while the one for apache is in “/etc/php5/apache2/”. Next right click on your project and select “Properties” from the context menu. Then select the “Run Configuration” category.

At this point you have two choices, either set the “Working Directory” to your project directory or specify the full path to your php file in the “PHP Options” field. If you go with the former you’ll have to enter “--php-ini path/to/phpini/php.ini” into the “PHP Options” field. If you had a config directory in the root directory of your project you’d set “PHP Options” to “--php-ini config/php.ini”. In the latter case you’ll have to enter “--php-ini /path/to/project/directory/config/php.ini”.

Now to add your library to the PHP include path. Open the projects php.ini file. Search for “include_path”. You should wind up around line 780. At this point you’ll have two choices commented out either UNIX or Windows. You’ll want to uncomment the line appropriate for your OS. Then append the path to your library. In my case the “include_path” was ".:/usr/share/php:/usr/share/pear” then I added “/home/david/workspace/aws-sdk-for-php” with a colon between the previous entry and the new one. The final line looked like so:

include_path = “.:/usr/share/php:/usr/share/pear:/home/david/workspace/aws-sdk-for-php”

Now when the file is run from NetBeans it will automatically load the library.

Pretty spiffy.

No comments:

Post a Comment