Deploy Laravel Project On Digital Ocean Full Explanation - FreeCodeBlog

Last updated: Jun 15, 2022

Laravel is one of the best framework that builds web application in PHP. It ensures a pleasing journey for the developer with satisfactory functioning. Laravel deployment is the final step of this process. To ensure the perfection in outcome of a project, the deployment must be cautiously done. Digital Ocean is one of the most reliable and affordable web hosting service provider for laravel projects. It also has a very large community that can help with problems of a user. All this advantages makes Digital Ocean a good choice for deploying laravel projects. In this article, the full process of deploying a Laravel project on Digital Ocean will be explained broadly.


Deploy Laravel Project On Digital Ocean Full Explanation
Deploy Laravel Project On Digital Ocean Full Explanation


To deploy laravel in Digital Ocean you just have to follow some very simple steps.

  • Creating an account on A Digital Ocean.
  • Selection of the size of your server.
  • Selection of operating system and region.
  • Providing an image for operating system.
  • Creating a droplet.
  • Installation of LAMP/LEMP stack.
  • Installation of Laravel app.
  • Adjustment of the firewall.
  • Installation of the PHP modules.

This is the process in a very short manner. Now I'll provide a elaborated process of deploying Laravel projects on Digital Ocean. If you don’t understand the method with the quick process provided earlier, I hope this broad discussion with tiny details will help.


Step 1:
First of all, you have to create an account on Digital Ocean if you don’t have one.

Step 2:
Secondly, you need to have a configured GitHub. Only after configuring GitHub you will be able to view your repositories.

Step 3:
Now you have to select a name for your deployment. All the letters in the name must be in lowercase. Then you have to select where you want to deploy. You can also select a branch to deploy. You also have the option to auto deploy every time a commit is made to your repositories.

Step 4:
After doing all that, now you will be able to add variables. But if you use “App Spec” with doctl, you won't have to go through this process. 

Step 5:
This is the main step of deploying. Now you have to choose a plan. For laravel, the deployment can not be done as a static site as PHP is a server side language. You have to choose a perfect plan for your project. You can also choose any plan such a s 5$/month and then later on changing it to 12$/month, you can also do that. 

Step 6:
Now you have to go to the COMPONENTS tab and click on CREATE COMPONENT and select database. By default, Digital Ocean supports PostgreSQL so you cam choose that. In this part you only do the development while your system is setting up. Also, the app Platform will do some of the works such as setting the environment variable to get connection with the database.

Step 7:
Now you have give time and let the database create and redeploy your app. After the development database creation is done, the injection of the connection string to the app as an environment variable called DATABASE_URL. Now you have to bring all your tables to the database using the command ‘php artisan migrate'. After completing the deployment, move to “CREATE A WORKER' option.

Step 8:
Click on the console for your project using the backend, then type ‘php artisan passport:install'. This will create the keys and database for all the necessary authentication. It will also provide the location of your public and private keys. For every file, to view the contents save them as an environment variable for which you will need 2 commands. 1. Cat oauth-private.key, 2. Cat oauth-public.key.

If you forget to change the database driver, which most people do, go back to Components ~ Your Deployment ~ Environment Variables ~ Edit and add ‘DB_CONNECTION=pgsq1. This will cause a redeployment because it has to be available to the alp. If you own a worker setup, you must add it in the worker setup as well. If you do it, the first deployment will be cancelled and new one will be built. 

Managed DB is the main reason for people loving Laravel and app platform. You can easily set up the scaling ahead of time. You can also change the config/database.php file in Laravel for both MySQL or PGSQL to look like this. 


Now you have perfectly deployed your Laravel part jet on Digital Ocean which is one of the best hosting operators of this time with amazing speed and a lot of features. It can be guaranteed that you will get performance -optimized servers that will ensure you good surfing experience. If you're still not sure whether to go for it or not, you choose the 3 day trial to experience Laravel on Digital Ocean and see the results for yourself. Then you can ultimately decide whether to go for it, or not.

Post Tags
Post Writer
Masum Biswas (@masum7323)

My name is Masum Biswas. I'm a full stack developer. I live in Bangladesh and I love to write tutorials and tools that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, MySQL, VueJS, Tailwind CSS and Bootstrap from the early stage.

Follow Me On
Related Posts
Solve Ckeditor 5 Code Block Plugin Not Working In Laravel

Ckeditor 5 code block plugin not working in laravel? No. Do you have a programming laravel project and want to use code block ckeditor 5 plugin in... Read More

How To Upload File On Laravel Vue

You need to read upload a file on laravel 8 vue 2 tutorial If you want to know how we can upload a image file in laravel 8 with vue 3. so guys, let... Read More

Download A File In Laravel Vue From Storage Folder

Want to download a file from storage folder in laravel with vue js? Yes! Okay don't worry you can easily make a download file from storage folder s... Read More

How To Make A Filter Search In Laravel With Vue Js

Laravel vue filter search! Want to make a filter search in laravel with vue js? Yes. Okay don't know to make filter search system using laravel and... Read More

Please Commit Your Changes Or Stash Them Before You Merge Slove For Cpanel Git Version Control

You need to solve your local changes to the following files would be overwritten by merge and please commit your changes or stash them before you m... Read More