Supporting multiple TLDs in Laravel Valet

Simon Hamp
Sep 9 · 3 min read

Dnsmasq

address=/{tld}/127.0.0.1
listen-address=127.0.0.1
sudo brew services restart dnsmasq

Valet

{
...
"tlds": [
"tld1",
"tld2"
]
}
// server.php, line 70
$siteName = basename(
// Filter host to support wildcard dns feature
valet_support_wildcard_dns($_SERVER['HTTP_HOST']),
'.'.$tld
);
// change to:
foreach ($valetConfig['tlds'] as $tld) {
if (strpos($_SERVER['HTTP_HOST'], '.'.$tld) === false) {
continue;
}
$siteName = basename(
// Filter host to support wildcard dns feature
valet_support_wildcard_dns($_SERVER['HTTP_HOST']),
'.'.$tld
);
}
// cli/valet.php, line 145, secure command
$app->command('secure [domain]', function ($domain = null) {
$url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];
Site::secure($url); Nginx::restart(); info('The ['.$url.'] site has been secured with a fresh TLS certificate.');
})->descriptions('Secure the given domain with a trusted TLS certificate');
// change to:
$app->command('secure [domain]', function ($domain = null) {
$urls = [];
foreach (Configuration::read()['tlds'] as $tld) {
$url = ($domain ?: Site::host(getcwd())).'.'.$tld;
Site::secure($url); $urls[] = $url;
}
Nginx::restart(); $urls = implode(', ', $urls); info('The ['.$urls.'] site has been secured with a fresh TLS certificate.');
})->descriptions('Secure the given domain with a trusted TLS certificate');
// cli/valet.php, line 158, unsecure command
$app->command('unsecure [domain]', function ($domain = null) {
$url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];
Site::unsecure($url);Nginx::restart();info('The ['.$url.'] site will now serve traffic over HTTP.');
})->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');
// change to:
$app->command('secure [domain]', function ($domain = null) {
$urls = [];
foreach (Configuration::read()['tlds'] as $tld) {
$url = ($domain ?: Site::host(getcwd())).'.'.$tld;
Site::secure($url); $urls[] = $url;
}
Nginx::restart(); $urls = implode(', ', $urls); info('The ['.$urls.'] site will now serve traffic over HTTP.');
})->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');
valet restart

Simon Hamp

Written by

Nerd face. Senior dev @helloelvie. Running @BWBootstrap. Fun times with @noelicious86

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade