What's the best place for external libraries in a PHP project?

php

Solution

You're on the right track, putting everything in `/lib`. I'd suggest separating each one into its own subfolder, since many libraries will have multiple files. So have `/lib/googlemaps`, `/lib/recaptcha` and so on.

If you're still not sure, perhaps take a look at some frameworks like CodeIgniter. Joomla uses the system I described above. They even have `/lib/joomla` for the whole Joomla framework.

There's no need to over-think it. As long as it's easy to find and include the libraries, don't worry about it.

Problem

What's the best practice for locating external libraries in a PHP project (e.g., GoogleMapAPI, Recaptcha, etc.)? Right now I have all classes in /lib or subdirectories thereof, and am using Zend convention for naming (e.g., class Foo sits in /lib/Foo.php, class Db_Bar sits in /lib/Db/Bar.php). But should I segregate third-party stuff? If so, how? Where? Inside /lib? Elsewhere? Note: Autoloading of these classes is not an issue because they are always included/required explicitly where needed (unlike my own classes). THANKS!

Original source