LEMP Stack merupakan kombinasi perangkat lunak yang memungkinkan Anda menyajikan halaman website dinamis dan web aplikasi modern. Panduan ini khusus untuk Ubuntu 22.04 LTS dengan versi software terbaru tahun 2025.
Update 2025: Tutorial ini telah diperbarui dengan PHP 8.3, Nginx terbaru, MariaDB 10.11, dan security best practices untuk Ubuntu 22.04 LTS.
Apa itu LEMP Stack?
LEMP merupakan singkatan dari Linux OS, dengan (E)Nginx sebagai web servernya, basis data menggunakan MySQL atau MariaDB, dan diperuntukkan untuk website yang menggunakan bahasa pemrograman PHP.
Komponen LEMP Stack (Ubuntu 22.04 LTS):
- Linux: Ubuntu 22.04 LTS (Jammy Jellyfish)
- Nginx: Web server performa tinggi
- MariaDB: Database server yang kompatibel dengan MySQL
- PHP 8.3: Scripting language terbaru dengan performa optimal
Jika diperhatikan dengan seksama huruf depan masing-masing software di atas yang ditandai dengan bold membentuk singkatan LEMP.
Dengan menginstall LEMP Stack ini, Anda dapat menjalankan:
- WordPress - CMS paling populer di dunia
- Laravel - PHP framework modern untuk web aplikasi
- Drupal, Joomla - CMS lainnya
- Custom PHP Applications - Aplikasi PHP buatan sendiri
Prerequisites
Sebelum mengikuti tutorial ini, pastikan Anda sudah:
✅ Server Ubuntu 22.04 LTS yang sudah di-setup dengan benar
✅ User non-root dengan akses sudo privileges
✅ UFW Firewall yang sudah dikonfigurasi
✅ SSH key authentication (recommended)
Jika belum, ikuti tutorial Langkah pertama setup server di Ubuntu 22.04.
🚀 Ingin setup LEMP Stack tanpa ribet? Kami menyediakan jasa setting VPS dengan LEMP Stack yang sudah dioptimasi, security hardening, dan monitoring untuk performa maksimal server Anda.
Step 1: Update Sistem Ubuntu 22.04
Sebelum menginstall LEMP Stack, pastikan sistem Ubuntu 22.04 Anda ter-update:
sudo apt update && sudo apt upgrade -yInstall package pendukung yang diperlukan:
sudo apt install curl wget gnupg2 software-properties-common apt-transport-https -yStep 2: Install Nginx (Web Server)
Nginx merupakan web server open source performa tinggi yang digunakan oleh 400+ juta website dan 67% dari 10 ribu top website dunia.
Install Nginx:
sudo apt update
sudo apt install nginx -yStart dan enable Nginx:
sudo systemctl start nginx
sudo systemctl enable nginxCek status Nginx:
sudo systemctl status nginxOutput yang diharapkan:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running)Test Nginx di Browser:
Untuk memastikan Nginx berjalan dengan baik, akses IP server melalui web browser:
# Cek IP publik server
curl ifconfig.coKemudian buka di web browser:
# Buka di browser
http://YOUR_SERVER_IPJika berhasil, Anda akan melihat halaman “Welcome to nginx!”.
Konfigurasi UFW Firewall:
Jika menggunakan UFW firewall, izinkan traffic Nginx:
# Cek status UFW
sudo ufw status
# Allow Nginx HTTP dan HTTPS
sudo ufw allow 'Nginx Full'
# Atau secara manual
sudo ufw allow 80/tcp
sudo ufw allow 443/tcpVerifikasi rules firewall:
sudo ufw status verboseStep 3: Install MariaDB (Database Server)
MariaDB adalah database server open source yang kompatibel dengan MySQL dan lebih performant. Ubuntu 22.04 menyediakan MariaDB 10.6+ yang stabil.
Install MariaDB:
sudo apt install mariadb-server mariadb-client -yStart dan enable MariaDB:
sudo systemctl start mariadb
sudo systemctl enable mariadbCek status MariaDB:
sudo systemctl status mariadbSecure MariaDB Installation:
Jalankan script keamanan untuk memperkuat konfigurasi MariaDB:
sudo mysql_secure_installationIkuti panduan interaktif:
- Enter current password for root: Tekan Enter (password kosong)
- Set root password: Ketik
Ydan buat password yang kuat - Remove anonymous users: Ketik
Y - Disallow root login remotely: Ketik
Y(recommended) - Remove test database: Ketik
Y - Reload privilege tables: Ketik
Y
Test Koneksi MariaDB:
sudo mysql -u root -pJika berhasil, Anda akan masuk ke MariaDB shell:
MariaDB [(none)]> SHOW DATABASES;
MariaDB [(none)]> EXIT;Step 4: Install PHP 8.3 (Scripting Language)
PHP 8.3 adalah versi terbaru dengan peningkatan performa signifikan dan fitur baru. Untuk Ubuntu 22.04, kita akan menggunakan repository Ondrej Sury untuk mendapatkan PHP 8.3.
Tambah Repository PHP 8.3:
# Add repository Ondrej Sury untuk PHP terbaru
sudo add-apt-repository ppa:ondrej/php -y
sudo apt updateInstall PHP 8.3 dan Extensions:
sudo apt install php8.3-fpm php8.3-cli php8.3-common -yInstall PHP Extensions untuk Web Development:
sudo apt install php8.3-{mysql,curl,gd,intl,mbstring,soap,xml,xmlrpc,zip,bcmath,opcache,readline,json} -yExtensions yang diinstall:
php8.3-mysql: Koneksi ke MariaDB/MySQLphp8.3-curl: HTTP requestsphp8.3-gd: Image processingphp8.3-intl: Internationalizationphp8.3-mbstring: Multibyte string handlingphp8.3-xml: XML processingphp8.3-zip: Archive handlingphp8.3-opcache: Performance optimization
Start dan Enable PHP-FPM:
sudo systemctl start php8.3-fpm
sudo systemctl enable php8.3-fpmCek Status PHP-FPM:
sudo systemctl status php8.3-fpmVerifikasi Versi PHP:
php -vOutput yang diharapkan:
PHP 8.3.x (cli) (built: ...) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.x, Copyright (c) Zend Technologies
with Zend OPcache v8.3.x, Copyright (c), by Zend TechnologiesStep 5: Konfigurasi Nginx Server Block
Server block Nginx mirip dengan virtual host di Apache. Kita akan membuat konfigurasi baru yang optimized untuk PHP 8.3.
Buat Direktori untuk Website:
sudo mkdir -p /var/www/html
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/htmlBuat Konfigurasi Nginx yang Dioptimasi:
sudo nano /etc/nginx/sites-available/defaultGanti seluruh isi file dengan konfigurasi berikut:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# PHP processing dengan PHP 8.3-FPM
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Cache static files
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 1M;
add_header Cache-Control "public, immutable";
}
# Security: deny access to hidden files
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
# Security: deny access to backup files
location ~ ~$ {
access_log off;
log_not_found off;
deny all;
}
}Test Konfigurasi Nginx:
sudo nginx -tOutput yang diharapkan:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulRestart Nginx:
sudo systemctl reload nginxStep 6: Test LEMP Stack
Sekarang semua komponen LEMP Stack sudah terinstall: Nginx, MariaDB, dan PHP 8.3. Mari kita test apakah semuanya bekerja dengan baik.
Buat File Test PHP:
sudo nano /var/www/html/info.phpTambahkan script PHP berikut:
<?php
phpinfo();Buat Simple HTML Test:
sudo nano /var/www/html/index.htmlTambahkan HTML berikut:
<!DOCTYPE html>
<html>
<head>
<title>LEMP Stack Ubuntu 22.04 - Works!</title>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
.container { max-width: 600px; margin: 0 auto; text-align: center; }
.success { color: #28a745; }
.info { background: #f8f9fa; padding: 20px; border-radius: 5px; }
</style>
</head>
<body>
<div class="container">
<h1 class="success">✅ LEMP Stack Berhasil Terinstall!</h1>
<div class="info">
<h3>Komponen Yang Terinstall:</h3>
<p><strong>Linux:</strong> Ubuntu 22.04 LTS</p>
<p><strong>Nginx:</strong> Web Server</p>
<p><strong>MariaDB:</strong> Database Server</p>
<p><strong>PHP:</strong> 8.3 (Latest)</p>
</div>
<p><a href="/info.php">🔍 Lihat PHP Info</a></p>
</div>
</body>
</html>Set Permissions:
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 644 /var/www/html/Test di Browser:
- Test HTML: Buka
http://YOUR_SERVER_IP/di browser - Test PHP: Buka
http://YOUR_SERVER_IP/info.phpdi browser
Jika berhasil, Anda akan melihat:
- Halaman HTML dengan pesan sukses
- Halaman PHP Info menampilkan informasi PHP 8.3 lengkap
Hapus File Test (Security):
Setelah testing selesai, hapus file info.php untuk keamanan:
sudo rm /var/www/html/info.phpStep 7: Optimasi PHP 8.3 untuk Performa
Konfigurasi default PHP 8.3 dapat dioptimasi untuk performa yang lebih baik, terutama untuk production environment.
Edit Konfigurasi PHP 8.3:
sudo nano /etc/php/8.3/fpm/conf.d/99-custom.iniTambahkan konfigurasi optimasi berikut:
; ==============================================================================
; PHP 8.3 Performance Optimization for Ubuntu 22.04
; ==============================================================================
; Memory Management
memory_limit = 512M
max_execution_time = 60
max_input_time = 60
; File Uploads
upload_max_filesize = 64M
post_max_size = 64M
max_file_uploads = 20
; Error Reporting (Production)
display_errors = Off
log_errors = On
error_log = /var/log/php8.3-fpm.log
; Session Management
session.gc_maxlifetime = 3600
session.gc_probability = 1
session.gc_divisor = 1000
; OPcache Configuration (Sangat Penting untuk Performa)
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 64
opcache.max_accelerated_files = 10000
opcache.max_wasted_percentage = 5
opcache.use_cwd = 1
opcache.validate_timestamps = 0
opcache.revalidate_freq = 0
opcache.save_comments = 0
opcache.fast_shutdown = 1
; Realpath Cache (Meningkatkan performa file system)
realpath_cache_size = 64M
realpath_cache_ttl = 600Optimasi PHP-FPM Pool:
sudo nano /etc/php/8.3/fpm/pool.d/www.confCari dan ubah pengaturan berikut:
; Process Management
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 1000
; Performance Tuning
request_terminate_timeout = 60s
rlimit_files = 65536
rlimit_core = unlimited
; Security
security.limit_extensions = .php .php3 .php4 .php5 .php7 .php8Restart PHP-FPM:
sudo systemctl restart php8.3-fpm
sudo systemctl status php8.3-fpmVerifikasi OPcache:
Buat file test untuk memverifikasi OPcache:
sudo nano /var/www/html/opcache-test.php<?php
echo "<h2>OPcache Status</h2>";
if (function_exists('opcache_get_status')) {
$status = opcache_get_status();
echo "<p><strong>OPcache Enabled:</strong> " . ($status ? 'Yes' : 'No') . "</p>";
if ($status) {
echo "<p><strong>Memory Usage:</strong> " . round($status['memory_usage']['used_memory'] / 1024 / 1024, 2) . " MB</p>";
echo "<p><strong>Cached Scripts:</strong> " . $status['opcache_statistics']['num_cached_scripts'] . "</p>";
echo "<p><strong>Hit Rate:</strong> " . round($status['opcache_statistics']['opcache_hit_rate'], 2) . "%</p>";
}
} else {
echo "<p>OPcache not available</p>";
}
echo "<h2>PHP Configuration</h2>";
echo "<p><strong>PHP Version:</strong> " . PHP_VERSION . "</p>";
echo "<p><strong>Memory Limit:</strong> " . ini_get('memory_limit') . "</p>";
echo "<p><strong>Max Execution Time:</strong> " . ini_get('max_execution_time') . " seconds</p>";
echo "<p><strong>Upload Max Filesize:</strong> " . ini_get('upload_max_filesize') . "</p>";
?>
Buka http://YOUR_SERVER_IP/opcache-test.php untuk melihat status OPcache.
Hapus file test setelah verifikasi:
sudo rm /var/www/html/opcache-test.phpKesimpulan
Selamat! Anda telah berhasil menginstall LEMP Stack lengkap di Ubuntu 22.04 LTS dengan komponen terbaru:
✅ Nginx - Web server performa tinggi
✅ MariaDB 10.6+ - Database server yang robust
✅ PHP 8.3 - Scripting language dengan performa optimal
✅ Security Hardening - Konfigurasi keamanan yang proper
✅ Performance Optimization - Tuning untuk performa maksimal
Apa Selanjutnya?
Sekarang server Ubuntu 22.04 Anda siap untuk:
1. Install CMS Populer:
- Install WordPress dengan LEMP Stack
- Install Drupal atau Joomla
2. Deploy Framework Modern:
- Laravel 10.x untuk web aplikasi
- CodeIgniter 4 untuk rapid development
- Symfony untuk enterprise applications
3. Setup SSL Certificate:
- Konfigurasi Let’s Encrypt untuk HTTPS
- Implementasi HTTP/2 untuk performa
4. Monitoring & Maintenance:
- Setup log monitoring
- Backup otomatis database
- Update security rutin
Performance Benchmarks
Dengan konfigurasi ini, Anda dapat mengharapkan:
- PHP 8.3: 10-30% lebih cepat dari PHP 8.1
- OPcache: Mengurangi response time hingga 50%
- Nginx: Dapat handle 10,000+ concurrent connections
- MariaDB: Query performance yang optimal
Security Best Practices yang Sudah Diterapkan
✅ PHP Security Headers - XSS, CSRF, dan clickjacking protection
✅ File Permission - Proper ownership dan permissions
✅ Database Security - Secured MariaDB installation
✅ Nginx Security - Hidden files dan backup protection
✅ UFW Firewall - Network access control
Referensi
- How to Install LEMP Stack on Ubuntu 22.04 - LinuxBabe
- Nginx Configuration Best Practices - Official Nginx Documentation
- PHP 8.3 New Features - Official PHP Documentation
- MariaDB Performance Tuning - MariaDB Knowledge Base
- Ubuntu 22.04 Server Guide - Official Ubuntu Documentation
Tags: LEMP Stack, Ubuntu 22.04, Nginx, MariaDB, PHP 8.3, Web Server, Linux Server Setup
Semoga tutorial ini bermanfaat! Jangan lupa share jika artikel ini membantu setup server Anda. 🚀
About The Author
Gege Riyadi
Founder Gegeriyadi.com, layanan yang sudah 10 tahun bergerak di bidang Web Development & WordPress Security Services yang juga intens update seputar SEO dan juga Web Optimization... [Read full bio]