What's the difference between require and require-dev?

What's the difference between require and require-dev?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

What's the difference between require and require-dev?

When you initialize a new PHP project with Composer, the composer.json file immediately presents two distinct sections that often confuse developers: require and require-dev. While the Composer documentation describes require as packages needed to run an application, it defines require-dev more vaguely as "packages required for developing this package." This lack of specificity leaves many wondering exactly what constitutes "development" versus "production" in the context of dependency management.

The fundamental distinction lies in the lifecycle of the software. The require section is strictly for production dependencies. These are the libraries your application absolutely needs to function when deployed to a live server or served to an end-user. If you remove a package listed here, your application will fail to start or crash during runtime with a missing class error. Examples include frameworks like Laravel, database drivers like PDO wrappers, or utility libraries like Guzzle for HTTP requests.

Conversely, require-dev contains dependencies that are only necessary while you are building the software. These packages facilitate testing, debugging, documentation generation, and static analysis but provide zero value once the code is deployed. If you uninstall everything listed in require-dev, your production environment remains stable and functional. Common examples include PHPUnit for unit testing, Pest for testing frameworks, PHPStan or Rector for static analysis and refactoring, and tools like PHP_CodeSniffer for enforcing coding standards.

The practical implication of this separation is control over the final artifact size and security surface area. When you deploy a Laravel application, for instance, you want to ensure that no unused development libraries are included in the optimized cache or the production autoload map. Composer handles this by default when running composer install on a machine without the --dev flag, effectively ignoring the require-dev section. However, if you run composer install --no-scripts or simply intend to deploy using composer dump-autoload -o, you must be explicit about excluding dev dependencies to avoid bloating your deployment package with tools like monolog/monolog (if used only for development logging) or fakerphp/faker.

Consider a scenario where you are building a custom PHP library intended for public consumption. You might need phpunit/phpunit to write your test suite. If you accidentally place PHPUnit in the require section, any user who installs your package will be forced to download and run tests just to get a simple function working. This is inefficient and confusing. By placing it in require-dev, you signal to users that testing is part of your development workflow, not a runtime requirement for their application.

There are specific edge cases where this line blurs. Some packages provide both production and development features in a single installable unit. For example, a package might offer a CLI tool for end-users to manage configuration files, which technically runs on the user's server. In such cases, that tool should reside in require. If the same package includes a test suite or a code generator meant solely for your own development environment, those specific sub-dependencies triggered by its installation logic often belong in require-dev if they are optional flags within the main package's setup.

Understanding this dichotomy prevents common pitfalls like deploying a massive vendor directory that slows down your web server's static file serving or introducing security vulnerabilities from unused libraries. It also ensures that when you run composer update, you only pull in changes to production code, avoiding accidental upgrades to testing frameworks that might break your local test suite if you haven't synced your dev environment correctly.

For those managing large monolithic applications or microservices where consistency is key, maintaining a clean split between these two sections is essential for reproducible builds. If you are working within the Laravel ecosystem specifically, this distinction is reinforced by the framework's default configuration and the community's best practices regarding production deployments found at https://laravelcompany.com.

Our network