Categories
Laravel Samuel

Setting Up Laravel Forge Staging & Live Machines With Auto Deploy

We are going to break this into three separate sections. Section #1 will be setting up a stand alone Database machine. Section #2 will be setting up a staging and live environment for Laravel sites. Section #3 will be setting up a staging and live environment for WordPress sites.

Section: 1

  • We will be installing a MySQL database server. The documentation on that can be found here: https://docs.digitalocean.com/products/databases/mysql/
  • When creating the database we are going to select the following options from the Forge Screen
    • Type: Database
    • Region: Default
    • Server Size: 4GB Ram, 2 CPU Core, 80 GB SSD
      • This option cost $24/month
    • VPC: we will add it to our company VPC network, all of the other machines will also be added to this network
    • Enable weekly backups: yes

Once the server has been spun up we will save all of the login information that gets emailed to us in our password manager, make a connection to the machine using TablePlus, then delete the email with the passwords.

Making A Connection to the machine using TablePlus:

  • The first thing we will do is go to the SSH screen in forge for the database machine and add our public SSH key. To copy our SSH key from the command line use:
pbcopy < ~/.ssh/id_rsa.pub
  • Once our SSH key has been added to the machine, we can open up TablePlus and create our connection. To do this we will copy the Database Connection URL from the database tab on forge -> open TablePlus and select “create new connection” then select “import from URL”. Note, there is a great video on setup and connecting here: https://www.youtube.com/watch?v=jY5FhyiEdig

Allowing App servers to connect to the DB:

This step can actually only be completed once the other app machines have been created in steps 2 and 3 below, but once you have those created you need to come back to this machine and click into the server -> click network -> then select the option to allow the app machines to connect to the stand alone DB machine.

Section #2:

Laravel staging and live environments. We will create a two separate servers for staging and live. Both of these servers will be “web servers” from the server type drop down menu. We will check the option at the bottom of the page to add servers SSH key to source control providers. Both servers will be added to our company VPC.

Staging: 2GB Ram, 2CPU Core, 60GB SSD – cost $18/month

Live: 4GB Ram, 2 CPU, 80GB SSD – cost 24/month

*Once Both of these Machines are created we need to:

  • Install all our needed versions of PHP
  • Add our SSH key and test our SFTP connections
  • Create a new site with isolated user
    • Note: you must add an ssh key for each isolated user
  • Connect our project repo.
    • Note: we will need to add the servers SSH key and deploy key to the repo.
  • Once the repo is connected we will need to edit the .env file to point to our database machine + set the app_name, app_env, app_debug & app_url
  • we then need to activate our SSL from the SSL tab select lets encrypt
    • Note: we must point the site to the server before obtaining the SSL