Using envvault with PHP
Note: Please ensure that you have completed the previous steps
Prerequisites
- PHP installed on your system
- Composer installed
- envvault CLI tool installed
- An existing PHP project
Usage
Running Your Application
To run your PHP application with environment variables from envvault:
$ envvault run --env=dev php -S localhost:8000
Caching Environment Variables
For better performance, you can cache your environment variables:
$ envvault run --env=dev -c -- php -S localhost:8000
Example Implementation
Here is how to set up a basic PHP application with envvault:
<?php
// index.php
require_once __DIR__ . '/vendor/autoload.php';
// Your environment variables are automatically loaded
$port = getenv('PORT') ?: '8000';
$dbUrl = getenv('DB_URL');
$app = new SlimApp();
$app->get('/', function ($request, $response) {
return $response->write('Hello from envvault!');
});
$app->run();
// .env
PORT=8000
DB_URL=mysql://user:pass@localhost/dbname