Laravel on VPS: The Ultimate Deployment & Configuration Guide for Senior Developers
You're a Laravel expert.
You've mastered queues, events, service containers, and API resources.
Now it's time to step into the world of servers and production deployment.
Let’s walk through deploying Laravel on a VPS (Virtual Private Server) — from buying the server to running your app live like a pro.
🧠 Why Use a VPS Instead of Shared Hosting or Forge?
Let’s break it down:
| Hosting Type | Pros | Cons |
|---|---|---|
| Shared Hosting | Cheap, easy | Limited control, bad performance |
| Laravel Forge | Super convenient | Monthly cost, less control |
| VPS | Full control, scalable, fast | You manage everything (but that’s the point!) |
VPS is your first real step into DevOps — and gives you total control, flexibility, and performance.
🛒 Step 1: Choose Your VPS Provider
Here are great options:
- 🧊 DigitalOcean – Popular, easy UI
- ☁️ Vultr – Affordable, global datacenters
- 🔥 Hetzner – Incredible price-performance
- 💡 Linode – Great documentation
- ☁️ AWS Lightsail – Simplified AWS for beginners
➡️ Choose Ubuntu 22.04 with at least 1GB RAM (2GB preferred).
🔐 Step 2: Connect to Your VPS
Once the server is ready, you'll get an IP like 157.230.55.123.
Open your terminal:
ssh root@157.230.55.123
💡 First-time login tip: Always change your root password and create a non-root user for security.
adduser ajay
usermod -aG sudo ajay
Then log in as your new user:
ssh ajay@your-server-ip
🧰 Step 3: Install the Server Stack
Install Nginx, PHP, MySQL, and necessary tools.
Update server
sudo apt update && sudo apt upgrade -y
Install PHP 8.x and Extensions
sudo apt install php php-cli php-fpm php-mysql php-mbstring php-xml php-curl php-zip unzip curl git -y
Install Nginx
sudo apt install nginx -y
Install MySQL
sudo apt install mysql-server -y
Secure MySQL:
sudo mysql_secure_installation
Create Laravel DB:
CREATE DATABASE laravel_app;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'securePassword';
GRANT ALL PRIVILEGES ON laravel_app.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;
🧱 Step 4: Upload Your Laravel Project
Use Git or upload manually (SFTP).
Clone via Git
cd /var/www
sudo git clone https://github.com/yourusername/your-laravel-app.git laravel-app
cd laravel-app
Give permissions:
sudo chown -R www-data:www-data /var/www/laravel-app
sudo chmod -R 775 storage bootstrap/cache
⚙️ Step 5: Set Up Laravel Environment
Create .env file and update:
cp .env.example .env
Update DB info:
DB_DATABASE=laravel_app
DB_USERNAME=laravel_user
DB_PASSWORD=securePassword
Install composer dependencies:
composer install
php artisan key:generate
php artisan migrate
🌐 Step 6: Configure Nginx for Laravel
Create a new config file:
sudo nano /etc/nginx/sites-available/laravel-app
Paste:
server {
listen 80;
server_name yourdomain.com;
root /var/www/laravel-app/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Enable site and reload Nginx:
sudo ln -s /etc/nginx/sites-available/laravel-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
🔐 Step 7: SSL with Let’s Encrypt
Install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Get SSL:
sudo certbot --nginx -d yourdomain.com
Auto-renew:
sudo certbot renew --dry-run
🛡️ Step 8: Queue Worker & Scheduler
Install Supervisor
sudo apt install supervisor -y
Create a worker config:
sudo nano /etc/supervisor/conf.d/laravel-worker.conf
Paste:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/laravel-app/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/laravel-app/storage/logs/worker.log
Reload:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
Add Cron Job
crontab -e
Add:
* * * * * cd /var/www/laravel-app && php artisan schedule:run >> /dev/null 2>&1
📦 Optional But Recommended
- 🔎 Install Fail2Ban for security
- 🔐 Use UFW firewall to allow only SSH, HTTP, HTTPS
- 🛡️ Set up daily DB backups with cron
- 📊 Use Monit or Netdata for health checks
- 🚀 Explore CI/CD to auto-deploy from GitHub (next blog!)
✅ Final Checklist
- Laravel project is cloned
- Environment variables are set
- PHP, MySQL, Nginx are running
- SSL is configured
- Queue worker and cron are running
- Everything runs on your domain — secure, stable, and scalable
🧠 Key Takeaways
- VPS gives you full control — performance, security, and flexibility
- It’s a learning curve, but one that makes you a full-stack Laravel operator
- You now understand what happens after the code is written
👨💻 You’re No Longer Just a Developer
You’re now managing infrastructure, thinking like a tech lead, and owning your deployment pipeline.
This is how SaaS builders, founders, and senior architects operate. You’re on the path now 🚀
📘 What’s Next?
Stay tuned for the next blog:
🔁 Laravel CI/CD with GitHub Actions: Auto Deploy Your App from Push to Production
Want a ready-made deployment bash script? Or a YouTube tutorial version of this blog?
Just let me know!
Happy shipping 🧑🚀✨
Projects to explore next
Source-code projects from the KritiMyantra catalogue. Check each project's details before buying.
Flask Authentication System (Free Version) - Kritim Yantra
🛠 Features✔ Google & GitHub Authentication✔ User Registration & Login✔ Profile/Dashboard Access✔ Secure & Mi...
Flask Blog CMS with Admin Dashboard — Python Source Code
A Flask-based blogging website with a built-in admin dashboard. Manage articles, images, categories, tags and featured p...
Laravel 12 + ReactJS Starter Kit: Add Multi-Language Support (Arabic, English, Spanish) with Blog CRUD
🚀 Installation & Setup Download & Extract Get the ZIP from kritimyantra.com and extract it. Includes preconfigu...
Comments
No comments yet. Be the first to comment.
Sign in to join the discussion.