Tutorial ini dibuat sebagai salah satu rincian instalasi Nginx + Php-FPM + MariaDB yang dipergunakan untuk menjalankan blog ini, dengan memakai vps Ubuntu 18 64bit DigitalOcean
Instalasi package yang umum :
1 2 |
$ apt-get update && apt-get upgrade $ apt-get install ncdu htop nethogs proftpd supervisor iftop tinc git squid3 autoconf automake zip unzip unrar python-pip python-m2crypto redis-server |
Konfigurasi swap
1 2 3 |
$ dd if=/dev/zero of=/swap bs=1024 count=1048576 $ mkswap /swap $ chmod 0600 /swap |
SesuaikanĀ /etc/fstab seperti contoh berikut :
1 |
/swap swap swap defaults,noatime 0 0 |
Aktifkan swap dengan perintah swapon -a, atau restart vps
Instalasi Nginx
1 |
$ apt-get install nginx |
Instalasi Php7.2-FPM
1 |
$ apt install php-fpm php-mysql php php-fpm php-common php-mysql php-gd |
Instalasi MariaDB
1 2 |
$ apt-get install mariadb-server mariadb-client $ mysql_secure_installation |
Instalasi NodeJS dan NPM
1 2 |
$ apt-get install nodejs $ apt-get install npm |
Instalasi MongoDB
1 |
$ apt install -y mongodb |
Menambahkan user untuk website dan home direktori
1 2 3 4 5 6 7 8 9 10 11 12 |
$ adduser webhost Menambahkan user www-data ke webhost agar permission website normal : $ gpasswd -a www-data webhost Membuat direktori untuk website $ mkdir -p /home/webhost/http/hosts $ mkdir -p /home/webhost/http/logs $ cd /home/webhost/http/hosts/ $ chown -R www-data:webhost namadomain.com/ $ chown -R www-data:webhost namadomain.com/* |
Membuat file /etc/rc.local
1 2 |
$ printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local $ chmod +x /etc/rc.local |
Instalasi composer
1 2 3 |
$ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer $ chmod +x /usr/local/bin/composer |
Membuat Database
1 2 3 4 5 6 7 8 |
$ mysql -u root -p Isikan password... mysql> create database namaDatabase; mysql> grant usage on *.* to namaUser@localhost identified by 'P4sswordDBUser'; mysql> grant all privileges on namaDatabase.* to namaUser@localhost; mysql> flush privileges; mysql> exit; |
Perintah untuk backup atau dump database
1 |
$ mysqldump -q --skip-lock-tables -u namaUser --password=P4sswordDBUser namaDatabase > backup.sql |
Perintah untuk import database
1 |
$ mysql -u namaUser --password=P4sswordDBUser namaDatabase < backup.sql |
Instalasi Ghost-cli
1 2 3 4 5 6 7 8 9 10 11 |
$ npm install ghost-cli -g $ su webhost $ mkdir /home/webhost/http/hosts/ghost-domain.org $ cd /home/webhost/http/hosts/ghost-domain.org $ ghost install local Untuk menjalankan ghost : $ ghost start Untuk menghentikan ghost : $ ghost stop |
Instalasi OpenVPN
1 2 |
$ wget https://git.io/vpn -O openvpn-install.sh $ bash openvpn-install.sh |
Membuka port di firewall
1 2 3 4 5 6 7 8 |
$ ufw allow 80 $ ufw allow 443 $ ufw allow 1194/udp Jika kita merubah port ssh ke port 5678 , jangan lupa untuk membuka portnya $ ufw allow 5678 $ ufw reload |
Merubah port listen Php7.2-FPM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ nano /etc/php/7.2/fpm/pool.d/www.conf ... listen = /run/php/php7.2-fpm.sock ; comment baris diatas dan ganti ke 127.0.0.1:9000 ... Sehingga menjadi seperti dibawah $ nano /etc/php/7.2/fpm/pool.d/www.conf ... ; listen = /run/php/php7.2-fpm.sock listen = 127.0.0.1:9000 ... $ service php7.2-fpm restart |
Membuat file konfigurasi untuk domain yang dihost di vps :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
$ nano /etc/nginx/sites-enabled/erawanarifnugroho.com.conf #-- First bite config -- fastcgi_cache_path /etc/nginx-cache levels=1:2 keys_zone=phpcache:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; server { listen 80; server_name erawanarifnugroho.com www.erawanarifnugroho.com; return 301 https://$host$request_uri; } server { #-- Module first byte -- fastcgi_cache phpcache; fastcgi_cache_valid 200 30m; fastcgi_cache_methods GET HEAD; add_header X-FastCache $upstream_cache_status; server_name erawanarifnugroho.com www.erawanarifnugroho.com; index index.htm index.html index.php; root /home/webhost/http/hosts/erawanarifnugroho.com; try_files $uri $uri/ /index.php; client_max_body_size 2000M; error_log /home/webhost/http/logs/erawanarifnugroho.com_error.log; access_log /home/webhost/http/logs/erawanarifnugroho.com_access.log; location ~ \.php$ { gzip_vary on; try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With port: # fastcgi_pass 127.0.0.1:9000; # With socket: fastcgi_pass unix:/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #Untuk keperluan Letsencrypt location ~ /.well-known { allow all; } # Deny access to .htaccess location ~ /\.ht { deny all; } # ------------------------------------------------------------------------------------------------------------------------ # --- Fungsi caching dari Hummingbird --- gzip on; gzip_comp_level 9; gzip_http_version 1.1; gzip_proxied any; gzip_min_length 1100; gzip_buffers 16 8k; gzip_vary on; gzip_types # text/html is always compressed by HttpGzipModule text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/font.woff application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; # Disable for IE < 6 because there are some known problems gzip_disable "MSIE [1-6].(?!.*SV1)"; location ~* \.(txt|xml|js)$ { expires 8d; } location ~* \.(css)$ { expires 8d; } location ~* \.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac|eot|ttf|otf|woff|svg)$ { expires 8d; } location ~* \.(jpg|jpeg|png|gif|swf|webp)$ { expires 8d; } # --- Fungsi caching dari Hummingbird --- # ------------------------------------------------------------------------------------------------------------------------ } |
Instalasi Letsencrypt untuk domain
1 2 3 |
$ apt install certbot $ apt-get install python-certbot-nginx $ certbot --nginx -d erawanarifnugroho.com -d www.erawanarifnugroho.com |