[trick] 1 Perintah Bash Untuk Buat Virtual Host di Apache 2.4

Bismillah…

pernah share, cara membuat virtual host untuk pengembangan web terutama laravel ya masa kudu akses dari loclhost/laravel/public, soal akses url, ini dia:

https://topidesta.wordpress.com/2017/11/18/trick-cara-jitu-setting-virtual-host-untuk-laravel-di-linuxlite-ubuntu-16-04/

#! /bin/bash

# May need to run this as sudo!
# I have it in /usr/local/bin and run command 'vhost' from anywhere, using sudo.

#
#   Show Usage, Output to STDERR
#
function show_usage {
cat <<- _EOF_
Create a new vHost in Ubuntu Server
Assumes /etc/apache2/sites-available and /etc/apache2/sites-enabled setup used
    -d    DocumentRoot - i.e. /var/www/yoursite
    -h    Help - Show this menu.
    -s    ServerName - i.e. example.com or sub.example.com
    
    how: sudo vhost -d /var/www/myproject  -s myproject.local
    
_EOF_
exit 1
}


#
#   Output vHost skeleton, fill with userinput
#   To be outputted into new file
#
function create_vhost {
cat <<- _EOF_
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName $ServerName
    ServerAlias www.$ServerName
    DocumentRoot $DocumentRoot
    <Directory $DocumentRoot>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
    ErrorLog \${APACHE_LOG_DIR}/$ServerName-error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog \${APACHE_LOG_DIR}/$ServerName-access.log combined
</VirtualHost>
_EOF_
}

#Sanity Check - are there two arguments with 2 values?
if [ $# -ne 4 ]; then
	show_usage
fi

#Parse flags
while getopts "d:s:" OPTION; do
    case $OPTION in
        h)
            show_usage
            ;;
        d)
            DocumentRoot=$OPTARG
            ;;
        s)
            ServerName=$OPTARG
            ;;
        *)
            show_usage
            ;;
    esac
done

if [ ! -d $DocumentRoot ]; then 
    mkdir -p $DocumentRoot
    #chown USER:USER $DocumentRoot #POSSIBLE IMPLEMENTATION, new flag -u ?
fi

if [ -f "$DocumentRoot/$ServerName.conf" ]; then
    echo 'vHost already exists. Aborting'
    show_usage
else
    sudo sh -c "echo \"127.0.0.0    ${ServerName}\" >> \/tmp\/hosts"
    create_vhost > /etc/apache2/sites-available/${ServerName}.conf
    cd /etc/apache2/sites-available/ && a2ensite ${ServerName}.conf #Enable site
    service apache2 reload #Optional implementation
fi

kalo males copy past donwload aja ini url:
https://gist.github.com/mdestafadilah/2aff0ebefefcd79a7932393d8dec5f1d

Langkahnya:

  1. $ cd /tmp
  2. wget -s https://gist.github.com/mdestafadilah/2aff0ebefefcd79a7932393d8dec5f1d
  3. sudo mv vhosts.sh vhosts
  4. sudo mv /tmp/hosts /usr/local/bin/vhosts
  5. Run: vhost -h

Done. caranya ada kok di sourcenya.

Have a nice day.

source: https://gist.github.com/fideloper/2710970

Advertisements

[trick] Cara Jitu Setting Virtual Host Untuk Laravel di LinuxLite (Ubuntu 16.04)

Bismillah…

Alkisah, setting apache 2.2 berbeda dengan apache 2.4, alasan mereka karena alasan security… alhasil, gw sampe unistall ulang apache2 berkali kali, sampe akhirnya nemu langkah yang pas! ini dia, Sumbernya:

https://lowendbox.com/blog/how-to-setup-apache-virtual-hosts-on-ubuntu-16-04/ 

http://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/setup-apache-virtual-hosts-on-ubuntu-15-04-14-04.html

Oke, dari tutorial diatas gw berhasil akses aplikasi laravel via laravel.local tanpa localhost/laravel/public.. berikut spseifikasinya:

  1. LinuxLite 3 (Ubuntu 16.04)
  2. LAMPP (Linux, Apache 2.4, Php7, Pma)
  3. Laravel 5.*

Oke, kali ini gw ringkas ya versi gw … kita akan buat nama aplikasi simbada.local, berikut langkahnya:

1 buat sebuah folder laravel dimana saja, kita coba di folder /var/www/simbada

2 copy file simbada.conf dari source sites-avaliable/000-default.conf

3 ubah code simbada.conf sesuai folder dimana ‘simbada’ berada

4 tambahkan host local, untuk akses simbada.local, ada di /etct/hosts

5 Aktifkan virtual host dengan printah a2ensite dan restart apache

6. Sekrang bisa akses simbada.local tidak lagi localhost/simbada/public

oya, nanti kalo pake chromium akan muncul warning, seperti ini, tinggal klik aja ok.

Done.

Have a nice day.

[share] Laravel kita icip icip untuk Project Selanjutnya

Bismillah…

Karena ada project dari temen yang butuh pengembangan dengan teknologi laravel, vuejs dan nodejs … akhirnya gw belajar laravel, pokoknya trick and trip tentang laravel akan menambah wawasan blog ini, oya termasuk vuejs dan nodejs ya…

instalasi laravel bisa diakses disini (laravel 5.4):

  1. https://laravel.com/docs/5.4
  2. https://stackoverflow.com/questions/26376516/laravel-php-command-not-found

nah itu sekedar informasi sederhana, next akan ada trick and trip (insyaAllah).

Have a nice day!

 

[share] Menambahkan Fungsi OTP Di SMS Gateway Gratisan Zenziva.NET

Bismillah…

Selagi santai dikantor dengan bejibun module yang sudah ada, iseng research and development tentang SMS Gateway yang Gratis dari Zenziva.net bisa gunakan API (Application Programable Interface) dimana kita bisa kirim sms geratis tapi dengan nomor random dari Web Zenziva (orang geratisan, haha) eh, keingetan dengan Fitur dari TokoCash.com Tokopedia, dimana mengirimkan kode OTP (One Time Password)  ke nomor handphone yang sudah didaftarkan, ibaratnya ada validasinya … keren keren … oya, sebelumnya penulis topidesta yaitu uda rifki juga pernah share tentang sms gateway bisa baca disini.

Nah, akhirnya jajal dulu, API dari Zenziva kalo kirim sms gimana, terus bisa!!… silahkan dilihat di github:

https://github.com/RSUP/ZENZIVA-PHP

nah, kan targetnya biar bisa OTP (One Time Password) akhirnya ubek ubek source github tentang otp-php … kan pake PHP test nya hahha, terdamparlah di sini:

https://github.com/anoopsg/Otp-php

Ternyata kagak langsung bisa coy, butuh oprek lagi … nah ada beberapa baris yang gw ubah (gw fork dulu githubnya),  berikut bbrp yang gw ubah, sedikit sih

public function __construct(){
		$this->url = "https://reguler.zenziva.net/apps/smsapi.php";
		$this->userkey = "USERKEY";       //include api key here
		$this->passkey = "PASSKEY";		
		$this->message = urlencode($this->message);
		$this->otp = 4;			
	}

udah kan ya, oya kalo butuh userkey dan passkey bisa daftar di zenziva langsung:

https://reguler.zenziva.net/

Okaylah, silahkan unduh/ fork github gw yang udah gw ubah ada dialamat ini:

https://github.com/RSUP/Otp-php/

Kagak usah gw jelasain ya, baca postingan uda rifki aja yang udah jelasin SMS GATEWAY.. kalo pada bingung komentar ajah, kalo sempet gw bales, maaf kalo lama bales, kadang males buka blog soalnya… hahaha

Have a Nice Day

[trick] Menambahkan Library ESC/POS di Codeigniter

Bismillah…

Kebetulah dikantor lagi dapet maenan baru, printer epson series tm-u220d kayak gini:

Terus, karena ngoding langsung pake RAW-TEXT dari printer ribet, contoh RAW-TEXT dari Vendor Zebra kayak gini neh:

^FN11 : NO Rekam medis
^FN12 : Nama Pasien
^FN13 : No Rekam medis bentuk barcode
^FN61 : Nama obat
^FN62 : kwantitas makan, brp tablet/kapsul perhari
^FN63 : sblm atau ssedh makan
^PQ  : kwantitas label identik

^XA
^XFE:PHARMA01.ZPL
^FN11^FD111212121212^FS
^FN12^FDKomarudin Ibrahim Saleh^FS
^FN13^FD>;111212121212^FS
^FN61^FDPanadol Expectoran 250mg^FS
^FN62^FD3 x 1 Tablet / hari^FS
^FN63^FDMinum Setelah Makan^FS
^PQ2,0,0
^XZ

Nah, karena yang dipake itu dari EPSON, akhirnya searching eh dapet deh di Github yang senang hati berbagi ini linknya:

https://github.com/mike42/escpos-php/tree/master

Ternyata TM-U220 didukung sama libarary ini, yaudah oprek deh, cara gunanya gampang banget, karena udah pake bootstrap auotloader, jadi yah tinggal load sebagai library … selebihnya bisa dicek di repo gw:

https://github.com/RSUP/ESC-POS

Gw Kagak fork, soalnya gw pake manual download dan upload file git nyah …. hehehe.

Have a nice day!

source:

  1. https://github.com/mike42/escpos-php/tree/master
  2. https://github.com/RSUP/ESC-POS

[trick] Rest Client Upload File Di PHP/ Codeigniter

Bismillah…

kalo muncul error kayak gini..

Disallowed Key Characters.

class MY_Input extends CI_Input {

    /**
     * Clean Keys
     *
     * This is a helper function. To prevent malicious users
     * from trying to exploit keys we make sure that keys are
     * only named with alpha-numeric text and a few other items.
     * 
     * Extended to allow: 
     *      - '.' (dot), 
     *      - '[' (open bracket),
     *      - ']' (close bracket)
     * 
     * @access  private
     * @param   string
     * @return  string
     */
    function _clean_input_keys($str) {
        // if (!preg_match("/^[a-z0-9:_\/\.\[\]\\s-]+$/i", $str)) {
        if (!preg_match("/^[a-z0-9:_\/-àâçéèêëîôùû]+$|/i", $str)) {

            /**
             * Check for Development enviroment - Non-descriptive 
             * error so show me the string that caused the problem 
             */
            if (getenv('ENVIRONMENT') && getenv('ENVIRONMENT') == 'DEVELOPMENT')
                var_dump($str);
            exit('Disallowed Key Characters.');
        }

        // Clean UTF-8 if supported
        if (UTF8_ENABLED === TRUE) {
            $str = $this->uni->clean_string($str);
        }

        return $str;
    }

}

Simpan di core, dengan nama MY_Input.php….

Kalo udah, ini rest server bisa ditest pake rest client apa ajah … ini yang php:

	function upload_post() {
	 $uploaddir = ROOTPATH.'/foto/full/'; //exit(var_dump($uploaddir));
	    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

	    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
	        $this->response($uploadfile, 200);       
	    } else {
	        $this->response(array('error' => strip_tags($this->upload->display_errors())), 404);        
	    }
	}
	
		$this->load->helper('layout');
		
		$uploadpath = ROOTPATH.'/foto/real/'; //realpath('assets/doc/img/real/');
		$filedata = $_FILES['filedata']['tmp_name'];
		$filename = $_POST['filename'];
		if ($filedata != '' && $filename != '')
		    copy($filedata,$uploadpath.$filename);

		$this->load->library('image_moo');

        // Take The Foto, and IMO WORK!
        $source = $uploadpath.$filename; //exit(dump($source));

        /* SIMPEN FILE */
        $full_des = ROOTPATH."/foto/full/".$filename;          
        $medi_des = ROOTPATH."/foto/medium/".$filename;
        $smal_des = ROOTPATH."/foto/small/".$filename;
        $thum_des = ROOTPATH."/foto/thumbnails/".$filename;

        $medi_h = 342;
        $medi_w = 342;            
        $smal_h = 152;
        $smal_w = 152;
        $thum_h = 62;
        $thum_w = 62;

		$this->image_moo
            // Full
	        ->load($source)
	        ->resize(2000,2000)
	        ->round(10)
	        ->save($full_des,true)
	        
	        // Thumbnails
	        ->load($source)
	        ->stretch($thum_w,$thum_h)
	        ->round(10)
	        ->save($thum_des,true)
	        
	        // Small
	        ->load($source)
	        ->stretch($smal_w,$smal_h)
	        ->round(10)
	        ->save($smal_des,true)
	        
	        // Medium
	        ->load($source)
	        ->stretch($medi_w,$medi_h)
	        ->round(10)
	        ->save($medi_des,true)
        ;

kalo ini yang versi Codeigniter 2.x:

	function upload_post() {
	$status = "";
    $msg 	= "";
     
    if ($status != "error")
    {
        $config['upload_path'] = ROOTPATH.'/foto/full/';
        $config['allowed_types'] = 'gif|jpg|png|doc|txt';
        $config['max_size'] = 1024 * 8;
        $config['encrypt_name'] = FALSE;
 
        $this->load->library('upload', $config);
 
        if (!$this->upload->do_upload('userfile'))
        {
            $status = 'error';
            $msg = $this->upload->display_errors('', '');
        }
        else
        {
            $data = $this->upload->data();
            // $file_id = $this->files_model->insert_file($data['file_name'], $_POST['title']);
            if($data)
            {
                $status = "success";
                $msg = "File successfully uploaded";
            }
            else
            {
                unlink($data['full_path']);
                $status = "error";
                $msg = "Something went wrong when saving the file, please try again.";
            }
        }
        @unlink($_FILES[$file_element_name]);
    }
    echo json_encode(array('status' => $status, 'msg' => $msg));
	}

Udah Kelar!

source:

  1. http://stackoverflow.com/questions/7077666/codeigniter-and-restserver-how-to-upload-images/11163068#11163068
  2. http://toddish.co.uk/blog/ajax-file-upload-in-codeigniter-mvc/