Deploying Laravel Applications on Laravel Cloud With MongoDB Atlas

Last updated on by

Deploying Laravel Applications on Laravel Cloud With MongoDB Atlas image

Hosting a website or an application has always been a pain in the past. However, things got easier with time, and today, it has become seamless using Laravel Cloud. Laravel Cloud is a fully managed platform that allows you to hold the applications and host an optimised, scalable application without the pain of having server management.

In this tutorial, we will deploy a simple Laravel application on the Laravel cloud and connect with MongoDB Atlas.

The native integration of MongoDB as a database is not available at this moment in Laravel Cloud, but configuring the database is very simple as Laravel Cloud includes the MongoDB PHP extension by default. We will go through the steps on how to deploy in detail in the coming section.

Let’s get into it.

Pre-requisites

To deploy an application on the Laravel cloud, you need just a few things before we begin:

  1. Sign up for your first free Laravel Cloud account.
  2. MongoDB’s Atlas cluster. You can start by creating an Atlas cluster for free by following the documentation on Deploy a Free Cluster.
  3. A Laravel application connecting to MongoDB Atlas deployed on your GitHub, GitLab, or BitBucket repositories.

That's all you need. Once you are all set, deploying the application will just take a few minutes.

But before moving ahead, it is equally important to understand the Laravel cloud in detail so that we can deploy the application with ease.

Understanding Laravel Cloud

As the Laravel Cloud documentation says, Laravel Cloud is a fully managed platform as a service that allows you to deploy an optimised and scalable application with ease.

Here are a few of the important features of Laravel Cloud:

  1. You can deploy Laravel applications without any setup or server configuration.
  2. Database storage can be provisioned instantly.
  3. Updates are deployed with zero downtime, ensuring uninterrupted availability.
  4. Infrastructure can be scaled instantly without affecting application performance.
  5. TLS certificates and load balancing are automatically managed for security.
  6. Cloudflare-powered caching and DDoS protection enhance performance and security.
  7. Real-time monitoring and logs allow you to track application performance easily.

You can learn more about Laravel Cloud and its features by following the documentation on Welcome to Laravel Cloud.

Now, it's time to start learning the steps you need to follow to deploy your applications.

Deploying on Laravel Cloud

We will divide this section into two parts. First, we’ll configure our GitHub, GitLab, or BitBucket repositories, and second, we’ll configure the databases.

Once you have logged into the Laravel Cloud account and created your organisation, select the Sandbox which is free to get you started. Once you’re all set, click on New Application. You need to configure the control provider and repository for yourself.

As seen in the below screenshot, I have my Laravel application in the GitHub repository which is linked to the Laravel cloud. I have also selected the nearest region for myself. It is recommended that you select the same region for your MongoDB Atlas cluster and Laravel Cloud deployment. For instance, you can select ap-southeast-1(Singapore) for MongoDB Atlas and Asia Pacific(Singapore) for Laravel Cloud.

Screenshot from Laravel Cloud UI representing steps on setting up the Laravel repositories

Click on New Application, and you should see the application in the UI.

The next step is to deploy the application. To do that, click on Deploy. You should see the application being deployed in just a few seconds. In my case, it was 49 seconds. Great, right?

Click on Visit, and you should be able to see the application running.

But wait, it shows an error. ‼️

At this point, we should be able to see the logs and identify the error. As in the below image, we see ERROR: MongoDB connection configuration requires "dsn" or "host" key.

Screenshot from Laravel Cloud UI representing error logs

We have this error because we haven’t configured the database at this point. Now, let's try and understand how to configure the database.

At this point, Laravel Cloud has direct integration with Postgres and MySQL, but it also allows you to configure other databases.

To do that, all you need to do is copy the connection string from the Atlas UI, as shown in the below image.

Screenshot from Atlas UI demonstrating how to copy the connection string

Once copied, go to the Laravel Cloud settings tab and click on Reveal Secrets to add your environment variable. You can use the below screenshot for reference.

Screenshot from Laravel Cloud UI demonstrating steps to make the MongoDB connection

All you need to do at this point is save —-> redeploy —---> and voila! The application is all set and running.

Click on Visit to view your application. I have my content-management application ready with a public URL.

This was simple, right?

Deploying a Laravel application on Laravel Cloud with MongoDB Atlas is a seamless process that eliminates the complexities of server management. With just a few configurations, you can set up a highly scalable and optimized application quickly.

Conclusion

By following this tutorial, we have learned how to integrate MongoDB Atlas and leverage Laravel Cloud’s powerful features to host your Laravel application effortlessly. With real-time monitoring, automatic scaling, and built-in security, Laravel Cloud provides a robust infrastructure for modern web applications.

Now that your application is up and running, you can focus on building and enhancing its features without worrying about deployment hassles.

Ready to take it further? Explore more Laravel Cloud features, automate your deployment pipeline, and make the most of your cloud-based Laravel application with MongoDB Atlas.

You can also watch the YouTube clip here.

Aasawari Sahasrabuddhe photo

Senior Software Engineer, Technical writer , PHP, Laravel, Java

Cube

Laravel Newsletter

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

image
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi
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
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
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Tinkerwell logo

Tinkerwell

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

Tinkerwell
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Lucky Media logo

Lucky Media

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

Lucky Media
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Shift logo

Shift

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

Shift
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum

The latest

View all →
Building and Deploying a Laravel App With Claude Code on Zerops image

Building and Deploying a Laravel App With Claude Code on Zerops

Read article
The first hands-on AI Developer Certification image

The first hands-on AI Developer Certification

Read article
Heimdall: A Minimum Age Policy for Your Composer Dependencies image

Heimdall: A Minimum Age Policy for Your Composer Dependencies

Read article
Laravel Announces the Founders Summit, a One-Day Event for Founders image

Laravel Announces the Founders Summit, a One-Day Event for Founders

Read article
A Practical Guide to Laravel's First-Party Image Processing image

A Practical Guide to Laravel's First-Party Image Processing

Read article
RouteKey Model Attribute in Laravel 13.21 image

RouteKey Model Attribute in Laravel 13.21

Read article