Skip to content

Instantly share code, notes, and snippets.

@Tam
Created June 27, 2017 12:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tam/6df24d524657475422feb910aa5cf1aa to your computer and use it in GitHub Desktop.
Save Tam/6df24d524657475422feb910aa5cf1aa to your computer and use it in GitHub Desktop.
How to get ngrok working with Craft CMS during development
<?php
// When using:
// `ngrok http -host-header=example.dev 80`
$isNgrok = array_key_exists("HTTP_X_ORIGINAL_HOST", $_SERVER) && strpos($_SERVER["HTTP_X_ORIGINAL_HOST"], "ngrok");
$host = 'http://' . $_SERVER[$isNgrok ? 'HTTP_X_ORIGINAL_HOST' : 'SERVER_NAME'] . '/';
return array(
// ...
'.dev' => [
'devMode' => true,
'siteUrl' => $host,
'environmentVariables' => array(
'baseUrl' => $host,
),
],
// ...
);
@Bcdo
Copy link

Bcdo commented Feb 23, 2019

I have tried this so many times, but it just does not do it for me. The links created by the entry does not consider the ngrok.io, and tries to connect to the dev server directly. And the admin login page does not work properly, it does not respond to me pressing the login button. I can however type in manually the entry url with the ngrok.io, and it shows me the pages I want.
I use homestead, not sure if that can have anything to do with it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment