Selasa, 15 Januari 2019

Auto Mount Hardisk di Linux

Cara gampang untuk mount partisi di Linux adalah dengan memanfaatkan fstab, bila sudah ditambahakan di fstab setiap booting/reboot hardisk akan otomatis di mount
Jalankan blkid
/dev/sda1: LABEL="DATA" UUID="0cf51519-1b17-4861-8ca7-bbe119d6eac0" TYPE="ext4" PARTUUID="424fc3ac-b216-4f38-b144-6cd4f96c711e"
/dev/sdb1: SEC_TYPE="msdos" UUID="3E16-5919" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="62fbb27f-8970-46d6-99d3-a1d1d04a12311"
/dev/sdb2: UUID="3ee658e4-4f2c-42g9-9a9d-2f778ed5c87b" TYPE="ext4" PARTUUID="36c3fe5a-85c8-4f04-aaa8-a2ua60b4eywf0"
/dev/sdb3: UUID="gh21-h-kJLK-dd-dVzC-g0HQ-rws" TYPE="LVM2_member" PARTUUID="605tda7a-b1a1-4w2a-889f-d1da62bf3891"
Yang akan di mount otomatis adalah /dev/sda1
buka file /etc/fstab tambahkan

Partisi EXT4

UUID="0cf51519-1b17-4861-8ca7-bbe119d6eac0" /media/Film ext4 defaults 0 0

Partisi NTFS

UUID="0cf51519-1b17-4861-8ca7-bbe119d6eac0" /media/Film ntfs-3g  defaults,locale=en_US.UTF-8 0 0
buat folder /media/Film sebagai tempat mount partisi tersebut.
mkdir /media/Film
dengan menambahkan baris diatas di fstab maka hardisk yang di mount sewaktu booting bisa dibaca/tulis (read/write) oleh user.

Cara Partisi dan Format Hardisk di Linux dengan CLI

Cara untuk mempartisi dan format hardisk di Linux dengan CLI, utility yang akan kita gunakan adalah fdisk dan mkfs. Pilihan menggunakan command line, bila anda ingin memformat hardisk baru yang ditambahkan di server Linux yang tidak memiliki GUI, agar tidak salah partisi pastikan anda mengetahui Serial Number dan tipe hardisk, bisa di cek dengan perintah lsblk --nodeps -o name,serial,model
$ lsblk --nodeps -o name,serial,model
NAME SERIAL          MODEL
sda  WD-WCAW31471577 WDC WD1003FBXX-1
sdb  WD-WCAW31412727 WDC WD1003FBXX-1
Bila lsblk belum ter-install, install dengan
yum install lsblk
apt-get install lsblk

Cek Hardisk

Cek hardisk yang terdeteksi oleh Linux dengan perintah fdisk -l | grep -E '^Disk|/dev/*'
$  fdisk -l | grep -E '^Disk|/dev/*'
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Disk label type: dos
Disk identifier: 0x000cb8ad
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648  1951410175   975499264   83  Linux
/dev/sda3      1951410176  1953507327     1048576   82  Linux swap / Solaris
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Disk label type: dos
Disk identifier: 0x000bb114

Partisi Hardisk

fdisk /dev/sdb
output perintah diatas
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1953525167, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1953525167, default 1953525167): 
Using default value 1953525167
Partition 1 of type Linux and of size 931.5 GiB is set
 
Command (m for help): q
Pada tahap diatas kita memformat hardisk /dev/sdb menjadi 1 partisi dengan ukuran penuh 1 TB (931.5 GiB). Bila ingin membuat lebih dari 1 partisi dibagian Partition number masukkan 2, maksimalnya 4 partisi.

Format Hardisk

Karena saya hanya menggunakan 1 partisi, maka saya akan memformat seluruh hardisk /dev/sdb
mkfs.ext4  /dev/sdb
 
## output
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
....
....
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Mount Hardisk

Agar hardisk yang baru dipartisi bisa digunakan, mount hardisk tersebut ke folder /mnt, folder tempat mount bebas tidak harus di /mnt, bila folder belum ada, buat terlebih dahulu folder-nya sebelum di mount.
mount /dev/sdb /mnt

Senin, 03 Desember 2018

Kill Process MySQL

here I go with that trick:
  1. Login to MySql.
  2. run that query Select concat('KILL ',id,';') from information_schema.processlist where user='user';
  3. This will print all the process with KILL command.
  4. Copy all the query result, manipulate them and remove pipe. sign and paste all again into the query console. HIT ENTER.

Selasa, 06 November 2018

Install phpMyAdmin from Source

Install phpMyAdmin from Source

While it’s not recommended for production servers, because you have to manually ensure your install of phpMyAdmin is kept up-to-date, you can also install phpMyAdmin from source.

Step 1: Identify Apache’s DocumentRoot

We need to find Apache’s DocumentRoot so we know where to place our phpMyAdmin files:
In this case, we’ll need to put the phpMyAdmin files in /var/www/html.

Step 2: Download Latest Version of phpMyAdmin

The stable version of phpMyAdmin at the time this article was written: phpMyAdmin 4.3.11.1 (released 3/4/2015).
Visit the phpMyAdmin download page to grab the latest version of phpMyAdmin.
I ended up with a phpMyAdmin-4.3.11.1-english.tar.gz file in my /var/www/html directory.

Step 3: Unpack phpMyAdmin Files

Now rename the phpMyAdmin-4.3.11.1-english directory:
Remove the phpMyAdmin files:

Step 4: Secure /phpmyadmin Directory

We want to set up a specific user for our phpMyAdmin install.

Step 5: Update phpMyAdmin config.inc With Install Wizard

To use the phpMyAdmin install wizard, we first need to set up the config.inc file.

Step 6: Run phpMyAdmin Install Wizard

To begin the installation of phpMyAdmin, access the installation URL at:
http://example.com/phpmyadmin/setup/index.php
Under the “Servers” section, click on “New Server.”
phpMyAdmin Install from Source Click New Server
Under the “Servers” section, click on “New Server.”
Under the “Authentication” tab, type in your MySQL root password in the “Password for Config Auth” box and then click “Apply.”
phpMyAdmin Install from Source Authentication Tab Enter root Password
In the “Password for Config Auth” box, type in your MySQL root password.
Remove the phpMyAdmin /config directory for security.
1
sudo rm -rf /var/www/html/phpmyadmin/config

Kamis, 02 Agustus 2018

Insert to MySQL from JSon

Contoh hasil JSon String adalah sebagai berikut :

{
    "value": 4168,
    "currency": "CREDITS",
    "expiredDate": "11-12-2018"
}

JSon diatas merupakan hasil dari : http://api.nusasms.com/api/command?user=xxx_api&password=xxx_api_password&cmd=CREDITS&output=json

Create database sms_quota pada MySQL untuk menyimpan data string tersebut
dengan tabel sebagai berikut :

quota_id, quota_tgl, quota_value, quota_currency, expiredDate

Create file cek_data.php

<?php

$host="10.201.x.x";
$username="jaxxx";
$password="xxxx";
$dbase="sms-xxx";

$connection = mysqli_connect($host,$username,$password,$dbase) or die("Error " . mysqli_error($connection));

//untuk mendapatkan file json contoh data dari API URL
$jsondata = file_get_contents('http://api.nusasms.com/api/command?user=xxx_api&password=xxx_api_password&cmd=CREDITS&output=json');

//convert json ke data array
$data = json_decode($jsondata, true);

$value = $data['value'];
$currency = $data['currency'];
$expired = $data['expiredDate'];

$sql = "INSERT INTO sms_quota(quota_tgl, quota_value, quota_currency, expiredDate)
VALUES(NOW(), '$value', '$currency', '$expired')";

if(!mysqli_query($connection, $sql)){
  die("Error insert data ");
}else{
  echo "Success insert data";
}

?>

untuk memanggil jalankan http://[alamat]/cek_data.php

Selesai.....

Rabu, 11 April 2018

Insert MySQL from other host with PHP

<?php

//fecth loop data kantor Host 1
$dBIP='10.xxx.xxx.x';
$dBADN='usr_xxxxx';
$dBPWD='pwd_xxxxx';
$dBDBS="xxxxx_db";

$CONNECTW=mysql_connect($dBIP,$dBADN,$dBPWD);
mysql_select_db($dBDBS, $CONNECTW)  or die("Can't connect to second database");


function createOtherConn($host, $uname, $pass, $db) {
$conn = new mysqli($host, $uname, $pass, $db);
          if (!$conn->connect_error) {
return $conn;
          } else {
return false;
          }
}

$query = mysql_query("SELECT kantor_host FROM data_kantor WHERE kantor_status = '1'");
// $start = 0;
while ($row = mysql_fetch_array($query)) {
//SELECT dari Host 2
$kantorConn = createOtherConn($row['kantor_host'], 'usr_xxx', 'xxx123!', 'sms');
      try{
if ($kantorConn) {
$sql = "SELECT dbase_register,dbase_kantor,dbase_kode,dbase_total
                             FROM temp_dbase";
$result = $kantorConn->query($sql);
if ($result->num_rows > 0) {
while ($rowData = $result->fetch_assoc()) {
$dbReg     = $rowData['dbase_register'];
$dbKantor = $rowData['dbase_kantor'];
$dbKode    = $rowData['dbase_kode'];
$dbTotal    = $rowData['dbase_total'];

$queryIns = mysql_query("INSERT INTO temp_dbase (dbase_register, dbase_kantor, dbase_kode, dbase_total) VALUES ('$dbReg', '$dbKantor', '$dbKode', '$dbTotal')");
if ($queryIns) {
echo sprintf('Fetch data %s sukses..', $row['kantor_host']);
echo "<br/>";

} else {
echo sprintf('Fetch data %s gagal.', $row['kantor_host']);
echo "<br/>";
}
}
} else {
echo "No data to print.";
}
} else {
echo sprintf('Koneksi ke %s gagal.', $row['kantor_host']);
}
}catch(Exception $e){
echo "error :". $e->getMessage();
}
$kantorConn->close();

// if ($start >= 10) {
// break;
// }
// $start++;
}

?>

Senin, 02 April 2018

Konfigurasi HTTPS pada Website Apache2 Ubuntu Server 14.04 | Self-Signed SSL

HTTPS adalah protokol website (http) yang sudah memiliki secure yang sangat terjamin dan membuat website lebih aman dari serangan hacker. HTTPS dibuat dan memerlukan sebuah SSL Certificate untuk mensecure port HTTP. dan SSL Certifikace tersebut kita harus membelinya jika untuk website yang sudah publik.

Namun jika kita ingin belajar menggunakan virtualbox atau hanya mengatasi rasa ingin tau maka cara ini bisa anda gunakan.Ingat!! Jangan gunakan cara ini untuk Publik website ya.

Membuat Private Key (Buatlah password jika diminta):


$ openssl genrsa -des3 -out server.key 1024

Buat certificate nya :

$ openssl req -new -key server.key -out server.csr

Hapus Passpharse dari key :

$ cp server.key server.key.org
$ openssl rsa -in server.key.org -out server.key

Buat self-signed ssl nya:

$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Copy Certificate dan Key ke directory ssl apache2 :

$ cp server.crt /usr/local/apache/conf/ssl.crt
$ cp server.key /usr/local/apache/conf/ssl.key

Kemudian tambahkan ssl tsb ke VirtualHost yang ingin dibuat HTTPS , Letakkan script dibawah sebelum tag </VirtualHost> dan jangan lupa Port *:80 diganti dengan *:443

SSLEngine on
SSLCertificateFile /usr/local/apache/conf/ssl.crt/server.crt
SSLCertificateKeyFile /usr/local/apache/conf/ssl.key/server.key


Setelah itu restart apache anda :

$ a2enmod ssl
$ a2ensite default-ssl
$ service apache2 restart

Bukalah website anda dengan protokol https, Dan jangan lupa except certificate anda untuk bisa browse. Karna dianggap unsecure terhadap browser (karena self-signed SSL :D ):

https://www.domain.com