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).
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.
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:
Now we go to Digital Ocean then Projects , locate <ProjectName>, go to Resources > Domains.
Go to Domains, click on your <purchased domain name> and go to the section Create new record:
First, we’ll create an A-Record.
- Select the “A” at the top to create a new A-record (default).
- add your <mysubdomain.rootdomain.com> in the HOSTNAME field.
- select your Droplet in the WILL DIRECT TO field.
- Leave the TTL, unless you know what you are doing (I don’t).
- Click Create Record.
Now, we’ll create a CNAME-record.
- Select the “CNAME” option at the top to create a new CNAME-record.
- Enter <www.mysubdomain.rootdomain.com> with the www in the HOSTNAME field.
- Enter <mysubdomain.rootdomain.com> in the IS AN ALIAS OF field.
- Leave TTL
- 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! :-)