Digital Ocean Virtual Server Setup

Best way to setup a Digital Ocean Virtual Server for a Laravel Project

Step 1 – Create an account

After setting up your account, the first thing you’ll want to do is set up a SSH key. This will prevent you from having to enter your password every time you communicate with DigitalOcean from command line.

How to Add SSH Keys to Droplets

This part is a little confusing but you need to create a key on your computer and add that key to your digitalocean account.  To make your life easier, you will also want to add that key to your github account.

How to Generate SSH keys on your Computer

Via command line, move into the .ssh directory in your home directory.

Mac users:

(FYI: ~/ is a shortcut for your home directory on Mac)

Windows/Cmder users:

(FYI: %home% is a shortcut for your home directory on Windows)

If a .ssh directory does not exist, create it and then navigate into it:



Next, we’ll run a command to generate a new key pair, and we’ll use the default key name of id_rsa. If you’ve created SSH keys in the past, this key pair might already exist; to check, run the list command ls -la in your .ssh directory to see if the files id_rsa and exist. If they already exist then skip creating them.

If id_rsa keys do not exist, continue to generate a new key pair with this command:

When it asks you for a file name for the key, leave it blank so the default filename (id_rsa) is used. Example:

When it asks you to create a passphrase you can enter one or leave it blank.

If you were building a real-world application that contained sensitive data then it is recommend using a password on the SSH keys.  For development, it’s easier to leave the password blank because:

  • an SSH key is still super secure, even without a password and
  • it’s convenient to not have to enter a password each time you use the key.

Regardless of whether you enter a password or not, hit Enter to proceed, and then Enter again when it asks you to confirm your password.

How to Upload SSH Public Keys to your DigitalOcean Account

From the Account section in the navigation menu, select Security. In the SSH keys section, click Add SSH Key.

DigitalOcean add new key button

Next, copy your public key, which should end in .pub into your clipboard and paste the contents into the SSH key content field. In the second field, enter a name for the key that will help you identify the in the DigitalOcean interface. This is often the name of the machine you copied the public key from.

DigitalOcean new public key prompt

Click the Add SSH Key button when you are finished and the key will be displayed on the Security page. You can use a key’s More menu to edit the key information or delete it entirely:

DigitalOcean new public key prompt

Now when you create a Droplet, you can automatically embed this key by selecting it in the Add your SSH keyssection of the Droplet create page.

How to Upload SSH Public Keys to your Github Account



Step 2 – Create a Droplet

How to Create a Droplet from the DigitalOcean Control Panel

DigitalOcean calls their virtual servers Droplets; each Droplet that you spin up is a new virtual server for your personal use.

After you log into the DigitalOcean Control Panel with your email address and password for the first time, there are two ways to create a Droplet. You can either:

  • Click the large, blue Create Droplet button. This button is only visible when you do not have any Droplets.
  • Click the green Create button in the top right and choose Droplets.

Create Menu

Whichever link you use, you’ll be taken to the Create Droplet page. This page lets you specify configuration options for your Droplet, like how much memory it has and which features (like backups ) are enabled.

The base plan which costs $5/month works for a test instance.

Here are a couple options to save some money:

  1. DigitalOcean has a refer-a-friend program which you can read about here:
  2. Github offers a Student Developer Pack which includes a DigitalOcean discount; you can read more about that here:

When you create your droplet select LAMP 18.04



Scroll down and select the server size you need.  Here’s a very simple chart but it  depends on several variables including what is running on your site, how many concurrent users, and your required storage space.

  • 1 GB, 1 vCPU, 25 GB, 1 TB, $5/mo – For testing purposes.
  • 2 GB, 2 vCPUs, 60 GB, 3 TB, $15/mo – For a live site with 100 hits a day.
  • 4 GB, 2 vCPUs, 80 GB, 4 TB, $20/mo – For a live site with 1000 hits a day.
  • 8 GB, 4 vCPUs, 160 GB, 5 TB, $40/mo – For live site with 5,000 hits a day.


Step 3 – SSH to your new server droplet

From your local command line, SSH into your DigitalOcean droplet using the username root and the IP address:

When you first connect, you’ll see the following message indicating it’s a connection your computer does not recognize. Type yes and hit Enter to confirm the connection.

After you hit enter, if your SSH key is set up properly, you should be logged into your server. You should not be prompted for a password (the SSH key is your security credential for connecting, so no password is required).

Set up of your new server is complete, so lets take a look around and see what files you have to start with.

First, change into your document root which is located at /var/www/html/:

You should see two files:

  • index.html
  • info.php

If you access your site in the browser (via the IP address DigitalOcean gives you), you should see the default contents of index.html which looks like this: