Config.php not working on the server

TLDR: Make sure your config.php does not have any leading stray new lines

I came across an odd quirk that I’m posting here to hopefully save some ennui.

My site was working fine locally and on another remote test server, but when I went to publish it to my live server, the panel and the site were inaccessible with:

This page is currently offline due to an unexpected error. We are very sorry for the inconvenience and will fix it as soon as possible.

I had debug enabled in my config.php and the server logs did not show any errors.

After much debugging, the only things that seemed to work was deleting the contents config.php.

On closer inspection, I had a stray leading new line at the start of my config.php file:

     # <--- stray new line
<?php 
return [
    'debug'  => true,
    'smartypants' => true,
    'ds.omni-snippets.paths' => [
        __DIR__ . '/../snippets/home',        // Custom path for header snippets
        __DIR__ . '/../plugins/omni-snippets/snippets',
      ]
];

Changing it to this fixed my issue:

<?php 
return [
    'debug'  => true,
    'smartypants' => true,
    'ds.omni-snippets.paths' => [
        __DIR__ . '/../snippets/home',        // Custom path for header snippets
        __DIR__ . '/../plugins/omni-snippets/snippets',
      ]
];