Key Takeaways
- You can either set up Laravel manually on DigitalOcean for full flexibility or use Cloudways to skip the heavy lifting and get a managed environment ready in minutes.
- Since Laravel apps run from the
public/directory, making sure your server points here avoids errors and keeps your app secure. - Don’t forget to update your
.envfile with database credentials and adjust folder permissions so Laravel migrations, storage, and caching work without issues.
Shared hosting often bottlenecks Laravel applications with limited resources and restricted terminal access. To get real performance and full control over your environment, developers switch to cloud infrastructure like DigitalOcean.
DigitalOcean provides dedicated Droplets (VPS) that let you configure the exact server environment your application needs, ensuring stability and scalability.
In this guide, I will show you exactly how to deploy Laravel on DigitalOcean using two distinct workflows.
First, the Manual Method, where you provision a Droplet and configure the server stack yourself. Second, the Cloudways Method, which simplifies the process using a modern Git-based workflow to deploy directly to a managed DigitalOcean server.
- Method 1: How to Deploy Laravel on DigitalOcean (Manual Installation)
- 1) Create your Droplet
- 2) Connect to your server (via DigitalOcean Console)
- 3) Update the server & enable a basic firewall
- 4) Install the Software Stack (Nginx, PHP, Node.js)
- 5) Configure MySQL Database
- 6) Install Laravel & Build Assets
- 7) Configure Laravel’s Environment (.env)
- 8) Set Permissions & Run Migrations
- 9) Configure Nginx to Serve Your Site
- 10) Test It Live!
- Method 2: Deploy Laravel to DigitalOcean via Cloudways (The Faster Way)
Method 1: How to Deploy Laravel on DigitalOcean (Manual Installation)
Let’s dive into the first method. The manual approach is perfect for developers who want full control over their server stack. It might look intimidating at first, but it is actually a great way to understand exactly what’s happening behind the scenes of your application.
Prerequisites (Quick checklist)
- DigitalOcean Account: You’ll need an account with billing set up.
- Console Access: We will use the browser-based terminal provided by DigitalOcean, so you don’t need any special software on your computer.
- A Domain (Optional): If you want a real .com pointing to your site, you can set that up later. For now, we will use the IP address.
Placeholders you’ll replace as you go:
YOUR_SERVER_IP– The public IP address DigitalOcean assigns to you.myapp– The name of your project folder (you can name it whatever you want).
Cloudways Laravel Hosting on DigitalOcean
Skip the manual setup. Launch a fully optimized, secure Droplet in minutes without touching a single terminal command.
1) Create your Droplet
First things first, let’s get you a server. Log in to your DigitalOcean dashboard. In the top right corner, click the green Create button and select Droplets from the dropdown menu.

Region: Pick the datacenter closest to where your users actually are. If your audience is in New York, don’t pick a server in Bangalore. Latency can kill your SEO.

Image (Operating System): This is the most critical choice. Scroll down to the “Choose an image” section. By default, it might show an older version, so make sure you select Ubuntu 24.04 (LTS) x64.

Note: LTS stands for “Long-Term Support.” This ensures your server stays stable and secure for years without forcing you to upgrade the operating system constantly.
Size (CPU & RAM): For a standard Laravel application, you don’t need a supercomputer. Just scroll down to “Choose Size” and select the $8/month (1GB RAM / 1 CPU). It is perfect for getting started. You can always upgrade later based on your needs.

Authentication: We are going to skip the “Password” option because it’s less secure. Instead, we will use SSH Keys. This works like a digital handshake. Your computer has a special “key”, and we give the “lock” to DigitalOcean.
Since I’m using Windows, here is how I’d generate a key:
- Open command prompt.
- Type this command and press Enter:
ssh-keygen - It will ask you where to save the file. Just press Enter.
- Then it will ask for a passphrase. You can press Enter twice to leave it empty for now.

Now we need to grab the text of the key we just created. Run this command to get that:
type %userprofile%\.ssh\id_ed25519.pub
You should see a long string of text starting with ssh-ed25519. Highlight that entire string and copy it.

Go back to the DigitalOcean page, click New SSH Key, paste it in, and give it a name like “Windows-Laptop”. Finally, click the Add SSH Key button.

Once that is done, make sure the checkbox next to your new key is checked.

Scroll to the bottom and click Create Droplet.

2) Connect to your server (via DigitalOcean Console)
Watch the progress bar on your dashboard. Once it finishes, your server will be live.
Now, instead of messing with terminal commands on your computer, we’re going to use the Launch Console option in the DigitalOcean dashboard. This opens a direct line to your server right inside your web browser.
- Click on the “More” dropdown next to your Droplet.
- Look for the Access menu button.
- Click the blue button that says Launch Droplet Console.


We are now inside the DigitalOcean server as the root user (the super-admin).
3) Update the server & enable a basic firewall
Before we install Laravel, let’s give your brand-new server a health check. We want to ensure all the pre-installed system software is up-to-date and lock the doors to unwanted visitors.
Run this command to download and install updates. It might take a minute or two:
apt update && apt upgrade -y
Important: During the update process, you might see a pink screen asking about configuration files (specifically sshd_config). Select “keep the local version currently installed” and press Enter.

Once the updates finish, it is best practice to reboot the server to apply any kernel changes. Run:
reboot
(You will lose connection for about 30 seconds. Close the console window, wait a moment, and launch it again).
Next, let’s set up a Firewall. DigitalOcean servers are open to the world by default, which isn’t safe. We need to tell the server to only allow SSH connections (so you can log in) and Web traffic (so people can see your site).
Run these commands one by one:
apt install -y ufw
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
Note: When you run ufw enable, it might warn you that it could disrupt SSH connections. Since we explicitly allowed OpenSSH in the step before, it is safe to type y and press Enter.
4) Install the Software Stack (Nginx, PHP, Node.js)
Now comes the heavy lifting. We need to install the “engine” that runs Laravel. This includes Nginx (the web server), PHP (the language Laravel is written in), MySQL (the database), and Composer (to download Laravel).
We also need Node.js. Modern Laravel uses a tool called Vite to build your CSS and designs. Without Node.js, your site will just look like a broken white page.
Copy and paste this entire block into your console to install the core software:
apt install -y nginx mysql-server php-fpm php-mysql php-cli php-mbstring php-xml php-bcmath php-curl php-zip php-gd php-intl unzip git composer
Next, let’s install Node.js and NPM (the package manager for JavaScript):
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && apt install -y nodejs
Let’s verify it worked. Type systemctl status nginx and press Enter. You should see green text saying active (running).

5) Configure MySQL Database
Your application needs a place to store data (like user accounts). Let’s configure the MySQL server we just installed.
First, we need to enter the MySQL console. In your terminal, type:
mysql
Your prompt will change to mysql>. We need to create a database and a user. Run these four commands one by one:
1. Create the database:
CREATE DATABASE laravel_db;
![]()
2. Create a user (Change ‘StrongPass’ to your own secure password):
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'StrongPass';
![]()
3. Give the user permission to use that database:
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';
![]()
4. Save changes and exit:
FLUSH PRIVILEGES;
EXIT;
![]()

What you’ve done: You created a secure room (laravel_db) and gave a key to a specific user (laravel_user). This is much safer than using the root account for everything.
6) Install Laravel & Build Assets
Now for the fun part… actually installing Laravel. We’ll use Composer to pull down the latest version of the framework.
First, navigate to the web directory where websites live:
cd /var/www
Now, create your project. You can change myapp to whatever you want your folder to be named:
composer create-project laravel/laravel myapp
If it asks “Do not run Composer as root/super user… Continue?”, type yes and hit Enter.
Move into your new project folder:
cd myapp
Then run the build command:
npm install && npm run build
If you see a green “Build” success message, you are golden. Your application code is now sitting on the server, ready to go.
7) Configure Laravel’s Environment (.env)
Laravel relies on a hidden file called .env to know your database password. We need to edit this file using Nano.
nano .env
Use your arrow keys to move down until you find the DB_ section. Update it to match the credentials you created in Step 5:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=StrongPass
While you are here, look for APP_URL at the top of the file and change it to your actual server IP: APP_URL=http://YOUR_SERVER_IP

Tip: While you are editing the file, it is best practice to change APP_DEBUG=true to APP_DEBUG=false. This hides sensitive error details from the public.
How to save and exit Nano:
Press CTRL + O, then Enter, then CTRL + X.
Back in your regular terminal prompt, generate an application key or Laravel will show a 500 Server Error:
php artisan key:generate
8) Set Permissions & Run Migrations
We need to make sure the web server (Nginx) has permission to write to your storage folders.
chown -R www-data:www-data storage bootstrap/cache
chmod -R 775 storage bootstrap/cache
Now, let’s fill that empty database with Laravel’s default tables:
php artisan migrate
(Type yes if asked to confirm).
9) Configure Nginx to Serve Your Site
Right now, Nginx is still showing the default “Welcome” page.

We need to create a new configuration file. Type:
nano /etc/nginx/sites-available/myapp
Paste the following code (replace YOUR_SERVER_IP with your actual IP):
server {
listen 80;
server_name YOUR_SERVER_IP;
root /var/www/myapp/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}

Save and exit (CTRL + O, Enter, CTRL + X).
Now, enable this site and remove the default one:
ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
Test your config:
nginx -t

Finally, restart Nginx:
systemctl reload nginx
10) Test It Live!
Open your browser and visit: http://YOUR_SERVER_IP
If you followed every step, you should see the beautiful, modern Laravel welcome page.

Method 2: Deploy Laravel to DigitalOcean via Cloudways (The Faster Way)
If the manual method feels like too much work, Cloudways gives you a simpler path. Everything runs on DigitalOcean infrastructure, and we handle server management for you, so you don’t have to worry about security updates, firewalls, or installing PHP extensions manually.
In this method, we will create the app on your computer first, push it to GitHub, and then let Cloudways pull it onto the server.
1) Create the Application Locally
First, we need to generate the Laravel application on your own machine. Open your terminal and run:
composer create-project laravel/laravel my-app

Move into the folder:
cd my-app
Check the UI (Important): Confirm the app works before deploying.
php artisan serve

Open http://127.0.0.1:8000 in your browser.

2) Prepare for Deployment
Run this command to build your CSS/JS assets for production:
npm install && npm run build
3) Push to GitHub
Cloudways works best when it pulls code from a repository.
Log in to GitHub and create a new empty repository named my-app.


Run these commands in your terminal to upload your code:
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/my-app.git
git push -u origin main
(Replace YOUR_USERNAME with your actual GitHub username).
4) Launch the Cloudways Server
Log in to your Cloudways dashboard and click + Add Server.

- Application: Select Laravel.
- Provider: Select DigitalOcean.
- Server Size: The 1GB plan is perfect for starting out.
- Region: Choose the datacenter closest to your visitors.

Click Launch Now.
5) Connect Cloudways to GitHub
We need to give Cloudways permission to download your private code using an SSH Key.
- In Cloudways, go to Applications and select your Laravel app.
- Select Deployment Via Git from the left menu.
- Click Generate SSH Keys, then View SSH Keys and copy the text.


Add the Key to GitHub:
- Go to your GitHub repo settings.
- Select Deploy Keys > Add deploy key.
- Paste the key, name it “Cloudways”, and click Add Key.

6) Deploy the Application
Back in Cloudways Deployment Via Git:
- Git Remote Address: Paste your SSH link (starts with
[email protected]...). - Branch: Type
main. - Click Start Deployment.

7) Connect the Database
We need to update the .env file on the server to use the Cloudways database.
- In Cloudways, go to Access Details and copy your DB Name, Username, and Password.
- Go to Master Credentials and launch the SSH Terminal.

Navigate to your public folder:
cd applications
ls
cd [YOUR_FOLDER_NAME]/public_html
Open the settings file:
nano .env

Update the DB section with your copied credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=[Paste Database Name]
DB_USERNAME=[Paste Username]
DB_PASSWORD=[Paste Password]

Save the file (Ctrl+O, Enter, Ctrl+X).
8) Finalize the Installation
Since we uploaded a fresh application, we need to install the software libraries and clean up some default files to prevent conflicts. Run these commands in your SSH terminal:
1. Install Dependencies:
composer install

2. Clean Up Default Files:
rm database/migrations/20*.php
3. Set Up the Database:
php artisan migrate:fresh

9) Verify the Live Site
Go back to the Cloudways dashboard and click the Application URL.
You should now see the exact same Laravel “Welcome” page you saw on your local computer. Your app is now live on DigitalOcean!

Managed Cloudways Laravel Hosting
Stop wrestling with server configs. Deploy your app directly from GitHub and let us handle the security, backups, and updates.
Wrapping Up
Hosting Laravel on DigitalOcean gives you the performance and scalability your application needs, but the setup depends entirely on how much control you want versus how much time you want to spend managing servers.
In this guide, we covered two distinct paths: manually provisioning a Droplet to build the LEMP stack from scratch, and using Cloudways to automate the deployment pipeline directly from GitHub. You now have a live, production-ready environment that is secure and ready for traffic.
If you ran into any specific errors during the setup or have questions about the server configuration, drop a comment below.
1. How to install Laravel on a new server?
To install Laravel, the most common method is using Composer. Once your server has PHP and Composer ready, simply run the command:
composer create-project laravel/laravel your-app-name
This downloads the latest stable version of the framework and sets up the basic folder structure.
2. How do I host a Laravel project on DigitalOcean?
You have two main options to host a Laravel project. The manual method involves provisioning a DigitalOcean Droplet, installing the LEMP stack (Linux, Nginx, MySQL, PHP), and configuring the server via SSH. The automated method (via Cloudways) allows you to push your code to GitHub and deploy it to a DigitalOcean server with one click, handling all the server configuration for you.
3. What is the best way to deploy Laravel on DigitalOcean?
The most efficient way to deploy Laravel on DigitalOcean is using a Git-based workflow. By pushing your code to GitHub or GitLab, you can use tools like Cloudways or DigitalOcean App Platform to automatically pull updates and run migrations, ensuring zero downtime.
4. How much does Laravel hosting cost on DigitalOcean?
A standard Laravel DigitalOcean setup starts at $6/month for a 1GB RAM Droplet (manual setup). If you prefer a managed experience with 24/7 support and automated backups through Cloudways, pricing starts at $14/month.
5. Can Laravel run on Nginx?
Yes, Nginx is the recommended web server for Laravel. It is faster and more efficient than Apache for handling concurrent connections. DigitalOcean’s default “One-Click” Laravel installs and Cloudways’ managed stack both use Nginx by default to ensure high performance.
Abdul Rehman
Abdul is a tech-savvy, coffee-fueled, and creatively driven marketer who loves keeping up with the latest software updates and tech gadgets. He's also a skilled technical writer who can explain complex concepts simply for a broad audience. Abdul enjoys sharing his knowledge of the Cloud industry through user manuals, documentation, and blog posts.