DEV Community

Sankeeth Sriranganathan
Sankeeth Sriranganathan

Posted on

Laravel Server Setup (LEMP)

So you have built your amazing Laravel app and now you are ready for the world to see it. There is a variety of ways to host a Laravel app, however, in this post, we are going to run through how to host an app on a VPS using the LEMP technology stack.

The LEMP acronym stands for:

(L) Linux
(E) Nginx
(M) MySql
(P) PHP

Step 1 - Setting Up VPS

We will not be going into detail about VPS in this post, as it is a whole other topic

There is now a large amount of hosting providers that are offering VPS servers that very low costs. We are going to be using Digital Ocean as it allows for servers to be scaled up or down very easily.

  1. Create a new account on Digital Ocean
  2. Click on Create then Droplets
  3. Choose the Ubuntu image for your server
  4. Choose the server size
  5. Choose datacenter destination
  6. Add your SSH key
  7. Finally click created new droplet

Step 2 - Accessing Your Server

ssh root@100.100.100.100
Enter fullscreen mode Exit fullscreen mode

When accessing your server for the first time you will ask to confirm connection using the SSH key. Check that everything looks correct and continue connecting.

Step 3 - Updating the Package Manager

Before we continue we need to update the Apt-Get. This is used to install Linux based programs on your server.

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

By running the command above we can make sure Apt-Get is updated before we start installing anything.

Step 4 - Installing Nginx

During this step, we will be installing the E part of our LEMP stack.

Using Apt-Get we can usually install Nginx on our server by running the following command.

sudo apt-get install nginx
Enter fullscreen mode Exit fullscreen mode

Step 5 - Installing MySQL

MySQL is will satisfy the M within our LEMP stack. Run the following command to install MySQL.

sudo apt-get install mysql-server
Enter fullscreen mode Exit fullscreen mode

Once MySQL has successfully installed on the server, it is best to secure it to remove some of the vulnerabilities associated with MySQL.

To do this run the following command and you will get a series of questions that will help you secure your MySQL install.

sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

Step 6 - Installing PHP

Now it is very likely that PHP is already included in your Linux based server. However, we will need to update a few things as we need to set up PHP for processing. To do this run the following command.

sudo apt-get install php-fpm php-mysql php-mbstring
Enter fullscreen mode Exit fullscreen mode

By following the steps above you should now have a LEMP server for your Laravel applications.

Discussion (0)