Server Deployment

  1. Download PuTTY https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
  2. Daftar VPS (via Private Cloud IDCloudHost)
    1. Daftar ke IDCloudHost Console (Bisa pake Login with Google) https://console.idcloudhost.com/hub/login
    2. Topup untuk bisa buat VPS Private Cloud (atau bisa apply free credit, informasi cek link paling bawah)
    3. Klik Compute lalu klik New
    4. Isi sesuai form
  3. Masuk ke Server
    1. Informasi SSH dapat diakses di bagian kiri, lalu di klik, akan muncul seperti ini
    2. Gunakan Public IP untuk dapat masuk ke server dengan menggunakan PuTTY
    3. Masukkan username dan password
    4. Masuk sebagai root sudo su
  4. Mengatur Firewall Referensi: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04
    1. ufw app list
    2. ufw allow OpenSSH
    3. ufw enable
    4. ufw status
  5. Install LEMP Referensi: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04
    1. Install Nginx
      1. sudo apt update
      2. sudo apt install nginx
      3. sudo ufw allow ‘Nginx HTTP’
      4. sudo ufw status
      5. Buka IP kamu, harusnya muncul seperti ini
    2. Install MySQL
      1. sudo apt install mysql-server
      2. sudo mysql_secure_installation
      3. Setting security sesuaikan dengan keinginan kalian
      4. Ganti ke metode password
        1. sudo mysql
        2. SELECT user,authentication_string,plugin,host FROM mysql.user;
        3. ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
        4. Nanti masuknya pake: mysql -u root -p
    3. Install PHP
      1. sudo apt install php-fpm php-mysql
    4. Tes PHP
      1. sudo nano /etc/nginx/sites-available/default
      2. Ubah ke: index index.php index.html index.htm index.nginx-debian.html;
      3. Tambahin lagi : location ~ \\.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; } location ~ /\\.ht { deny all; }
      4. sudo nano /var/www/html/info.php
      5. Isi code didalemnya <?php phpinfo();
      6. sudo nginx -t
      7. sudo systemctl reload nginx
      8. Buka URL http://IP_SERVER_ANDA/info.php
    5. Install Composer
      1. sudo apt update
      2. sudo apt install curl php-cli php-mbstring git unzip
      3. cd ~
      4. curl -sS https://getcomposer.org/installer -o composer-setup.php
      5. HASH=xxx Copy hash dari sini https://composer.github.io/pubkeys.html
      6. php -r “if (hash_file(‘SHA384’, ‘composer-setup.php’) === ‘$HASH’) { echo ‘Installer verified’; } else { echo ‘Installer corrupt’; unlink(‘composer-setup.php’); } echo PHP_EOL;”
      7. sudo php composer-setup.php –install-dir=/usr/local/bin –filename=composer
      8. composer
    6. Install modul PHP
      1. sudo apt update
      2. sudo apt install php-mbstring php-xml php-bcmath
  6. Buat Database
    1. mysql -u root -p
    2. CREATE DATABASE bwastore;
    3. GRANT ALL ON bwastore. TO ‘bwastore’@’localhost’ IDENTIFIED BY ‘nasigorenglimaribu’ WITH GRANT OPTION;*
    4. exit
  7. Setup aplikasi
    1. sudo su
    2. Masuk ke folder cd /var/www
    3. Pull project kalian dari github git clone URL_GITHUB_KALIAN NAMA_DOMAIN_KALIAN
    4. ls lalu cd NAMA_DOMAIN_KALIAN
    5. composer install
    6. nano .env
    7. Copas konfigurasi kalian dari local, ganti bagian database
    8. Ganti bagian APP_DEBUG=false dan APP_ENV=production biar kalau error ga muncul (mengamankan coding)
    9. php artisan storage:link
  8. Setting nginx
    1. sudo chown -R www-data.www-data /var/www/NAMA_DOMAIN_KALIAN/storage
    2. sudo chown -R www-data.www-data /var/www/NAMA_DOMAIN_KALIAN/bootstrap/cache
    3. sudo nano /etc/nginx/sites-available/NAMA_DOMAIN_KALIAN server { listen 80; server_name NAMA_DOMAIN_KALIAN; root /var/www/NAMA_DOMAIN_KALIAN/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \\.php$ { fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\\.(?!well-known).* { deny all; } }
    4. Ganti bagian server_name jadi NAMA_DOMAIN_KALIAN
    5. Ganti bagian root jadi /var/www/NAMA_DOMAIN_KALIAN/public;
    6. Save filenya
    7. sudo ln -s /etc/nginx/sites-available/NAMA_DOMAIN_KALIAN/ etc/nginx/sites-enabled/
    8. sudo nginx -t
    9. Harus muncul kayak gini: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
    10. sudo systemctl reload nginx
  9. Setting Database dan Migration
    1. cd /var/www/NAMA_DOMAIN_KALIAN/
    2. php artisan migrate
  10. Setting domain kalian
    1. Masuk ke panel hosting kalian (contoh disini pakai IDCloudHost)
    2. Masuk manage DNS
    3. Tambah Add Record
    4. Namenya isi NAMA_DOMAIN_KALIAN. Depannya pakai titik
    5. Type nya ganti A
    6. Isi selanjutnya (RDATA / IP Address) masukin nama IP server kalian (bisa dicek di dashboard nya)
    7. Add Record / Save
    8. Kurang lebih seperti ini:
    1. Buka website kalian sesuai NAMA_DOMAIN_KALIAN
    2. Belum muncul? Sabar tunggu dulu mungkin belum propagasi. Tinggalin minum kopi dulu
  11. Install PHPMyAdmin (opsional)
    1. Referensi dari sini https://linuxize.com/post/how-to-install-phpmyadmin-with-nginx-on-ubuntu-18-04/
    2. sudo apt install phpmyadmin
    3. Skip dua pilihan, pilih OK (pakai TAB terus ENTER)
    4. Pilih yes
    5. Masukin password phpmyadmin
    6. mysql -u root -p
    7. CREATE USER 'padmin'@'localhost' IDENTIFIED BY 'PASSWORD_SQL_PHPMYADMINYA';
    8. GRANT ALL PRIVILEGES ON *.* TO 'padmin'@'localhost' WITH GRANT OPTION;
    9. exit
    10. sudo nano /etc/nginx/snippets/phpmyadmin.conf
    11. Copas ini : location /phpmyadmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpmyadmin/(.+\\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; } location ~* ^/phpmyadmin/(.+\\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } }
  12. nano /etc/nginx/sites-available/default
  13. Masukkan include snippets/phpmyadmin.conf; didalam block server{}
  14. sudo nginx -t
  15. sudo systemctl reload nginx
  16. Masuk ke http://IP_SERVER_KALIAN/phpmyadmin/
  17. Kalau nemu error, jalanin ini : sudo sed -i "s/|\\s*\\((count(\\$analyzed_sql_results\\['select_expr'\\]\\)/| (\\1)/g" /usr/share/phpmyadmin/libraries/sql.lib.php Petiknya jangan dicopas ketik manual

credit to bwa class