Secure tunnel with ngrok + Valet + Bedrock

Testing payments on WordPress + WooCommerce sometimes requires your website to be publicly accessible. To make your local website publicly accessible, you can use ngrok.

1. Install and activate relative-url

composer require wpackagist-plugin/relative-url
wp plugin activate relative-url

2. Update your config/application.php file

Replace

Config::define('WP_HOME', env('WP_HOME'));
Config::define('WP_SITEURL', env('WP_SITEURL'));

With

if (isset($_SERVER['HTTP_X_FORWARDED_HOST']) && strpos($_SERVER['HTTP_X_FORWARDED_HOST'], '.ngrok') !== false) {
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
    Config::define('WP_HOME', 'https://' . $_SERVER['HTTP_X_FORWARDED_HOST']);
    Config::define('WP_SITEURL', 'https://' . $_SERVER['HTTP_X_FORWARDED_HOST'] . '/wp');
    $_SERVER['WP_HOME'] = Config::get('WP_HOME');
    $_SERVER['WP_SITEURL'] = Config::get('WP_SITEURL');
} else {
    Config::define('WP_HOME', env('WP_HOME'));
    Config::define('WP_SITEURL', env('WP_SITEURL'));
}

3. Add your subdomain to your site’s config file

Replace your-subdomain with … your sudomain.

Open ~/.config/valet/Nginx/{sitename} and add the subdomain (your-subdomain.eu.ngrok.io) to all lines starting with server_name.

4. Use valet share to share your site

Replace your-subdomain with … your sudomain.

valet share --subdomain=your-subdomain --region=eu --host-header=rewrite

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Overtuigd?

Neem dan contact op voor een offerte of vrijblijvend gesprek.
Stuur een e-mail naar [email protected] of maak gebruik van het contactformulier.