Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

How to set up Laravel Forge on a custom VPS server

Published on by

How to set up Laravel Forge on a custom VPS server image

In this tutorial we are going to have a detailed look at how you can install Laravel Forge on a custom VPS as well as how to set up SSH keys to ensure a secure connection.

Setup requirements

Based on the Forge documentation, you are going to need the following:

  • A VPS server with fresh Ubuntu 20/22 installation
  • A server with at least 1 CPU core @ 1Ghz, 1GB RAM & 10GB disk space
  • An account on the Forge platform with an active subscription

For this tutorial, we are going to be using a cloud VPS server with Ubuntu 22.04.

Simple installation process

Setting up Laravel Forge on your custom VPS is actually really straight-forward as the installer automatically takes care of the entire process.

Select custom VPS

Start by opening up the Forge control panel. Next, click on the Create Server button. You will then see a list of existing providers. From here, select the Custom VPS option as illustrated below:

Choose app server type

We can now focus on the Type field. The default option - App Server is the perfect choice if you want to effortlessly deploy your Laravel/PHP applications as you get everything (PHP, Nginx, DB server, Redis and Memcached) in one single installation.

If you're uncertain about which server type will suit your needs, you can always choose App server as a good starting point. As your application grows, you can easily scale by adding dedicated servers for specialized services such as databases or data caching. Due to the versatile nature of this option, we are going to be using the App server type.

Enter your server's IP

Finally, you will need to fill in the other fields. Simply enter your server's IP address and leave the other fields with their default values. It is important to remember that you might need to alter some information depending on your hosting provider. However, in most cases, you'd only need to enter your server's IP.

NOTE: If you are installing Forge on Ubuntu 20, make sure to select it from the Advanced Settings menu!

Once you are done, click on Create Server. You will be then given a wget command that you will need to run on your server:

IMPORTANT: Make sure to store the provided server credentials in a secure location before proceeding!

Once you have copied and stored the credentials, you can paste in the command and run it:

Monitor the installation process

Once you start the command, you will also be able to monitor the installation through the control panel:

When the installation concludes, a new panel will open, which will contain many different customization options for your VPS:

How to set up SSH access for your server

The Forge installer will automatically take care of your server's security by leaving the 80, 443 & 22 open. Additionally, it also automatically disables password authentication for your server during the installation process. Because of this, you will need to manually create and configure a SSH key pair that you can use to connect to your server.

Create and copy your public SSH Key

Firstly, you'll need to generate an SSH key pair on your local machine. For Windows, you can use an app like PuTTY. As for MacOS or Linux, you can use the built-in terminal.

The SSH key pair consists of a public key and a private key. The public key is what you'll be adding to Laravel Forge and the private key will be stored securely on your local machine.

To create a SSH key pair on Linux/MacOS, open up the terminal and type in the following command:

ssh-keygen

Once you have your keys, make sure to copy your public key - it will be a long string of characters starting with either ssh-rsa or ssh-ed25519.

Add the public SSH key to Laravel Forge

Log into Forge and select the server that you want to add the SSH key to from the list that will be shown on your dashboard.

Next, click on the SSH Keys button from the menu on the side. This will take you to the SSH keys management page. From here, click on the Add SSH Key button. Then, you will need to paste in your public SSH key that you previously copied and you will also need to give it a name. Once you're done, click on the Add button to save your settings.

That's it! You've added your SSH key to Laravel Forge. You can now connect to your server from your local machine. Remember to keep your private key safe and secure as it's the only method that you can use to establish a connection to your server.

Eric L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Filed in:
Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Jump24 - UK Laravel Agency

Laravel Developers that Click into Place. Never outsourced. Never offshored. Always exceptional.

Visit Jump24 - UK Laravel Agency
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
FrankenPHP v1.11.2 Released With 30% Faster CGO, 40% Faster GC, and Security Patches image

FrankenPHP v1.11.2 Released With 30% Faster CGO, 40% Faster GC, and Security Patches

Read article
Capture Web Page Screenshots in Laravel with Spatie's Laravel Screenshot image

Capture Web Page Screenshots in Laravel with Spatie's Laravel Screenshot

Read article
Nimbus: An In-Browser API Testing Playground for Laravel image

Nimbus: An In-Browser API Testing Playground for Laravel

Read article
Laravel 12.51.0 Adds afterSending Callbacks, Validator whenFails, and MySQL Timeout image

Laravel 12.51.0 Adds afterSending Callbacks, Validator whenFails, and MySQL Timeout

Read article
Handling Large Datasets with Pagination and Cursors in Laravel MongoDB image

Handling Large Datasets with Pagination and Cursors in Laravel MongoDB

Read article
Driver-Based Architecture in Spatie's Laravel PDF v2 image

Driver-Based Architecture in Spatie's Laravel PDF v2

Read article