Download the PHP package unleashedtech/dotenv-drupal without Composer

On this page you can find all versions of the php package unleashedtech/dotenv-drupal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dotenv-drupal

Environment-Based Drupal Settings

This package extends Symfony's symfony/dotenv component to allow streamlined Drupal config via Environment Variables. Please refer to the Symfony component's documentation about how .env files should be used. It is important to note that .env files are ignored if the APP_ENV var has already been set by the server. For performance purposes, production environments should ideally rely on pre-configured environment variables, rather than environment variable values loaded from .env files.

Installation

composer require unleashedtech/dotenv-drupal

Configuring Drupal

First, you'll need to configure Drupal to use this package.

Drupal Settings & Sites Files

Drupal is typically configured via settings.php files in various directories. To use this package with Drupal, some code will need to be added to the top of the relevant settings.php file(s):

Conditional Logic

If conditional logic is required for a given site, such logic is still supported. This package will auto-load various settings.{{environment}}.php, config.{{environment}}.php or databases.{{environment}}.php files, if they exist. For instance, if you need to set a database prefix for staging, you can create databases.staging.php:

Each included file only has the related variable in scope (e.g. config.dev.php only has $config in scope).

Multi-Site Drupal

You can use the default settings file to provide base configuration for a multi-site install:

If you'd like, you can manually set the database name for each site via the setDatabaseName method:

Using the Multi-Site Default Site

If you need to use the default site as part of your multi-site install, you can allow it by calling the DotEnv::setMultiSiteDefaultSiteAllowed method in default/settings.php:

Sites Files

This package also provides functionality to configure Drupal's $sites variable via sites.php. The $sites variable is built from data in the DOMAINS & SITES environment variables. You will need to add the following code to sites.php:

Installation Conclusion

That's it! Drupal will now attempt to load essential connection information from Environment Variables.

Configuring Drupal via ENV Variables

This package will provide many default setting & configuration values based on the detected environment. Some of these values can be populated by environment variables.

Environment variables can be set in .env files, or via modifying server configuration. For production environments, environment variables should ideally be defined via server configuration.

Multi-site installations often need config that differs from the default site. This package first checks for variables following the {{ app }}__{{ site }}__{{ var }} naming convention, before falling back to the {{ var }} naming convention.

You can provide site-specific information via namespaced environment variables.

DATABASE_URL

The default database connection can be configured via a DSN:

For example:

For multi-site installations, do not specify a database name nor credentials in the DATABASE_URL variable:

For an "earth" Drupal App with a "default" site & an "antarctica" site:

The default Drupal App Name in the default settings.php file, as shown below:

The database name for a site can be overridden via definition of a {{ app }}__{{ site }}__DATABASE_NAME environment variable:

FILE_PUBLIC_PATH

Allows you to override the default $settings['file_public_path'] value:

Drupal expects this path to be relative to DRUPAL_ROOT.

FILE_PRIVATE_PATH

Allows you to override the default $settings['file_private_path'] value:

FILE_TEMP_PATH

Allows you to override the default $settings['file_temp_path'] value:

CONFIG_SYNC_PATH

Allows you to override the default $settings['config_sync_path'] value:

DOMAINS

A CSV list of domains used by the given environment:

MAILGUN_URL

The information Drupal should use to authenticate with the Mailgun API.

The "user" in the DSN is the API key.

US URL Example
EU URL Example

PUBLIC

A string allowing the enabling/disabling of Shield module auth functionality.

If true, Shield will not be enabled.

If false, the username will be the App Name & the password will be the Site Name.

Note: Make sure the "Enable Shield" checkbox is checked in Drupal & that config is committed.

SITES

A CSV list of Drupal "sites" (e.g. "subdomains") used by the given environment:

SALT

A string used for "one-time login links, cancel links, form tokens, etc."

Best Practices Issue

Use drush eval "var_dump(Drupal\Component\Utility\Crypt::randomBytesBase64(55))" to generate one.

SOLR_URL

The default Solr connection can be configured via a DSN:

This package makes several assumptions, which can be overridden via the SOLR_URL DSN. The DSN in the example above is automatically expanded to:

In the expanded example above, the user is the name of the Solr core & the fragment is the Drupal machine name for the connection. Consider revising Solr core & Drupal Solr server machine names to default, so the shorter DSN can be used.

Streamlined environment-dependent configuration of one Solr core is supported at this time.

TRUSTED_HOST_PATTERNS

Optional. A CSV list of patterns specifying trusted hosts.

Start (^) & end ($) characters are added to every pattern, by default.

Fallback Functionality

If the TRUSTED_HOST_PATTERNS variable is not set, this package will populate Drupal's trusted_host_patterns array based on the values of DOMAINS & SITES variables.

Examples

If you have DOMAINS set to foo.example,bar.example, the Drupal trusted_host_patterns settings array would have the following values:

If you have DOMAINS set to foo.example & SITES set to bar,baz,qux, the Drupal trusted_host_patterns setting array would have the following values:

Terms

App Name

The machine name of the Drupal App (e.g. "default" or "earth").

Site Name

The site name for a Drupal App Site (e.g. "default" or "antarctica").

Configuration Conclusion

With these few Environment Variables, you will be able to configure Drupal in a streamlined fashion similar to the way Symfony is configured. Support for many more common Drupal features can be expected soon. Please consider creating a Pull Request with features you would like to this package to support.


All versions of dotenv-drupal with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
symfony/dotenv Version ^5.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package unleashedtech/dotenv-drupal contains the following files

Loading the files please wait ...