Panduan Lengkap Membuat Server Web di Ubuntu: Nginx + PHP + MySQL untuk Pemula

Membangun server web sendiri di Ubuntu itu tidak sulit. Dengan kombinasi Nginx, PHP, dan MySQL, kamu sudah bisa menjalankan website WordPress, Laravel, Moodle, atau aplikasi lainnya. Artikel ini membahas langkah lengkap yang mudah dipahami pemula.


1. Update Sistem

Selalu mulai dengan update:

sudo apt update && sudo apt upgrade -y

2. Install Nginx

Nginx adalah web server yang cepat dan ringan.

Install:

sudo apt install nginx -y

Cek status:

systemctl status nginx

Buka IP server di browser → jika muncul halaman “Welcome to Nginx”, berarti berhasil.


3. Install MySQL / MariaDB

Install database server:

sudo apt install mariadb-server -y

Amankan instalasi:

sudo mysql_secure_installation

Masukkan password root, hapus user anonim, dan disable remote root.


4. Install PHP + Extensions

Install PHP 8.x dan modul penting:

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

Cek versi:

php -v

5. Konfigurasi PHP-FPM

Pastikan PHP-FPM berjalan:

systemctl status php8.1-fpm

(versi bisa berbeda)


6. Konfigurasi Nginx untuk Website PHP

Buat file konfigurasi:

sudo nano /etc/nginx/sites-available/mywebsite

Isi:

server {
    listen 80;
    server_name _;
    root /var/www/mywebsite;

    index index.php index.html;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Aktifkan site:

sudo ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

7. Buat Folder Website

sudo mkdir -p /var/www/mywebsite
sudo chown -R $USER:$USER /var/www/mywebsite

Buat file tes PHP:

nano /var/www/mywebsite/info.php

Isi:

<?php phpinfo(); ?>

Buka:
http://IP-SERVER/info.php

Jika muncul halaman PHP Info → konfigurasi sukses.


8. Cara Membuat Database Baru

Masuk MySQL:

sudo mysql

Buat database dan user:

CREATE DATABASE webdb;
CREATE USER 'eko'@'localhost' IDENTIFIED BY 'passwordku';
GRANT ALL PRIVILEGES ON webdb.* TO 'eko'@'localhost';
FLUSH PRIVILEGES;

9. Install Website (Contoh: WordPress)

Download:

cd /var/www/mywebsite
wget https://wordpress.org/latest.zip
unzip latest.zip
mv wordpress/* .
rm -r wordpress

Set permission:

sudo chown -R www-data:www-data /var/www/mywebsite
sudo chmod -R 755 /var/www/mywebsite

Lalu buka website di browser → lanjutkan instalasi WordPress.


10. Aktifkan HTTPS (SSL) dengan Certbot

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx

Ikuti instruksi → SSL aktif otomatis.


Penutup

Dengan langkah di atas, kamu sudah bisa membuat server web lengkap menggunakan Ubuntu, Nginx, PHP, dan MySQL. Konfigurasi ini bisa digunakan untuk WordPress, Laravel, Moodle, dan aplikasi web lainnya. Server buatan sendiri jauh lebih fleksibel dan mudah dikembangkan.

Leave a Comment