Trustpilot Reviews

infotech expertx min

Deploy Laravel Application on Digital Ocean

If you’ve developed an application with Laravel and you’re ready to deploy it, Digital Ocean is an excellent hosting solution. It’s affordable, fast, and easy to use, making it an excellent option for developers of all levels. In this article, we’ll walk you through the process of deploying your Laravel application on Digital Ocean, step by step.

Additionally, deploying a Laravel application on Digital Ocean can be a rewarding experience for developers who want to take their projects to the next level. With the right knowledge and tools, your application can be up and running on a reliable, scalable, and affordable platform in no time. Remember to follow best practices for server administration, security, and performance to ensure that your application is always up and running smoothly.

If you need help in doing this or need our services you can visit our page at Laravel App Development.

Or if you need a Laravel and Vue Developer you can check out our Lavrael and Vue JS Services.

1. Introduction

Laravel is a popular PHP web framework, known for its elegant syntax and powerful features. Additionally, Digital Ocean offers a range of benefits for hosting web applications, making it a powerful combination. In this article, we’ll be covering the process of deploying your Laravel application on Digital Ocean. Certainly! We can break down the information for you.

2. Prerequisites

  • A Laravel application that you want to deploy
  • A Digital Ocean account
  • Basic knowledge of server administration
  • An SSH client

3. Setting Up Your Digital Ocean Droplet

The first step is to set up your Digital Ocean droplet. To do this, log in to your Digital Ocean account and click on Create Droplet. Choose your preferred operating system and select the smallest available size. For this tutorial, we’ll be using Ubuntu 20.04. Additionally, select a data center, add options like backups, and create a new/choose an existing SSH key for droplet authentication. Consider two-factor authentication or a firewall for added security.

4. Creating a User and Adding SSH Keys

After your droplet has been created, you can log in using SSH. First, the step is to create a new user.

					sudo adduser your-username


Replace your username with a username of your choice. Additionally, you’ll be prompted to enter a password and some additional information about the user.

Next, you can add your SSH key to the new user’s authorized keys.

					sudo mkdir /home/yourusername/.ssh

					sudo touch /home/yourusername/.ssh/authorized_keys

					sudo nano /home/yourusername/.ssh/authorized_keys


Copy your SSH key into the file and save it. Now, you can log in as the new user using SSH. Additionally,

					ssh yourusername@yourserverip


5. Installing Necessary Software on Your Droplet

To deploy Laravel, first, install the necessary software, verify the server meets requirements, and configure the firewall for security. Then, update your package index.

sudo apt-get update

Next, install the necessary software:

					sudo apt-get install apache2 mysql-server php php-mysql libapache2-mod-php php-xml php-mbstring


Additionally, this will install the Apache web server, MySQL, and PHP, along with some additional modules that Laravel requires.

Launch Laravel, Thrive on Digital Ocean.

6. Creating a New Virtual Host

Next, you’ll need to create a new virtual host for your Laravel application. First, transition by creating a new directory for your application:

					sudo mkdir /var/www/yourapp


Next, first, create a new virtual host configuration file.

					sudo nano /etc/apache2/sites-available/


After creating a new virtual host for your Laravel application, there are several next steps you can follow. Firstly, configure the necessary server settings.

  1. To configure the virtual host and add the specified configuration, follow these steps:
					<VirtualHost *:80>
					    ServerAdmin your_email@example.com

					    ServerName yourapp.com

					    ServerAlias www.yourapp.com

					    DocumentRoot /var/www/yourapp/public

					    <Directory /var/www/yourapp/public>
					        AllowOverride All

					    ErrorLog ${APACHE_LOG_DIR}/yourapp_error.log

					    CustomLog ${APACHE_LOG_DIR}/yourapp_access.log combined
					 <VirtualHost> </VirtualHost>
					Replace “your_email@example.com” with your email address and “yourapp.com” with your domain name. Save and close the file.
  1. First, you need to enable the virtual host, and then execute the following command:

					sudo a2ensite yourapp.conf


Replace “your app. conf” with the name of the virtual host configuration file you just created.

  1. Next, restart Apache by running the following command:
					sudo systemctl restart apache2

  1. Now your Laravel application is ready to be deployed on Digital Ocean.

7. Configuring Your Laravel Application

To configure your Laravel application for deployment on Digital Ocean, you’ll need to follow these steps:

  1. Configure your .env file: Open the .env file in the root directory of your Laravel application and update the database configuration with your MySQL database credentials:






  1. To secure the Laravel app, generate a key with a command in the root dir. Additionally, keep it confidential; store it in env vars, not code.
					php artisan key: generate

  1. In order to transition your database smoothly, utilize the following command to migrate it:
					php artisan migrate


8. Setting up SSL Certificate

To set up an SSL certificate for your Laravel application, follow these steps:

  1. To install Certbot, follow the instructions provided below:
					sudo apt-get update

  1. To obtain SSL, first, run the command to generate CSR, then submit it to a trusted CA, and finally, install and configure the certificate.

					sudo certbot –apache -d yourapp.com -d www.yourapp.com


Follow the prompts to obtain the certificate. This is important because it ensures that the process is conducted accurately and efficiently. Please write in English language to facilitate clear communication and understanding throughout the certification procedure.

  1. Furthermore, these lines will redirect all HTTP requests to HTTPS for the domain example.com. Please make sure to replace “example.com” with your actual domain name.

					<VirtualHost *:80>
					    ServerName yourapp.com
					    Redirect / https://yourapp.com/

  1. Lastly, to restart Apache, execute the following command:

					sudo systemctl restart apache2


9. Testing Your Application

To test your Laravel application on Digital Ocean, follow these steps:

Firstly, access your application: Open a web browser and navigate to your domain name. You should see your Laravel application’s home page.

Next, test your database connection: Create a new record in your application and verify that it’s saved to the database.

Finally, test your SSL certificate: Verify that your website is loading over HTTPS and that your SSL certificate is valid.

10. Conclusion

Deploying a Laravel application on Digital Ocean is a straightforward process that requires some basic knowledge of server administration. This process involves several simple steps. First and foremost, deploying Laravel on Digital Ocean is easy: create an account, droplet, configure, connect, install, and deploy.


Digital Ocean is a cloud computing platform that provides scalable, affordable, and easy-to-use infrastructure for developers and businesses.

How do I create a virtual host in Apache?

To create a virtual host in Apache, the first step is to create a new configuration file in the directory /etc/apache2/sites-available/. Next, you will need to define the server name and document root for your virtual host. This information will be used to direct traffic to your website.

Additionally, Digital Ocean offers various tutorials and documentation to help you set up and manage your virtual hosts efficiently.

To create a virtual host in Apache, the first step is to create a new configuration file in the directory /etc/apache2/sites-available/. Next, you will need to define the server name and document root for your virtual host. This information will be used to direct traffic to your website. Additionally, this involves ensuring that all necessary settings and options are properly configured to optimize your virtual host’s performance.

To install Laravel on Digital Ocean, first, create a Droplet. Next, install Apache, MySQL, and PHP. Once that’s done, proceed to configure your server. Afterward, download and install Laravel using Composer. Finally, complete the setup by configuring your application with a database connection, .env file updates, and migrations. Additionally, ensure you follow the necessary security measures throughout the process.

Tell Us More About Your Project!