Tutorial Cara Install LEMP Stack di Server OS Debian 10

Tutorial Cara Install LEMP Stack di Server OS Debian 10

Stacks bisa membantu kamu mempermudah pengelolaan website. Ada dua jenis stacks yang bisa kamu gunakan sesuai OS dan web server yang digunakan, yaitu LEMP Stack untuk web server Nginx dan LAMP Stack jika kamu menggunakan Apache sebagai web server. Di artikel kali ini, kamu akan mempelajari cara install LEMP Stack di VPS untuk OS Debian 10.

LEMP Stack

LEMP (Linux, Nginx, MariaDB, PHP) Stack adalah salah satu stack yang diciptakan untuk memenuhi kebutuhan dalam melakukan deployment website ke server tanpa menggunakan control panel. Artinya, tidak ada Graphic User Interface (GUI) yang bisa menampilkan aplikasi untuk mengelola website, melainkan hanya menggunakan command atau perintah LEMP Stack.

Baca Juga: LAMP atau LEMP, Manakah yang Lebih Baik?

Cara Install LEMP Stack di Debian 10

Sebelum memulai cara install LEMP Stack di Debian 10, kamu perlu mempersiapkan beberapa hal berikut:

  • VPS dengan OS Debian 10.
  • Domain yang sudah diarahkan ke IP VPS.
  • Akses ke root sebagai Administrator.

Berikut ini adalah beberapa langkah utama yang akan kita lakukan dalam cara install LEMP Stack di Debian 10.

  • Update Server
  • Install Packages
  • Install Firewall
  • Install Nginx Web Server
  • Install MariaDB Database Server
  • Install PHP 7.2
  • Configure PHP.ini
  • Konfigurasi Virtual Host Nginx
  • Testing

Setelah itu, simak penjelasan langkah-langkahnya berikut ini.

Update Server

Login sebagai root ke server, kemudian perbarui server dan reboot.

$ apt-get update -y

$ reboot

 

Install Packages

Install beberapa packages yang dibutuhkan Debian 10.

$ apt-get install wget nano perl zip unzip gnupg2 -y

 

Install Firewall

Sebelum memulai instalasi LEMP Stack, kamu perlu meng-install firewall terlebih dulu agar lebih aman. Di artikel ini kami menggunakan CSF (ConfigServer Security & Firewall) sebagai firewall, simak cara instalasinya menggunakan perintah berikut:

$ cd /usr/src
$ wget https://download.configserver.com/csf.tgz
$ tar -xzf csf.tgz
$ cd csf/
$ sh install.sh

 

Ada sedikit perbedaan instalasi pada Debian 10, ikuti perintah di bawah ini.

Install packages libwww:

$ apt-get install libwww-perl -y

 

$ perl /usr/local/csf/bin/csftest.pl

 

Kemudian akan muncul output di bawah ini.

Testing ip_tables/iptable_filter...OK
Testing ipt_LOG...OK
Testing ipt_multiport/xt_multiport...OK
Testing ipt_REJECT...OK
Testing ipt_state/xt_state...OK
Testing ipt_limit/xt_limit...OK
Testing ipt_recent...OK
Testing xt_connlimit...OK
Testing ipt_owner/xt_owner...OK
Testing iptable_nat/ipt_REDIRECT...OK
Testing iptable_nat/ipt_DNAT...OK

RESULT: csf should function on this server


Nonaktifkan firewalld:

$ systemctl stop firewalld
$ systemctl disable firewalld

 

Pada konfigurasi CSF, ubah “make TESTING=’1’ menjadi 0”.

$ nano /etc/csf/csf.conf

 

Restart dan tes CSF:

$ systemctl restart {csf,lfd}
$ systemctl enable {csf,lfd}
$ systemctl is-active {csf,lfd}


Kemudian restart CSF agar dapat me-reload hasil konfigurasi yang sudah diperbarui.

$ csf -r 

 

Instal Nginx Web Server

Mengingat kita meng-install LEMP Stack di artikel ini, maka gunakan cara berikut untuk instalasi web server Nginx di Debian 10.

$ apt-get install nginx -y

 

Jika instalasinya sudah selesai, start dan enable Nginx on-boot.

$ systemctl enable nginx
$ systemctl start nginx

 

Cek apakah Nginx sudah berjalan atau belum:

$ systemctl status nginx
  • nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
   Active: active (running) since Wed 2021-02-24 08:03:57 UTC; 2min 35s ago
     Docs: man:nginx(8)
 Main PID: 2251 (nginx)
    Tasks: 2 (limit: 1149)
   Memory: 4.4M
   CGroup: /system.slice/nginx.service
           ├─2251 nginx: master process /usr/sbin/nginx -g daemon on; master_pro
           └─2252 nginx: worker process

 

Gunakan perintah berikut untuk mengecek versi Nginx:

$ nginx -v
nginx version: nginx/1.14.2

 

Versi yang kami install adalah 1.14.2 yang menjadi versi terbaru untuk saat ini, mungkin akan berbeda dengan versi yang kamu install nantinya.

Baca Juga: 5 Web Server Gratis Untuk Deployment Website

Install MariaDB Databse Server

Server database yang digunakan adalah MariaDB untuk menggantikan MySQL, karena MySQL sudah deprecated dan tidak up-to-date lagi.

$ apt-get install mariadb-server -y

 

Jika instalasinya sudah selesai, start dan enable MariaDB on-boot.

$ systemctl enable mariadb
$ systemctl start mariadb

 

Jangan lupa untuk mengecek status MariaDB, apakah sudah running atau belum.

$ systemctl status mariadb
  • mariadb.service - MariaDB 10.3.27 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: 
   Active: active (running) since Wed 2021-02-24 08:34:08 UTC; 4min 12s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 3854 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 31 (limit: 1149)
   Memory: 72.2M
   CGroup: /system.slice/mariadb.service
           └─3854 /usr/sbin/mysqld

Gunakan command di bawah ini untuk memulai inisialisasi setup MariaDB.

$ mysql_secure_installation

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...


All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

Install PHP 7.2

Di artikel ini, kami menggunakan PHP 7.2, ikuti instruksi berikut untuk meng-install.

Import dan tambahkan repositori SURY.

$ wget https://packages.sury.org/php/apt.gpg
$ apt-key add apt.gpg
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.list


Perbarui indeks repositori.

$ apt-get update -y 

 

Install PHP dengan perintah:

$ apt install php7.2 php7.2-cli php7.2-common php7.2-fpm -y 

 

Start dan enable PHP 7.2-FPM on-boot.

$ systemctl enable php7.2-fpm
$ systemctl start php7.2-fpm

 

Cek status php7.2-fpm apakah sudah aktif atau belum:

$ systemctl status php7.2-fpm
  • php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor prese
   Active: active (running) since Wed 2021-02-24 09:19:47 UTC; 1min 7s ago
     Docs: man:php-fpm7.2(8)
  Process: 14246 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/p
 Main PID: 14243 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/se
    Tasks: 3 (limit: 1149)
   Memory: 11.6M
   CGroup: /system.slice/php7.2-fpm.service
           ├─14243 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
           ├─14244 php-fpm: pool www
           └─14245 php-fpm: pool www

 

Configure PHP.ini

Buka file php.ini dan PHP-FPM configuration. Ubah config sesuai di bawah ini.

$ nano /etc/php/7.2/fpm/php.ini

;cgi.fix_pathinfo=1 menjadi cgi.fix_pathinfo=0

 

$ nano /etc/php/7.2/cli/php.ini

;cgi.fix_pathinfo=1 menjadi cgi.fix_pathinfo=0

 

Kemudian simpan lalu keluar.

 

Baca Juga: Cara Konfigurasi Virtual Host di Apache

Konfigurasi Virtual Host Nginx

Atur virtual host agar Nginx dapat menghubungkan domain ke server. Setelah itu buat file sesuai dengan nama domainmu, di sini kami menggunakan vps188.dewiweb.net.

$ nano /etc/nginx/sites-enabled/vps188.dewiweb.net

 

Tambahkan script di bawah ini:

server {
  listen 80;
  listen [::]:80;
  server_name vps188.dewiweb.net;
  root /var/www/html/;
  index index.php index.html index.htm index.nginx-debian.html;

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

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

 # A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;
  }

  # disable access to hidden files
  location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }
}

 

Jika sudah, simpan dan keluar, lalu sambungkan hasil config tersebut ke sites-available.

$ ln -s /etc/nginx/sites-enabled/vps188.dewiweb.net /etc/nginx/sites-available/vps188.dewiweb.net

 

Cek konfigurasi yang dilakukan, apakah ada syntax error atau tidak:

$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

 

Reload dan restart Nginx:

$ systemctl reload nginx
$ systemctl restart nginx

 

Buat fileinfo di direktori root domain.

$ cd /var/www/html/
$ nano index.php

 

Tambahkan script di bawah ini.

<?php
 phpinfo ();
?> 

 

Kemudian simpan dan keluar.

 

Testing

Cara install LEMP Stack di Debian 10 hampir selesai, sekarang kamu hanya perlu mengakses domain yang digunakan sebelumnya. Jika berhasil, maka akan tampilannya akan terlihat seperti berikut ini.

cara install lemp stack di debian 10 berhasil

Baca Juga: Rekomendasi Framework PHP Terbaik untuk Web Developer

Simpulan

Demikian tutorial cara install LEMP Stack di Debian 10 ini. Jika kamu menggunakan OS lain, kamu juga bisa mengecek Cara Install LEMP Stack di CentOS 7 atau Cara Install LEMP Stack di Server dengan Ubuntu 18.04. Namun, apa pun OS kamu, pastikan kamu selalu menggunakan server VPS atau cloud hosting terbaik agar website-mu tak hanya cepat dan aman, tapi juga selalu bisa diandalkan, ya!

Jika ada pertanyaan, segera hubungi Ninja Support 24/7 di website utama Dewaweb. Jangan sungkan untuk meninggalkan ide-ide topik yang ingin kamu baca di blog Dewaweb, ya. Semoga artikel ini bermanfaat buat kamu, salam sukses online!