Use Laravel Forge to Automate Web-Server Creation on a Linode

Updated by Onwuka Gideon Written by Onwuka Gideon

Contribute on GitHub

Report an Issue | View File | Edit File

Laravel Forge Banner

What is Laravel Forge

Laravel Forge is a tool for deploying and configuring web applications. It was developed by the makers of the Laravel framework, but can be used to automate the deployment of any web application that uses a PHP server.

Creating a fully-functioning web server is normally a complicated and time-consuming process, involving the installation of multiple components such as Nginx, MySQL, and PHP. Laravel Forge automates all of the necessary installation and configuration, allowing you to get your website up and running quickly.

Once your server has been created, deploying updates becomes as simple and painless as pushing to your repository on Github. Also, you can easily manage the configuration of your website though a web interface. Finally, Forge automatically provides advanced security features, such as free SSL certificates (through Let’s Encrypt) and automatic firewall configuration.

Before You Begin

  1. Sign up for a Laravel Forge account if you do not have one.

  2. This guide will require a Linode account and an API key. For more detailed instructions, refer to this guide.

If you want to be able to quickly deploy from Github, Gitlab or Bitbucket, you will need to link these sites to your Forge account. From your Forge dashboard, select the Your Profile tab.

  1. Choose your preferred source control by clicking on the Source Control link on the Left.

    Linode API

  2. Click on the source control service you would like to connect to.

    Once you link to a source control service, you will be prompted to authorize Laravel Forge. You will then be redirected back to Forge’s website.

    Linode API

Adding Your Linode API Key to Forge

  1. Open your Laravel Forge Dashboard.

  2. Click on Service Providers.

  3. Select Linode and input your API key.

Linode API

Create a Server

  1. Click on Linode.

    Linode API

    You will then be provided with some options:

    Credentials: Any cloud providers that you have linked to your account.

    Name: A name for your server. You can choose any name you like.

    Server Size: The size of the server.

    Region: The data center where you want your server hosted. Choose a location close to where you expect the majority of users to be.

    PHP Version: The installed PHP version.

    Database Name: If your application needs a database, then you can name it here. By default it will be named forge.

  2. Once you have finished selecting options, click Create Server. A pop up will show you the sudo and database passwords that have been automatically generated for you. Be sure to copy these values and store them in a secure place.

    Linode API

    Forge will now perform the steps necessary to create and configure a Linode based on the settings you chose earlier.

  3. A green check in the Status column means the server is active. This will take a few seconds.

    Linode API

  4. Navigate to the public IP address of your Linode in a browser.

    Linode API

  5. When the setup process has completed, you will receive an email containing details about your new server.

    Linode API

Add a Domain Name

If you want to use Let’s Encrypt to obtain a free SSL certificate for your website, you will need to buy a Fully Qualified Domain Name (FQDN) and set it to point to your new server.

  1. Head back to Laravel Forge account then click on the active server.

  2. Go to your domain name provider, add an ANAME record for the domain or subdomain, and point it to the public IP address of your server.

    Linode API

    • Root Domain: This is your domain name.
    • Project Type: This is the type of project you are using. If you are building regular PHP, you can choose General PHP/Laravel. Other options include Static, HTML, Symfony, and Symfony (Dev).
    • Web Directory: This is the directory from which public files will be served.
  3. Submit the form by clicking ADD SITE.

    If you do not add a domain name, you can still access your server through its public IP address.

Add a Repository

  1. Click on your active servers. Under the active site, choose the domain name you added in the previous step.

    Linode API

  2. Click Apps on the left-hand side and then select your Git repository.

    Linode API

  3. Fill in the repository field with your username and repository. Then select the branch you want to use. Click on INSTALL REPOSITORY. Observe that the repository field is gitlab_username/repository_name_without_.git. The sample image below shows dongido/transaction-manager:

    Linode API

  4. If you visit the website again, the repository is now copied to your Linode server and everything is set up.

    Linode API

Quick Deploy

These steps will show how to immediately deploy changes from the source directory to the live site.

  1. From the INSTALL REPOSITORY menu, toggle Quick Deploy to “on”.

    Linode API

  2. Make changes to your project on Github or Gitlab and commit them to the master branch. Your live site will be updated to reflect the changes.

    Linode API

Adding SSL to Your Domain Name

SSL (Secure Sockets Layer) is the standard security technology for establishing an encrypted link between a web server and a browser. To add SSL:

  1. Choose your server on Forge.

  2. Select the domain name of your server.

  3. Click on SSL from the menu on the left.

    Linode API

    Laravel Forge comes with Let’s Encrypt which help us generate a free SSL certificate.

  4. If you already have an SSL certificate, click on the Install Existing Certificate. Otherwise, select LetsEncrypt (Beta).

  5. If you chose to use LetsEncrypt, you will be presented with a button to obtain a certificate. Click on it and allow it to install.

  6. Activate your new certificate by clicking on the activate icon.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Join our Community

Find answers, ask questions, and help others.

comments powered by Disqus

This guide is published under a CC BY-ND 4.0 license.