Cara Install WordPress dengan Nginx di FreeBSD
Tutorial FreeBSD server kali ini, kita akan belajar bagaimana cara install WordPress dengan menggunakan Nginx web server disertai SSL dari Let’s Encrypt untuk protokol HTTPS.
Perangkat yang digunakan
Perangkat yang digunakan di tutorial ini:
- VPS FreeBSD 12.1 di Vultr
- Domain musaamin.my.id
- IP 207.148.123.152
- Nginx
- PHP 7.4
- MariaDB 10.5
- Let’s Encrypt
- WordPress
Install Nginx
Install Nginx web server.
1 | pkg install nginx |
Aktifkan service nginx.
1 | sysrc nginx_enable="YES" |
Jalankan service nginx.
1 | service nginx start |
Browse http://serverIP untuk menguji apakah Nginx web server sudah berjalan dengan baik.
Konfigurasi Server Block
Selanjutnya mengkonfigurasi Nginx server block untuk domain musaamin.my.id.
Membuat folder untuk document root.
1 2 | mkdir -p /var/www/musaamin.my.id echo "hello world" > /var/www/musaamin.my.id/index.html |
Membuat folder untuk menyimpan file konfigurasi server block.
1 | mkdir -p /usr/local/etc/nginx/vhosts |
Membuat file konfigurasi server block.
1 | nano /usr/local/etc/nginx/vhosts/musaamin.my.id.conf |
Isi file konfigurasi server block.
1 2 3 4 5 6 7 8 9 10 11 12 13 | server { listen 80; server_name musaamin.my.id www.musaamin.my.id; root /var/www/musaamin.my.id; index index.html; location / { try_files $uri $uri/ =404; } access_log /var/log/nginx/musaamin.my.id_access.log; error_log /var/log/nginx/musaamin.my.id_error.log; } |
Buka file konfigurasi Nginx.
1 | nano /usr/local/etc/nginx/nginx.conf |
Tambahkan konfigurasi di bawah ini sebelum penutup http.
1 2 3 4 | http { ... include /usr/local/etc/nginx/vhosts/*.conf; } |
Cek apakah ada kesalahan konfigurasi.
1 | nginx -t |
Jika tidak ada kesalahan.
1 2 | nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful |
Restart service nginx.
1 | service nginx restart |
Browse http://musaamin.my.id.
Install PHP
Install PHP 7.4 dan extensionnya.
1 | pkg install php74 php74-mysqli php74-mbstring php74-pecl-mcrypt php74-zlib php74-curl php74-opcache php74-xml php74-xmlrpc php74-gd php74-json php74-zip |
Buka file konfigurasi PHP-FPM.
1 | nano /usr/local/etc/php-fpm.d/www.conf |
Aktifkan dan sesuaikan konfigurasi berikut.
1 2 3 4 | listen = /var/run/php74.sock listen.owner = www listen.group = www listen.mode = 0660 |
Buat file php.ini
1 2 | cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini-production.default ln -s /usr/local/etc/php.ini-production /usr/local/etc/php.ini |
Buka file php.ini.
1 | nano /usr/local/etc/php.ini |
Opsi yang diaktifkan dan diubah.
1 | cgi.fix_pathinfo=0 |
Aktifkan dan jalankan service php-fpm.
1 2 | sysrc php_fpm_enable="YES" service php-fpm start |
Konfigurasi server block untuk membaca script PHP.
1 | nano /usr/local/etc/nginx/vhosts/musaamin.my.id.conf |
Ubah konfigurasinya menjadi seperti di bawah ini.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | server { listen 80; server_name musaamin.my.id www.musaamin.my.id; root /var/www/musaamin.my.id; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $fastcgi_script_name =404; include fastcgi_params; fastcgi_pass unix:/var/run/php74.sock; fastcgi_index index.php; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; } access_log /var/log/nginx/musaamin.my.id_access.log; error_log /var/log/nginx/musaamin.my.id_error.log; } |
Tes konfigurasi Nginx.
1 | nginx -t |
Restart nginx.
1 | service nginx restart |
Buat file info.php.
1 | echo "<?php phpinfo(); ?>" > /var/www/musaamin.my.id/info.php |
Browse http://musaamin.my.id/info.php
Install SSL Let’s Encrypt
Install certbot Let’s Encrypt untuk Nginx.
1 | pkg install py37-certbot-nginx |
Request SSL untuk domain musaamin.my.id.
1 | certbot --nginx -d musaamin.my.id -d www.musaamin.my.id |
Jika berhasil, certbot mengubah file konfigurasi server block.
1 | nano /usr/local/etc/nginx/vhosts/musaamin.my.id.conf |
Isinya.
1 2 3 4 5 6 7 | ... listen 443 ssl; # managed by Certbot ssl_certificate /usr/local/etc/letsencrypt/live/musaamin.my.id/fullchain.pem; # managed by Certbot ssl_certificate_key /usr/local/etc/letsencrypt/live/musaamin.my.id/privkey.pem; # managed by Certbot include /usr/local/etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /usr/local/etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot ... |
Browse https://musaamin.my.id.
Install MariaDB
Install MariaDB database.
1 | pkg install mariadb105-server mariadb105-client |
Aktifkan dan jalankan service MariaDB.
1 2 | sysrc mysql_enable="YES" service mysql-server start |
Amankan instalasi MariaDB.
1 | mysql_secure_installation |
Jawab pertanyaannya.
1 2 3 4 5 6 7 | Enter current password for root (enter for none): ENTER Switch to unix_socket authentication [Y/n] y Change the root password? [Y/n] y Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y |
Login MariaDB
1 | mysql |
Buat database untuk WordPress.
1 2 3 4 5 | CREATE DATABASE musaamin; CREATE USER 'musaamin'@localhost IDENTIFIED BY 'rahasia'; GRANT ALL PRIVILEGES ON musaamin.* TO 'musaamin'@'localhost'; FLUSH PRIVILEGES; exit |
Install WordPress
Download WordPress terbaru.
1 | wget https://wordpress.org/latest.tar.gz -O wordpress.tar.gz |
Ekstrak wordpress.tar.gz
1 | tar xzvf wordpress.tar.gz |
Copy isi folder wordpress ke document root.
1 | cp -Rfv wordpress/* /var/www/musaamin.my.id |
Ubah ownership.
1 | chown -R www:www /var/www/musaamin.my.id |
Hapus file index.html dan info.php yang dibuat sebelumnya.
1 2 | rm -f /var/www/musaamin.my.id/info.php rm -f /var/www/musaamin.my.id/index.html |
Browse https://musaamin.my.id untuk install WordPress.
- Continue
- Let’s go!
- Masukkan nama database, username, dan password yang telah dibuat di MariaDB. Untuk Database Host = 127.0.0.1. Submit
- Run the installation
- Masukkan site title, username, password, dan email. Install WordPress.
WordPress telah selesai diinstall.
Cek https://musaamin.my.id dan login ke dashboard.
Gratis saldo $100 untuk pendaftaran akun baru di Vultr. Daftar sekarang
Selamat mencoba 🙂