Hosting 2 (or more) Laravel apps on one single Laravel Forge Server, using only one DigitalOcean Droplet and with the use of subdomains (purchased domain name required).

Lotje Kinable
4 min readJan 1, 2021

--

Summary: I wanted to host my personal website on Laravel Forge and a project, that’s far from finished. I bought one domain name and one DigitalOcean Droplet. I struggled to find answer to why the “default” website worked and the new app I added to my server did not. Follow these steps to add 2 or more Laravel Apps to one Laravel Forge server (DigitalOcean droplet) and with one domain name (using subdomains).

Use the link below to get $100 for free over 60 days at Digital Ocean!

On Laravel Forge, to to Servers > Sites.

In the field “root domain” add your chosen subdomain and domain name like <mysubdomain.rootdomain.com>. I used the name of my project for my subdomain, because I want to add multiple versions before I will deploy my project(s) on a seperate server.

Form to create a New Site on Laravel Forge.
Laravel Forge, creating a New Site form

Decide if you want to create separate database, you can always add it later too or use the default database. Then click “ADD SITE”.

Under the section “Active Sites”, you’ll see your newly created Site:

The site we added through the form.
Laravel Forge, newly created site

Now we go to Digital Ocean then Projects , locate <ProjectName>, go to Resources > Domains.

Overview Project on Digital Ocean
Overview Project on Digital Ocean

Go to Domains, click on your <purchased domain name> and go to the section Create new record:

First, we’ll create an A-Record.

Overview Digital Ocean “Create new A-record” section
  1. Select the “A” at the top to create a new A-record (default).
  2. add your <mysubdomain.rootdomain.com> in the HOSTNAME field.
  3. select your Droplet in the WILL DIRECT TO field.
  4. Leave the TTL, unless you know what you are doing (I don’t).
  5. Click Create Record.

Now, we’ll create a CNAME-record.

Overview Digital Ocean “Create new CNAME-record” section
  1. Select the “CNAME” option at the top to create a new CNAME-record.
  2. Enter <www.mysubdomain.rootdomain.com> with the www in the HOSTNAME field.
  3. Enter <mysubdomain.rootdomain.com> in the IS AN ALIAS OF field.
  4. Leave TTL
  5. Click Create Record.

Now, we have 2 (or more) Sites that are linked to one Laravel Forge Server, using one Droplet. The next step is to add our (GitHub) project to our Site.

Go to Laravel Forge > Sites and select <mysubdomain.rootdomain.com>, your newly created Site (sometime a refresh is needed to see your new sites under the Sites tab).

This bit is exactly the same as adding the first (or default) site to Laravel Forge. Click on Git Repository and add your repo.

Next, go to “Environment” on the left side and wait until the .env file is loaded.

Change the value of APP_URL to https://<mysubdomain.rootdomain.com>

If you don’t change the above value, the NGINX server does not know to which site your URL needs to be redirected.

Don’t forget to change any additional values for your project, eg. Database credentials (default database or custom database), mail setup, etc…

Click “Save” and go to “Deployments” on the left hand side and click “DEPLOY NOW”.

You can use these steps to create some additional test sites. This is obviously not recommend for production, but you can easily use this to deploy your projects to test them before you decide to purchase an additional (bigger) Digital Ocean Droplet.

This is my first article, feedback is highly appreciated! Have fun coding Laravel apps and deploying them on Laravel Forge! :-)

Kind regards,

Lotje Kinable

--

--

Lotje Kinable
Lotje Kinable

Written by Lotje Kinable

👩🏼‍💻 @1993 she/her, genderfluid, Laravel developer, wife🏳️‍🌈, dog mom, non-professional 🎼 piano/guitar player, photographer and reader 😊

No responses yet