PMG Digital Made for Humans

Forget app_dev.php In Your Symfony Application

2 MINUTE READ | October 7, 2016

Forget app_dev.php In Your Symfony Application

Author's headshot

Christopher Davis

Christopher Davis has written this article. More details coming soon.

I’m not a big fan of the typical app.php and app_dev.php setup in the Symfony Standard Edition. While it’s not a big deal if the app_dev.php file gets deployed, it shouldn’t be done anyway. It’s too risky and complicates the deploy process a bit.

The alternative: environment variables that default to production mode.

Rather than doing new AppKernel('prod', false) in a single index.php entrypoint, we’ll create a named constructor that fetches a few environment variables. The key here is to default to production mode so a botched deployment doesn’t ever expose debug information.


<?phpuse Symfony\Component\HttpKernel\Kernel;class AppKernel extends Kernel{    public static function fromEnvironment()    {        $env = getenv('APP_ENVIRONMENT') ?: 'prod';        $debug = filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOLEAN);        return new self($env, $debug);    }     // ...}

Now use that named constructor as your main entrypoint — app.php in Symfony standard, though I like to just use index.php. And remove the app_dev.php file.


<?phpuse Symfony\Component\HttpFoundation\Request;// require autoloader or bootstraprequire __DIR__ . '/../app/autoload.php';// from the environment!$app = AppKernel::fromEnvironment();// just like normal$request = Request::createFromGlobals();$response = $app->handle($request);$response->send();$app->terminate($request, $response);
To me, this method is easier to understand and removes a step from the deployment. Two fairly good things.

Image credit Flickr

Interested in working with us? See our open engineering roles here.

Stay in touch

Bringing news to you

Subscribe to our newsletter

By clicking and subscribing, you agree to our Terms of Service and Privacy Policy

Related Content

thumbnail image

AlliPMG CultureCampaigns & Client WorkCompany NewsDigital MarketingData & Technology

PMG Innovation Challenge Inspires New Alli Technology Solutions

4 MINUTES READ | November 2, 2021

thumbnail image

Applying Function Options to Domain Entities in Go

11 MINUTES READ | October 21, 2019

thumbnail image

My Experience Teaching Through Jupyter Notebooks

4 MINUTES READ | September 21, 2019

thumbnail image

Working with an Automation Mindset

5 MINUTES READ | August 22, 2019

thumbnail image

3 Tips for Showing Value in the Tech You Build

5 MINUTES READ | April 24, 2019

thumbnail image

Testing React

13 MINUTES READ | March 12, 2019

thumbnail image

A Beginner’s Experience with Terraform

4 MINUTES READ | December 20, 2018