Kritim Yantra
Jun 21, 2025
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.
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.
Here are great options:
β‘οΈ Choose Ubuntu 22.04 with at least 1GB RAM (2GB preferred).
Once the server is ready, you'll get an IP like 157.230.55.123
.
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
Install Nginx, PHP, MySQL, and necessary tools.
sudo apt update && sudo apt upgrade -y
sudo apt install php php-cli php-fpm php-mysql php-mbstring php-xml php-curl php-zip unzip curl git -y
sudo apt install nginx -y
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;
Use Git or upload manually (SFTP).
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
Create .env
file and update:
cp .env.example .env
Update DB info:
DB_DATABASE=laravel_app
DB_USERNAME=laravel_user
DB_PASSWORD=securePassword
composer install
php artisan key:generate
php artisan migrate
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
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
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:*
crontab -e
Add:
* * * * * cd /var/www/laravel-app && php artisan schedule:run >> /dev/null 2>&1
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 π
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 π§βπβ¨
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google