PHP Classes

EnvKey PHP: Load environment variables from the EnvKey service

Recommend this page to a friend!
  Info   View files View files (38)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2023-06-27 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 45 All time: 10,610 This week: 128Up
Version License PHP version Categories
envkey-php 1.0Custom (specified...5PHP 5, Web services, Language
Description 

Author

This package can load environment variables from the EnvKey service.

It loads a PHP extension that can access the EnvKey Web service.

This extension can load and save environment variables that are stored in an encrypted way in the EnvKey servers.

Innovation Award
PHP Programming Innovation award nominee
June 2023
Number 2
Many PHP applications use environment variables to share configuration values between different parts of the code, such as database configuration values.

Often these configuration values are sensitive information that should be kept private to protect that information.

This package uses an extension that loads and saves environment variables and the respective values in a remote service named EnvKey in an encrypted way.

This way, the application can share environment variable values for an application that can use a hosting environment distributed between multiple machines.

It uses encryption to avoid sharing sensitive information with the EnvKey service.

Manuel Lemos
Picture of EnvKey
Name: EnvKey <contact>
Classes: 1 package by
Country: United States United States
Innovation award
Innovation award
Nominee: 1x

Details

envkey-php

Integrate EnvKey with your PHP projects to keep API keys, credentials, and other configuration securely and automatically in sync for developers and servers.

envkey-php integration example

This repo is mirrored in two locations:

Installation

$ composer require envkey/envkey-php

Usage

If you haven't already, download and install EnvKey from our website, then create a new org. Next, follow the ~1 minute integration quickstart to init an app with a .envkey file (for connecting development) or generate a server ENVKEY (for connecting a server).

At the entry point of your application, be sure you're including the composer autoloader.

require_once 'vendor/autoload.php'; // Include the Composer autoloader

Now all your EnvKey variables will be available with getenv('VARIABLE_NAME').

$stripe = new \Stripe\StripeClient(getenv('STRIPE_SECRET_KEY'));

Errors

The package will throw an error if an ENVKEY is missing or invalid.

Overriding Vars

This package will not overwrite existing environment variables or additional variables set in the .env file you loaded your ENVKEY from. This can be convenient for customizing environments that otherwise share the same configuration. You can also use branches or local overrides for this purpose.

PHP Request Model / Latency

Unlike other EnvKey language libraries that expect a long-running server process, this library is designed for PHP's short-lived per-request processes. Instead of loading config from an EnvKey host on every request, which would add 100-500ms of latency (depending on location and connection speed), this library caches your encrypted config in RAM in a background process and keeps it up to date. After the first load of EnvKey on a server, subsequent requests will load config from this cache, with effectively zero latency (less than 1 millisecond).

Working Offline

As mentioned in the previous section, this package caches your encrypted config in RAM. Your config will still be available (though possibly not up-to-date) if you lose your internet connection. When the connection is reestablished, the latest config will be loaded immediately.

envkey-source

Using a language-specific library like this one is the easiest and fastest method of integrating with EnvKey. That said, the envkey-source executable, which this library wraps, provides additional options and functionality when used directly from the command line. If you need additional flexibility and it works for your use case, consider using envkey-source directly.

x509 error / ca-certificates

On a stripped down OS like Alpine Linux, you may get an x509: certificate signed by unknown authority error when attempting to load your config. You can fix it by ensuring that the ca-certificates dependency is installed. On Alpine you'll want to run:

apk add --no-cache ca-certificates

Further Reading

For more on EnvKey in general:

Read the docs.

Read the integration quickstart.

Read the security and cryptography overview.

Need help? Have questions, feedback, or ideas?

Post an issue, start a discussion, or email us: support@envkey.com.

  Files folder image Files  
File Role Description
Files folder imageexample (2 files, 1 directory)
Files folder imageext (8 directories)
Files folder imagesrc (4 files)
Files folder imagetests (1 file)
Accessible without login Plain text file 06e9ac4b9e0f4f24.version.shasum Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Image file envkey-php.gif Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file sdkphp-version.txt Doc. Documentation

  Files folder image Files  /  example  
File Role Description
Files folder imagesrc (1 file)
  Accessible without login Plain text file composer.json Data Auxiliary data
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files  /  example  /  src  
File Role Description
  Accessible without login Plain text file index.php Aux. Auxiliary script

  Files folder image Files  /  ext  /  envkey-source_2.4.0_darwin_amd64  
File Role Description
  Accessible without login Plain text file envkeysource-version.txt Doc. Documentation
  Accessible without login Plain text file LICENSE Lic. License text
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  ext  /  envkey-source_2.4.0_darwin_arm64  
File Role Description
  Accessible without login Plain text file envkeysource-version.txt Doc. Documentation
  Accessible without login Plain text file LICENSE Lic. License text
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  ext  /  envkey-source_2.4.0_freebsd_amd64  
File Role Description
  Accessible without login Plain text file envkeysource-version.txt Doc. Documentation
  Accessible without login Plain text file LICENSE Lic. License text
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  ext  /  envkey-source_2.4.0_freebsd_arm64  
File Role Description
  Accessible without login Plain text file envkeysource-version.txt Doc. Documentation
  Accessible without login Plain text file LICENSE Lic. License text
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  ext  /  envkey-source_2.4.0_linux_amd64  
File Role Description
  Accessible without login Plain text file envkeysource-version.txt Doc. Documentation
  Accessible without login Plain text file LICENSE Lic. License text
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  ext  /  envkey-source_2.4.0_linux_arm64  
File Role Description
  Accessible without login Plain text file envkeysource-version.txt Doc. Documentation
  Accessible without login Plain text file LICENSE Lic. License text
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  ext  /  envkey-source_2.4.0_windows_amd64  
File Role Description
  Accessible without login Plain text file envkeysource-version.txt Doc. Documentation
  Accessible without login Plain text file LICENSE Lic. License text
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  ext  /  envkey-source_2.4.0_windows_arm64  
File Role Description
  Accessible without login Plain text file envkeysource-version.txt Doc. Documentation
  Accessible without login Plain text file LICENSE Lic. License text
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Accessible without login Plain text file auto.php Aux. Auxiliary script
  Accessible without login Plain text file constants.php Aux. Auxiliary script
  Plain text file Fetcher.php Class Class source
  Plain text file Loader.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file EnvkeyTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:45
This week:0
All time:10,610
This week:128Up