Declare App Dependencies

Page last updated:

Page last updated:

Cloud Foundry recognizes an app as PHP by the existence of a .php file in the root directory.

The demo app you deployed has a composer.json to require additional dependencies, and it looks something like this:

{
  "name": "laravel/lumen",
  "description": "The Laravel Lumen Framework.",
  "keywords": ["framework", "laravel", "lumen"],
  "license": "MIT",
  "type": "project",
  "require": {
    "php": ">=7.0.0",
    "laravel/lumen-framework": "5.2.*",
    "vlucas/phpdotenv": "~2.2",
    "fzaninotto/faker": "~1.4"
  },
  "require-dev": {
    "phpunit/phpunit": "~4.0"
  },
  "autoload": {
    "psr-4": {
      "App\\": "app/"
    }
  },
  "autoload-dev": {
    "classmap": [
      "tests/",
      "database/"
    ]
  }
}

The composer.json file determines both the version of PHP that will be used to run your application on Cloud Foundry, as well as the dependencies that should be installed with your application. When an app is deployed, Cloud Foundry reads this file and installs the appropriate PHP version together with the dependencies using the composer install command.

Run this command in your local directory to install the dependencies, preparing your system for running the app locally:

$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file

...

Generating autoload files

Once dependencies are installed, you will be ready to run your app locally.

Upon running cf push, we will also push our whole dependencies folder vendor. Since Cloud Foundry runs composer install anyways, this is redundant and should be omitted to save bandwidth and even more importantly: time. You can create a .cfignore file which works just like a .gitignore file and which tells Cloud Foundry what files should be excluded when pushing. Let’s create a .cfignore file and exclude the vendor folder:

vendor

Pro Tip: Composer created a `composer.lock` file when you ran `composer install`. Pushing the composer.lock file, will lock down the dependencies’ versions to be installed. This is recommended, especially for production apps. You should also check it into your repo.

I’ve installed the App dependencies locally
View the source for this page in GitHub