DevOps 2 min read 1,245 views

How to Deploy Laravel to Ubuntu Server with Nginx in 2026

Complete deployment guide for Laravel applications on Ubuntu with Nginx, SSL certificates, and performance optimization.

E
Server deployment

Prerequisites

  • Ubuntu 22.04+ server
  • Domain name pointing to server IP
  • SSH access to server

Step 1: Install Required Packages

sudo apt update && sudo apt upgrade -y
sudo apt install nginx mysql-server php8.3-fpm php8.3-mysql \
    php8.3-mbstring php8.3-xml php8.3-curl php8.3-zip \
    php8.3-bcmath php8.3-redis git composer -y

Step 2: Configure MySQL

sudo mysql_secure_installation

sudo mysql
CREATE DATABASE laravel_app;
CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL ON laravel_app.* TO 'laravel'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 3: Deploy Laravel Application

cd /var/www
sudo git clone https://github.com/your/repo.git laravel-app
cd laravel-app
sudo chown -R www-data:www-data .
sudo chmod -R 755 storage bootstrap/cache

composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache

Step 4: Configure Nginx

# /etc/nginx/sites-available/laravel
server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/laravel-app/public;

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

sudo ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 5: Install SSL with Certbot

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com
sudo systemctl reload nginx

Step 6: Set Up Queue Worker (Optional)

# /etc/supervisor/conf.d/laravel-worker.conf
[program:laravel-worker]
command=php /var/www/laravel-app/artisan queue:work
user=www-data
autostart=true
autorestart=true
numprocs=2

sudo supervisorctl reread
sudo supervisorctl update

Your Laravel application is now live!

Share this article:
ES

Written by Edrees Salih

Full-stack software engineer with 9 years of experience. Passionate about building scalable solutions and sharing knowledge with the developer community.

View Profile

Comments (0)

Leave a Comment

Your email will not be published.

No comments yet. Be the first to share your thoughts!