detect environment type (production, development or staging) in Silex detect environment type (production, development or staging) in Silex symfony symfony

detect environment type (production, development or staging) in Silex


I don't have experience with Silex but I always use environment variables for this. Then in your application you can get the current environment with:

getenv('ENVIRONMENT')


Silex by itself doesn't have environments, only has a debug mode. In order to know if your application is in debug mode you have the $app['debug'] variable.

Having said that nothing prevents you to create your own environment variable in, let's say $app['env'] (yes very original...). So everywhere you need to know which environment are you running you can use the $app['env'] variable.

In order to initialize this variable and following the silex skeleton you can have (in the web folder, your DocumentRoot) an index.php, index_dev.php, index_stg.php where you set the $app['env'] accordingly before calling $app->run().

Or you can use the technique explained by @WimMostmans and use a real environment variable :-)