-
Notifications
You must be signed in to change notification settings - Fork 33
Ngrok
Ngrok is a useful tool for making your local Totara site accessible publicly on the web. This is very useful when testing intergrations with Totara, such as the mobile app, or external services such as Microsoft Teams, LinkedIn Learning, or even if you simply want to make your site available for someone else to look at.
You will first need to sign up for an account, and then install and authenticate ngrok on your machine. You will also need to make sure that the ngrok
command can be run normally - this may require adding your ngrok installation directory to your $PATH
variable.
You will then need to add some magic to your config.php
so you are able to simultaneously use ngrok as well as accessing the instance locally.
$is_multi_site = __DIR__ !== '/var/www/totara/src';
$site_name = $is_multi_site ? basename(__DIR__) : 'totara';
$has_server_dir = file_exists(__DIR__ . '/server/config.php');
$is_multi_site = __DIR__ !== '/var/www/totara/src';
$site_name = $is_multi_site ? basename(__DIR__) : 'totara';
$has_server_dir = file_exists(__DIR__ . '/server/config.php');
// This detects and sets the wwwroot dynamically so you don't have to manually change it
if (!empty($_SERVER['HTTP_X_ORIGINAL_HOST']) && strpos($_SERVER['HTTP_X_ORIGINAL_HOST'], 'ngrok.io') !== false) {
// using ngrok
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_ORIGINAL_HOST'];
$CFG->wwwroot = 'https://' . $_SERVER['HTTP_HOST'];
} else if (!empty($_SERVER['HTTP_HOST']) && !empty($_SERVER['REQUEST_SCHEME'])) {
// accessing it locally via the web
$hostname = $_SERVER['HTTP_HOST'];
$hostname_parts = explode('.', $hostname);
$CFG->wwwroot = $_SERVER['REQUEST_SCHEME'] . '://';
if (end($hostname_parts) === 'behat') {
// redirect if using the behat URL
$hostname = str_replace('.behat', '', $hostname);
}
$CFG->wwwroot .= $hostname;
if ($is_multi_site && strpos($hostname, $site_name) === false) {
$CFG->wwwroot .= '/' . $site_name;
if ($has_server_dir) {
$CFG->wwwroot .= '/server';
}
}
} else {
// accessing it via CLI
$CFG->wwwroot = 'http://totara73';
if ($is_multi_site) {
$CFG->wwwroot .= '/' . $site_name;
}
if ($has_server_dir) {
$CFG->wwwroot .= '/server';
}
}
Once ngrok is set up, you can use the tngrok
command to use it with Totara.
If you have multiple sites set up, you will need to add entries into your /etc/hosts
file, for each Totara host such as totara73
that you wish to use, you will need to add one with your desired site as the subdomain, like yoursite.totara73
.
Copyright (c) 2023 Totara Learning Solutions Limited
- Node.js and Grunt
- PHPUnit
- Behat
- Cron
- Machine Learning
- Mailcatcher (for viewing emails)
- Shell Customisations
- Ngrok (for making your site publicly accessible)
-
PHPStorm Integration
- Performance improvements
- Automated testing integration
- XDebug setup
- Database tools