PHPackages                             neam/php-app-config - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. neam/php-app-config

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

neam/php-app-config
===================

A PHP framework-agnostic approach to make the current \[config\](http://12factor.net/config) available to PHP applications and shell-scripts.

2.0.0(9y ago)680.7k↓30%6BSD-3-ClausePHPPHP &gt;=5.3.0

Since Apr 7Pushed 9y ago1 watchersCompare

[ Source](https://github.com/neam/php-app-config)[ Packagist](https://packagist.org/packages/neam/php-app-config)[ Docs](https://github.com/neam/php-app-config)[ RSS](/packages/neam-php-app-config/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (6)

PHP App Config
==============

[](#php-app-config)

A PHP framework-agnostic approach to make the current [config](http://12factor.net/config) available to PHP applications and shell-scripts.

For use by the application wherever it may be fit, for instance in the application's / PHP framework's configuration files.

Installation
------------

[](#installation)

- Install via composer:

```
composer require neam/php-app-config:dev-develop

```

- Copy the `example/config` folder into the root directory of your project.

```
cp -r vendor/neam/php-app-config/example/config config

```

- Make sure that all app entry scripts include the file called `include.php` right after including the composer autoloader (adjust the path as necessary in each entry script):

```
// Make app config available as PHP constants
require(dirname(__FILE__) . '/../vendor/neam/php-app-config/include.php');

```

- Replace config vars in your app with the corresponding PHP constants. Example of usage within Yii configuration:

Before:

```
'db' => array(
    'connectionString' => 'mysql:host=localhost;dbname=db',
    'emulatePrepare' => true,
    'username' => 'root',
    'password' => 'supersecret',
    'charset' => 'utf8',
    'enableParamLogging' => true, // Log SQL parameters
    //'schemaCachingDuration'=>3600*24,
),

```

After:

```
'db' => array(
    'connectionString' => 'mysql:host=' . DATABASE_HOST . (defined('DATABASE_PORT') && DATABASE_PORT != '' ? ';port=' . DATABASE_PORT : '') . ';dbname=' . DATABASE_NAME,
    'emulatePrepare' => true,
    'username' => DATABASE_USER,
    'password' => DATABASE_PASSWORD,
    'charset' => 'utf8',
    'enableParamLogging' => true, // Log SQL parameters
    //'schemaCachingDuration'=>3600*24,
),

```

How it works
------------

[](#how-it-works)

Configuration directives are looked for in the following places:

- $\_ENV (which can be populated during a bootstrapping phase as in the `local` example config file)
- php-fpm environment variables (set in php-fpm configuration files and available through getenv())
- apache sub-process environment variables (set in Apache 2.x vhost config and available through apache\_getenv())
- php-cgi params (set in nginx location blocks using fastcgi\_param and available through $\_SERVER)

The `include.php` file will load a file (defaulting to `project-root/config/local/include.php`) that defines what application-specific configuration directives to expect.

To change the expected config include file, set the `CONFIG_INCLUDE` environment variable to the path to the include relative to the project root. For instance, in order to use `project-root/config/remote/include.php`, set the CONFIG\_INCLUDE environment variable to `config/remote/include.php`.

Within the config include file, you define which directives to expect using the Config::expect() method:

```
Config::expect("DATABASE_URL", $default = null, $required = true);

```

The `include.php` file will then call `Config::defineConstants()` which will define expected configuration directives as constants.

Using the example config includes
---------------------------------

[](#using-the-example-config-includes)

The included example configuration includes sample config profiles used to deploy to Heroku-style services and/or running the code locally.

### Remote deployment (Docker Cloud / Platform as a Service)

[](#remote-deployment-docker-cloud--platform-as-a-service)

- Deploy the app to Docker Cloud or a PaaS
- Set the CONFIG\_INCLUDE config var to `config/remote/include.php`

#### Example - Heroku

[](#example---heroku)

```
$ heroku config:set CONFIG_INCLUDE=config/remote/include.php

```

- Set the expected config vars (DATABASE\_URL, GA\_TRACKING\_ID etc) to their respective values

Your app should now run on Heroku using the expected config vars as PHP constants.

### Local

[](#local)

The example local config include will first expect the `remote`, then load the `overrides.php` file, followed by a non-versioned file called `secrets.php`. To use the local configuration:

- Create ang gitignore your secret local configuration file

```
cp .env.dist .env
echo ".env" >> .gitignore

```

- Add general defaults/overrides that all developers use locally in the `overrides.php` file
- Add secret defaults/overrides that should not be versioned to the `secrets.php` file

Your app should now run locally using the expected config vars as PHP constants.

Useful commands
---------------

[](#useful-commands)

To show your current config, you can run the following in a shell:

```
php -d variables_order="EGPCS" vendor/neam/php-app-config/export.php

```

To use the config in a shell-script:

```
source vendor/neam/php-app-config/shell-export.sh
# now the config is available to the shell-script

```

To export the current configuration to a file which can be sourced by a shell script:

```
php -d variables_order="EGPCS" vendor/neam/php-app-config/export.php > .exported.php-app-config.inc.sh

```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~175 days

Total

2

Last Release

3519d ago

Major Versions

1.0.0 → 2.0.02016-09-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/d71e1dd8ef0c10991227f77fbc40e68504121455a0ec42e3ae7d05630f47605c?d=identicon)[motin](/maintainers/motin)

---

Top Contributors

[![motin](https://avatars.githubusercontent.com/u/793037?v=4)](https://github.com/motin "motin (33 commits)")

---

Tags

phpconfig12factor

### Embed Badge

![Health badge](/badges/neam-php-app-config/health.svg)

```
[![Health](https://phpackages.com/badges/neam-php-app-config/health.svg)](https://phpackages.com/packages/neam-php-app-config)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
