Laravel on VPS: The Ultimate Deployment & Configuration Guide for Senior Developers

Author

Kritim Yantra

Jun 21, 2025

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 πŸ§‘β€πŸš€βœ¨

Ajay Yadav

Ajay Yadav

Senior Full-Stack Engineer

7 + Years Experience

Transforming Ideas Into Digital Solutions

I architect and build high-performance web applications with modern tech:

Laravel PHP 8+ Vue.js React.js Flask Python MySQL

Response time: under 24 hours β€’ 100% confidential

Comments

No comments yet. Be the first to comment!

Please log in to post a comment:

Sign in with Google

Related Posts