|
1 | | -PHP dotenv for codeigniter |
2 | | -========================== |
3 | | - |
4 | | -Loads environment variables from `.env` to `getenv()` automagically. |
5 | | - |
6 | | -This is a PHP version of the original [Ruby |
7 | | -dotenv](https://github.com/bkeepers/dotenv). |
8 | | - |
9 | | -Why .env? |
10 | | ---------- |
11 | | -**You should never store sensitive credentials in your code**. Storing |
12 | | -[configuration in the environment](http://www.12factor.net/config) is one of |
13 | | -the tenets of a [twelve-factor app](http://www.12factor.net/). Anything that is |
14 | | -likely to change between deployment environments – such as database credentials |
15 | | -or credentials for 3rd party services – should be extracted from the |
16 | | -code into environment variables. |
17 | | - |
18 | | -Basically, a `.env` file is an easy way to load custom configuration |
19 | | -variables that your application needs without having to modify .htaccess |
20 | | -files or Apache/nginx virtual hosts. This means you won't have to edit |
21 | | -any files outside the project, and all the environment variables are |
22 | | -always set no matter how you run your project - Apache, Nginx, CLI, and |
23 | | -even PHP 5.4's built-in webserver. It's WAY easier than all the other |
24 | | -ways you know of to set environment variables, and you're going to love |
25 | | -it. |
26 | | - |
27 | | -* NO editing virtual hosts in Apache or Nginx |
28 | | -* NO adding `php_value` flags to .htaccess files |
29 | | -* EASY portability and sharing of required ENV values |
30 | | -* COMPATIBLE with PHP's built-in web server and CLI runner |
| 1 | +# PHP dotenv for codeigniter |
| 2 | +> Autodetect environment type and load variables from `.env` to `getenv()` automagically. |
| 3 | +
|
| 4 | +This is a PHP version of the original [Ruby dotenv](https://github.com/bkeepers/dotenv). |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +## Manual Installation without Composer |
| 9 | +1. Copy folder **system** to your codeigniter projects. |
| 10 | +2. Add this code to your codeigniter index.php before codeigniter core loaded (before this text "* LOAD THE BOOTSTRAP FILE") : |
| 11 | + ```php |
| 12 | + /* |
| 13 | + * -------------------------------------------------------------------- |
| 14 | + * LOAD PHP DOT ENV FILE |
| 15 | + * -------------------------------------------------------------------- |
| 16 | + * |
| 17 | + * And away we go... |
| 18 | + * |
| 19 | + */ |
| 20 | + require_once BASEPATH . 'dotenv/autoloader.php'; |
| 21 | + |
| 22 | + $dotenv = new Dotenv\Dotenv(__DIR__); |
| 23 | + $dotenv->load(); |
| 24 | + ``` |
| 25 | + |
| 26 | +## Configuration |
| 27 | +1. Create **.env** according your environment by copy file **.env.example** for database configuration and the other configuration. |
| 28 | +Example : **.env.development**, **.env.testing**, **.env.production** |
| 29 | + |
| 30 | +2. Load configuration, in file **application/config/database.php** change to this configuration |
| 31 | +```php |
| 32 | + $db['default']['hostname'] = getenv('DB_HOST'); |
| 33 | + $db['default']['username'] = getenv('DB_USERNAME'); |
| 34 | + $db['default']['password'] = getenv('DB_PASSWORD'); |
| 35 | + $db['default']['database'] = getenv('DB_DATABASE'); |
| 36 | + $db['default']['dbdriver'] = getenv('DB_CONNECTION'); |
| 37 | +``` |
| 38 | +3. Add ".env" to your .gitignore file |
| 39 | +4. It will be running, thank you |
31 | 40 |
|
| 41 | +## Release History |
32 | 42 |
|
33 | | -Manual Installation without Composer |
34 | | ------------------------------------- |
35 | | -- copy folder "system" to your codeigniter projects |
| 43 | +* 0.1.1 |
| 44 | + * CHANGE: Autodetect environment & Update Readme |
| 45 | +* 0.1.0 |
| 46 | + * Initial version |
36 | 47 |
|
37 | | -- add this code to your codeigniter index.php before codeigniter core loaded |
38 | | -(before this text "* LOAD THE BOOTSTRAP FILE") |
39 | | -```php |
40 | | -/* |
41 | | - * -------------------------------------------------------------------- |
42 | | - * LOAD PHP DOT ENV FILE |
43 | | - * -------------------------------------------------------------------- |
44 | | - * |
45 | | - * And away we go... |
46 | | - * |
47 | | - */ |
48 | | -require_once BASEPATH . 'dotenv/autoloader.php'; |
| 48 | +## Meta |
49 | 49 |
|
50 | | -$dotenv = new Dotenv\Dotenv(__DIR__); |
51 | | -$dotenv->load(); |
52 | | -``` |
| 50 | +Agung Jati Kusumo – [@its_agungjk](https://twitter.com/its_agungjk) – agungjk.social@gmail.com |
53 | 51 |
|
54 | | -- in file "application/config/database.php" change to this configuration |
55 | | -```php |
56 | | -$db['default']['hostname'] = getenv('DB_HOST'); |
57 | | -$db['default']['username'] = getenv('DB_USERNAME'); |
58 | | -$db['default']['password'] = getenv('DB_PASSWORD'); |
59 | | -$db['default']['database'] = getenv('DB_DATABASE'); |
60 | | -$db['default']['dbdriver'] = getenv('DB_CONNECTION'); |
61 | | -``` |
| 52 | +Distributed under the MIT license. See ``LICENSE`` for more information. |
62 | 53 |
|
63 | | -- create ".env" by copy file ".env.example" for database configuration and the other configuration |
| 54 | +[https://github.com/agungjk/phpdotenv-for-codeigniter](https://github.com/agungjk/phpdotenv-for-codeigniter) |
64 | 55 |
|
65 | | -- add ".env" to your .gitignore file |
| 56 | +## Contributing |
66 | 57 |
|
67 | | -- and it will be running, thank you |
| 58 | +1. Fork it (<https://github.com/agungjk/phpdotenv-for-codeigniter/fork>) |
| 59 | +2. Create your feature branch (`git checkout -b feature/fooBar`) |
| 60 | +3. Commit your changes (`git commit -am 'Add some fooBar'`) |
| 61 | +4. Push to the branch (`git push origin feature/fooBar`) |
| 62 | +5. Create a new Pull Request |
0 commit comments