How to deploy your Laravel app to Digital Ocean using Laravel Forge
I've outlined every step including screenshots for setting up a Laravel website using Laravel Forge and Digital Ocean.
Laravel Forge makes it trivial to get your Laravel app up and running on Digital Ocean (and other providers).
However, there are a bunch of steps!
I've outlined all of the steps required to go from having your Laravel app in a GitHub repo to having it hosted on a server with a MySQL database, SSL certificate installed and a Queue Worker running.
If you have questions about any of the steps or get stuck, be sure to check out the free Laracasts course on Laravel Forge.
Select Digital Ocean from the list of supported servers on Laravel Forge.
I made the following changes to my server but feel free to configure your server to meet your needs. Once your done configuring your server, click [Create Server].
- Server Size
- Enable Digital Ocean Weekly Backups
While your server is being provisioned, save the provided Sudo Password and Database Password to somewhere safe and secure like in 1Password or LastPass.
In the Active Servers section, you will see a list of your servers. Once your new server's status is set to Active, click the server name.
Click on the "default" domain in the Active Sites section.
Select Git Repository to connect this site with an existing repository on Github.
Add the name of your repository and configure any other settings you need. Then click the [Install Repository] button.
After installing the repository, you'll need to wait a few moments.
Click on the [Deploy Now] button in the Deployment box to deploy your code to Digital Ocean.
Click the [Enable Quick Deploy] button to enable push-to-master deploys.
Log into your Domain Registrar (I'm using Hover in this example) and point your nameservers to Digital Ocean.
Go to Digital Ocean > Networking > Domains
Add your domain then click the [Add Domain] button.
Add a new
A record with the following details and click the [Create Record] button.
- WILL DIRECT TO your droplet's name
Add a CNAME record and click the [Create Record] button.
- IS AN ALIAS OF
If your Laravel app requires a database, go back to the list of servers on Laravel Forge.
Click the new server you created and then click the Database menu item in the left sidebar and enter your database details. Once done, click the [Add Database] button.
To connect your SSH key to Laravel Forge click the SSH Keys menu item in the left sidebar and add the name of your SSH key and the Public Key then click the [Add Key] button.
TIP You can quickly get your Public Key within Terminal by entering
cat ~/.ssh/id_rsa.pub | pbcopy command which copies your Public Key to your Mac's clipboard ready to be pasted into the Public Key textarea.
To test the connection to your database open Sequel Pro (which does NOT currently work with MySQL 8) or TablePlus (which does work with MySQL 8) and add a new SSH connection with the following details:
- Name: Any name
- MySQL Host: 127.0.0.1
- DB User: (Name of
Usercreated when you created the database above)
- DB Password: (
Passwordcreated when you created the database above)
- Database: (Name of
- SSH Host: IP address of site (listed on Digital Ocean)
- SSH User: forge
- SSH Key: ~/.ssh/id_rsa
Now you need to edit your
.env values. To do this go to the Sites drop down menu in Laravel Forge and select your new Site.
In the left sidebar, click the Environment menu item then click the [Edit Environment] button
.env with necessary production values. Values you might update in the
.env file are:
Currently we haven't associated a domain. Let's fix that. For your Site, click the Meta link in the left sidebar. In the Domain section, replace
default your website's domain name in the Site Domain field then click the [Update Domain] button.
To configure your site to use SSL (which is recommended), click the SSL link in the left sidebar then select LetsEncrypt.
You will see the Domains you are acquiring an SSL certificate for. Click the [Obtain Certificate] button to complete the process.
If you have queued jobs and need a queue worker to trigger those jobs click the Queue link in the left sidebar. Fill in the details (as per your requirements). For my site, I'm just going to use a
database connection which is the only change I make to the Worker. Click the [Start Worker] button after you have configured all of the fields.
Now your site is live!
Congrats, enjoy and build something awesome.