Deploy a Laravel App on a Laravel Forge Server using a Digital Ocean Droplet and a domain name

Lotje Kinable
5 min readJan 3, 2021

--

The accounts you need:

  1. Create a Laravel Forge account, add a credit card and choose which plan you want. If you choose the first plan, only one server can be created. Checkout my article about deploying multiple Laravel Apps on one Laravel Forge Server.
  2. Use this link https://m.do.co/c/1c27867c48f0 to create an account on Digital Ocean and get $100 in credit over 60 days!

Add Digital Ocean as Server Provider on Laravel Forge:

DIGITAL OCEAN Part:

  1. Go to Digital Ocean
  2. Under the tab Account select API
  3. Under Tokens/Keys click “Generate New Token”
  4. Fill in the name of your Token eg. <Forge server App 01>
  5. Read and Write permissions are already select by default
  6. Go ahead and click “Generate Token”.
  7. Next you’ll see a token, copy it.
DigitalOcean Token for Laravel Forge Server

LARAVEL FORGE Part:

  1. Go to Account (Click on your name on the right)
  2. Go to Server Providers
  3. Choose “Digital Ocean” as provider
  4. Fill in the email address you used for your digital ocean account
  5. Paste the Token you copied.
  6. Click ADD CREDENTIAL
  7. Digital Ocean is now added to the Active providers.

Creating the Server on Laravel Forge:

  1. Click on “FORGE” in the header
  2. Click on the square with “Digital Ocean”
  3. Most of the credentials are already filled in:
  • check your email address
  • check the name you want to give your server, leave it if you like it, it should be unique
  • check your region
  • server size: I start with the first 1GB option, that’s the 5 dollar Droplet, you can always choose a bigger Droplet when you need to
  • choose your PHP version
  • Post Provision can be ‘none’
  • choose your mysql version
  • give a NAME to your Database
  • leave the Load Balancer unchecked
  • leave the Weekly Backups unchecked (unless you want to pay for it)

4. Click CREATE SERVER

5. Copy and save the Sudo Password and the Database Password to a secure place, with the name of your server ( especially if you are planning on adding multiple servers)

Laravel Forge Server Credentials

6. After a while (+-10 min) your server will be ready, and the status will change from ‘building’ to ‘provisioning’ to ‘connected’.

Once your server is connected:

  1. Click on the name of your server or click on Servers and select your server.
  2. Go to Sites > Active Sites and select the ‘default’ site
  3. Under Site Details, select Meta
  4. Fill in your domain name and click UPDATE
  5. You’ll see your domain name, between the name of your server and your ip address

On Digital Ocean, connect your (purchased) domain name to your newly created site/server (refresh Digital Ocean, if you were still logged in, then you can find your Droplet with the name of your newly created server under Projects > resources)

  1. Go to Networking > Domains
  2. Enter your purchased domain and select your Project (if you have multiple otherwise leave the default)
  3. Click Add Domain

Next, we’ll redirect our purchased domain to use the DigitalOcean nameservers , there are three.

Add the first nameserver:

  1. Under Domains, click on your newly added domain
  2. Under Create new record select the option “NS”
  3. Add an “@“ or your domain name in the HOSTNAME field
  4. In the WILL REDIRECT FIELD add “ns1.digitalocean.com.”
  5. Leave the TTL default

Add the second nameserver:

  1. Click on Create Record
  2. Under Create new record select the option “NS”
  3. Add an “@“ or your domain name in the HOSTNAME field
  4. In the WILL REDIRECT FIELD add “ns2.digitalocean.com.”
  5. Leave the TTL default

Add the third nameserver:

  1. Click on Create Record
  2. Under Create new record select the option “NS”
  3. Add an “@“ or your domain name in the HOSTNAME field
  4. In the WILL REDIRECT FIELD add “ns3.digitalocean.com.”
  5. Leave the TTL default
  6. Click on Create Record

Next, we’ll add an A record to redirect our domain name to our server/site:

  1. Under Create new record select the option “A”
  2. Add an “@“ or your domain name in the HOSTNAME field
  3. In the WILL REDIRECT FIELD select your Server/Droplet from the list
  4. Leave the TTL default
  5. Click on Create Record

Then we’ll add a CNAME record to redirect www.yourdomain.com to our server/site:

  1. Under Create new record select the option “CNAME”
  2. Add “www” or <www.yourdomainname.com> in the HOSTNAME field
  3. In the IS AN ALIAS OF field enter an @ or <yourdomainname.com>
  4. Leave the TTL default
  5. Click on Create Record

Now head over to Laravel Forge, we are ready to add our Laravel App to our Site.

  1. Under Sites, select the name of your Site and head over to the Apps tab.
  2. Click on Git Repository ( Go to Account > Source Control > CONNECT TO GITHUB and follow the steps to connect your GitHub account to Laravel Forge)
  3. Install Repository
  4. Select Github
  5. Fill in your repository details
  6. Choose your default branch, which is “main” on Github since a few weeks.
  7. Choose to Install Composer Dependencies
  8. Click Install Repository
  9. Now wait until all is installed

Head over to ENVIRONMENT under Site Details.

Fill in the details about your Laravel app in the .env file.

  • database, database user and password (you can create a new database under Servers > Database)
  • email server
  • APP_URL -> http://yourdomainname.com
  • + all relevant .env settings for your app

Click SAVE and go to Deployments and click Deploy Now and once the status is Finished click on the green arrow on the right site (at the top) to open up your App.

Optional: Create an SSL certificate with Let’s Encrypt.

  1. Go to SSL under Site Details
  2. Click on the box with LetsEncrypt
  3. Fill in your domain
  4. Click OBTAIN CERTIFICATE

Sometimes it takes some after the site setup before you can create a certificate!

If the status is installed and active is active, go back to your website and refresh, you’ll now see the lock in your browser.

Thanks for reading, please leave a comment and happy coding!

Kind regards,

Lotje Kinable

--

--

Lotje Kinable

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