Need help with Mongo and PHP 7.4

autoload.php is a conventional name for a file which loads a bunch of other php files.

PHP packages typically come with an autoload.php file.

Composer, the tool that installs the MongoDB PHP library on top of PHP’s own MongoDB driver, installs all the packages you install via Composer in a directory called vendor. It’s just like npm in Javascript where everything is installed in a project subdirectory called node_modules.

So typically for PHP + MongoDB you:

  • make sure the PHP driver mongodb.so is installed and called out in your php.ini files for web and for cli
  • create your project directory
  • use Composer to install MongoDB’s PHP Library in your project directory, which results in you having a ./vendor subdirectory of your project

Then, in your program code, require_once ./vendor/autoload.php which loads all the modules Composer installed in your ./vendor subdirectory of your project.

2 Likes