<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Joshua de Gier</title>
    <description>The latest articles on DEV Community by Joshua de Gier (@pendonl).</description>
    <link>https://dev.to/pendonl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F417080%2F7cdb2afa-ed06-4fd3-b207-3a99452f1611.jpg</url>
      <title>DEV Community: Joshua de Gier</title>
      <link>https://dev.to/pendonl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pendonl"/>
    <language>en</language>
    <item>
      <title>Installing Expose on a Laravel Forge server with a custom domain and wildcard SSL</title>
      <dc:creator>Joshua de Gier</dc:creator>
      <pubDate>Fri, 26 Jun 2020 00:07:41 +0000</pubDate>
      <link>https://dev.to/pendonl/installing-expose-on-a-laravel-forge-server-with-a-custom-domain-and-wildcard-ssl-3e72</link>
      <guid>https://dev.to/pendonl/installing-expose-on-a-laravel-forge-server-with-a-custom-domain-and-wildcard-ssl-3e72</guid>
      <description>&lt;p&gt;A little over a week ago, Marcel Pociot launched his latest product called Expose. Expose is a beautiful, open source, tunnel application that allows you to share your local websites with others via the internet.&lt;/p&gt;

&lt;p&gt;As I’ve been a paying customer for ngrok without using it too much, this was a trigger for me to take a dive into setting up Expose on a custom domain. The setup was pretty easy, besides a few things I had to search for. So hopefully it saves a few of you the trouble of finding out yourself ;-)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note&lt;/strong&gt;: I’ve used sharedwithexpose.com as an example domain in the screenshots. Might be knocking on an open door here, but don’t forget to replace this with your own custom domain!&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparing your domain
&lt;/h2&gt;

&lt;p&gt;First things first: we need to setup the domain you want to use. In this guide I’ll assume you want your Expose installation to run over https. In Laravel Forge you are able to add a wildcard Let’s Encrypt certificate using one of these DNS providers: Cloudfare, DigitalOcean, DNSimple, Linode and OVH.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SMIVADOf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0enfmt02lba4a8e5og35.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SMIVADOf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0enfmt02lba4a8e5og35.png" alt="This is what your domain DNS configuration looks like in DigitalOcean. Don’t forget to add the nameservers to your domain and create both an @ and * record as illustrated above."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case I used DigitalOcean to manage the DNS for a domain I already bought. Instructions for DigitalOcean can be found at &lt;a href="https://www.digitalocean.com/docs/networking/dns/"&gt;https://www.digitalocean.com/docs/networking/dns/&lt;/a&gt;. Don’t forget to create both the @ and * A-records and direct them to your Droplets IP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the Forge server and site
&lt;/h2&gt;

&lt;p&gt;Second step: create a server in Forge using the provider of your choice. Be sure to at least choose PHP 7.3 since Expose does not run on lower versions. Of course, don’t forget to save your sudo password in a password manager!&lt;/p&gt;

&lt;p&gt;Let’s proceed to adding the domain to the server using the sites tab in Forge. The single most important thing to do is to check “Allow Wildcard Sub-Domains”, since we need those for the sites shared via Expose.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vX95kE7O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ili8rdlp35zapx6lprog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vX95kE7O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ili8rdlp35zapx6lprog.png" alt="Adding the domain to Forge, don’t forget to tick the Allow Wildcard Sub-Domains checkbox."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After you’ve added your site, let’s continue by installing a Let’s Encrypt certificate. Under your site’s dashboard in Forge, choose SSL from the side menu and click Let’s Encrypt. Since we’re requesting a certificate for a wildcard domain we need to provide an API token for the provider of choice. After inserting the token click the green Obtain Certificate button and wait for a bit until installation is finished.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sbq16Hfc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f7lba8jxjkfpty0j2988.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sbq16Hfc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f7lba8jxjkfpty0j2988.png" alt="Obtaining a Wildcard SSL certificate via Forge using DigitalOcean as DNS provider"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Expose on the server
&lt;/h2&gt;

&lt;p&gt;Installing Expose on the server is a breeze, since Forge servers come pre-installed with the tools we are about to use! All we need to do is SSH into the server and globally install Expose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer global require beyondcode/expose
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After composer is done installing Expose, we’re ready to configure the Expose servers settings and creating a daemon script in Forge which monitors the process and restarts it whenever it has failed.&lt;/p&gt;

&lt;p&gt;First of all, we need to copy the expose config file to another directory for supervisor to be able to correctly load the settings. From within the /home/forge directory execute the following two commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php /home/forge/.config/composer/vendor/bin/expose publish
ln -s .expose/config.php .expose.php
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After that you can edit the .expose.php file to your liking. I’ve notice that the settings you enter in the Expose admin panel don’t persist whenever Supervisor had to restart my daemon script. I’m not sure if this is intended, but for now I would suggest to configure the .expose.php config file correctly instead of using the admin panel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up nginx and deamon script
&lt;/h2&gt;

&lt;p&gt;Next up are setting up nginx, this is perfectly described in the Expose docs under SSL support. The only thing you have to do is replace Forge’s default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;location / {
    try_files $uri $uri/ /index.php?$query_string;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_read_timeout 60;
    proxy_connect_timeout 60;
    proxy_redirect off;

    # Allow the use of websockets
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Last step is to create the daemon script which monitors the process for us. Go to your server in Forge, choose Daemons and create a record like the one below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4FXF0PXW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x2v060fs3qzxw8xdxufs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4FXF0PXW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x2v060fs3qzxw8xdxufs.png" alt="The Daemon script that monitors our Expose proces and restarts it whenever it fails or stops"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating users
&lt;/h2&gt;

&lt;p&gt;If everything went well, you should now be presented with Expose’s placeholder page at the root of your selected domain name. Also, Expose’s admin panel should be available at &lt;a href="https://expose.yourdomain.com"&gt;https://expose.yourdomain.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You most likely want to prevent random users from using your custom domain. Which means you should create users from the Expose admin panel. Also make sure you’ve set validate_auth_tokens to true in your .expose.php config file. After creating a user you are presented with their API token. This token needs to be set in your local installations config.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note&lt;/strong&gt;: Some users seem to be having issues when visiting the users page of the Expose admin panel. As far as I’ve seen this is due to an error reading the SQLite database. In the .expose.php configuration file you can manually set the location for database to /home/forge/.expose/expose.db. See this Github Issue: &lt;a href="https://github.com/beyondcode/expose/issues/18#issuecomment-646485519"&gt;https://github.com/beyondcode/expose/issues/18#issuecomment-646485519&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing and configuring the client
&lt;/h2&gt;

&lt;p&gt;The last steps are as easy as 1, 2, 3. We start off again by installing Expose globally using composer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer global require beyondcode/expose
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After that we publish the configuration file use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;expose publish
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next up is modifying the configuration file, using the editor of your choice to open the file and at least be sure you’ve correctly entered the host and auth_token in this file. Both are used to connect to the right host and of course to provide the correct credentials. More info about local client configuration can be found in the Expose docs.&lt;/p&gt;

&lt;h2&gt;
  
  
  That’s it!
&lt;/h2&gt;

&lt;p&gt;That should be it, you are now ready to share your first local website using your own custom Expose domain!&lt;/p&gt;

&lt;p&gt;If you find yourself having any trouble getting Expose installed or you think I’ve missed a step, don’t hesitate to write down a comment. If you think you’ve found a bug, please use Expose’s Git issues instead.&lt;/p&gt;

&lt;p&gt;Last but not least I want to thank Marcel Pociot for creating Expose and users filipac (&lt;a href="https://github.com/filipac"&gt;https://github.com/filipac&lt;/a&gt;) and ahmedash95 (&lt;a href="https://github.com/ahmedash95"&gt;https://github.com/ahmedash95&lt;/a&gt;) for their help in a few issues over at Github that lead me to a working installation!&lt;/p&gt;

&lt;h2&gt;
  
  
  Pendo
&lt;/h2&gt;

&lt;p&gt;My name is Joshua de Gier, I’m owner of Pendo — a digital agency located in Maastricht, the Netherlands. Our main focus is development of custom web applications and websites using Laravel. Feel free to reach out to us if you are looking for a development agency or temporary extra hands for your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pendo.nl"&gt;https://pendo.nl&lt;/a&gt;&lt;br&gt;
(+31) 043–302 00 01&lt;br&gt;
&lt;a href="mailto:info@pendo.nl"&gt;info@pendo.nl&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>expose</category>
      <category>forge</category>
      <category>ssl</category>
    </item>
  </channel>
</rss>
