KodeJs
Cara Deploy Laravel 13 di VPS Linux Nginx & SSL Gratis
Laravel3 menit baca

Cara Deploy Laravel 13 di VPS Linux Nginx & SSL Gratis

Kembali ke Blog
Egi Samsul Mu'arifEgi Samsul Mu'arif10 September 20263 menit baca

Panduan lengkap deploy aplikasi Laravel 13 di VPS Ubuntu Linux menggunakan Nginx, MySQL, PHP 8.3/8.4, & SSL HTTPS Let's Encrypt gratis.

Mendeploy aplikasi Laravel 13 ke lingkungan produksi (production server) seperti VPS (Virtual Private Server) berbasis Linux sering kali menjadi tantangan tersendiri bagi pengembang web.

Berbeda dengan shared hosting biasa, penggunaan VPS Linux (Ubuntu) dengan web server Nginx memberikan kontrol penuh atas performa, keamanan, dan konfigurasi server.

Artikel ini membimbingmu melakukan deployment aplikasi Laravel 13 di VPS Ubuntu dari nol hingga siap diakses dengan protokol HTTPS (SSL Gratis).

Prasyarat & Arsitektur Server

Pastikan kamu sudah menyiapkan:

  1. VPS dengan sistem operasi Ubuntu 22.04 LTS atau 24.04 LTS.

  2. Domain yang sudah diarahkan (DNS A Record) ke IP Public VPS kamu.

┌─────────────────────────────────────────────────────────────────────────┐
│                    ARSISEKTUR DEPLOYMENT LARAVEL 13                     │
├────────────────────────────────┬────────────────────────────────────────┤
│ Komponen Server                │ Peran & Fungsi                         │
├────────────────────────────────┼────────────────────────────────────────┤
│ • Nginx                        │ Web Server & Reverse Proxy             │
│ • PHP-FPM (8.3/8.4)            │ FastCGI Process Manager untuk Laravel  │
│ • MySQL Database               │ Sistem Manajemen Basis Data            │
│ • Certbot (Let's Encrypt)      │ Sertifikat SSL HTTPS Gratis            │
└────────────────────────────────┴────────────────────────────────────────┘

1. Update Server & Install Dependency

Akses VPS kamu melalui SSH di terminal:

Bash

ssh root@ip_server_vps_kamu

Perbarui paket pustaka Ubuntu dan install Nginx, MySQL, Unzip, Git, serta modul PHP yang dibutuhkan Laravel 13:

Bash

sudo apt update && sudo apt upgrade -y

sudo apt install nginx mysql-server git unzip curl -y

sudo apt install php-fpm php-cli php-mysql php-mbstring php-xml php-bcmath php-curl php-zip -y

2. Install Composer

Unduh dan pasang Composer secara global di dalam VPS:

Bash

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

3. Clone Repository & Setup Project Laravel 13

Pindahkan direktori ke /var/www/ dan clone repositori aplikasi Laravel kamu dari GitHub/GitLab:

Bash

cd /var/www
sudo git clone https://github.com/username/repository-kamu.git laravel13-app
cd laravel13-app

# Install dependency pustaka PHP
composer install --optimize-autoloader --no-dev

# Salin konfigurasi .env
cp .env.example .env

Buka dan sesuaikan berkas .env (isi nama database, username, password, dan ubah APP_ENV=production serta APP_DEBUG=false):

Bash

nano .env

Jalankan perintah generate key, migrasi database, dan pembuatan symlink storage:

Bash

php artisan key:generate
php artisan migrate --force
php artisan storage:link
php artisan config:cache
php artisan route:cache
php artisan view:cache

Atur hak akses direktori agar Nginx (www-data) dapat menulis berkas storage dan cache:

Bash

sudo chown -R www-data:www-data /var/www/laravel13-app
sudo chmod -R 775 /var/www/laravel13-app/storage /var/www/laravel13-app/bootstrap/cache

4. Konfigurasi Web Server Nginx

Buat file konfigurasi Nginx baru untuk domain kamu:

Bash

sudo nano /etc/nginx/sites-available/domainkamu.com

Isi dengan konfigurasi standar Nginx khusus Laravel 13 berikut (sesuaikan nama domain dan versi PHP-FPM):

Nginx

server {
    listen 80;
    listen [::]:80;
    server_name domainkamu.com www.domainkamu.com;
    root /var/www/laravel13-app/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 = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

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

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

Aktifkan konfigurasi Nginx dan muat ulang layanannya:

Bash

sudo ln -s /etc/nginx/sites-available/domainkamu.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

5. Pasang Sertifikat SSL Gratis (Let's Encrypt Certbot)

Amankan koneksi website kamu dengan HTTPS menggunakan Certbot:

Bash

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d domainkamu.com -d www.domainkamu.com

Certbot akan secara otomatis memperbarui file konfigurasi Nginx untuk mengaktifkan sertifikat SSL dan melakukan pengalihan otomatis (auto-redirect) dari HTTP ke HTTPS.

Kesimpulan

Aplikasi Laravel 13 milikmu kini telah berhasil terpasang di VPS Linux menggunakan Nginx, MySQL, dan dilindungi sertifikat SSL HTTPS gratis dari Let's Encrypt. Dengan environment production yang terkonfigurasi dengan tepat, aplikasi dapat berjalan secara cepat, stabil, dan aman.


Egi Samsul Mu'arif

Ditulis oleh

Egi Samsul Mu'arif

Web & Mobile Developer

Artikel Terkait

Lihat semua