Install Oci8 Oracle database connections di PHP5 Ubuntu 14.04

Install Oracle Instantclient basic dan Instantclient sdk

  1. Download Instantclient-basic dan instantclient-sdk di situs resmi oracle http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html (sesuaikan OS Linux 32/64 bit)
  2. Saya coba beberapa versi yg jalan menggunakan versi “instantclient-sdk-linux-12.1.0.1.0.zip” dan instantclient-basic-linux-12.1.0.1.0.zip
  3. Extract semua ke masing-masing folder (“tar xzvh xxxxxx”)
  4. Pindahkan isi dari instantclient-basic ke “/opt/oracle/instantclient”
  5. Pindahkan isi dari instantclient-sdk ke “/opt/oracle/instantclient/sdk”
  6. Masuk ke folder “/opt/oracle/instantclient” dan jalankan
    ln -s libclntsh.so.* libclntsh.so
    ln -s libocci.so.* libocci.so
  7. Buka menggunakan text editor file “/etc/ld.so.conf” cth: “sudo nano /etc/ld.so.conf”. Lalu tambahkan di paling bawah  ‘/opt/oracle/instantclient’
  8. Jalankan “ldconfig”

 

Install manual pecl oci8 di ubuntu 14

  1. Download dan extract pecl oci8 http://pecl.php.net/package/oci8 (untuk php 5.x download pecl 2.0.12)
  2. Masuk ke folder hasil extract, lalu jalankan “phpize” via console
  3.  Jalankan “./configure -with-oci8=shared,instantclient,$ORACLE_HOME” atau “./configure -with-oci8=shared,instantclient,<dir path instantclient cth: /opt/oracle/instantclient >”
  4. Jalankan “make install”
  5. Enable extension oci8.so di php5, caranya :
    1. buat file baru di /etc/php5/mods-available isinya extension=oci8.so , cth:
      1. “touch /etc/php5/mods-available/oci8.ini”
      2. “echo ‘extension=oci8.so’ >> /etc/php5/mods-available/oci8.ini “
    2. Jalankan “php5enmod oci8” untuk enable extension
    3. restart / reload service apache”service apache2 reload”
  6. Done

 

referensi:

  • https://askubuntu.com/questions/453449/error-installing-oci8-on-ubuntu-14-04
  • https://gist.github.com/tassoevan/10392954

lib instantclient dan pear oci 8 yg saya pakai (ubuntu 14.04 32 bit, php 5.5)

Android (aplikasi katalog online)

Project ini dibuat untuk tugas matakuliah pemrograman mobile. Lupa waktu itu semester berapa, cuma terakhir di rubah pada tanggal 6 agustus 2014. Sebelumnya aplikasi ini dibuat dengan menggunakan eclipse. Tapi berhasil di convert ke Android studio dengan cara disini:  http://stackoverflow.com/questions/16584263/how-do-i-open-my-existing-eclipse-projects-in-android-studio.

Untuk Source Code saya upload di :

https://github.com/alvinux/Android-katalog-toko-online

Untuk Dokumentasi dan keterangan download disini

Remote server (dekstop/cmd) via website

Misalkan kita punya beberapa server, entah itu windows server atau ubuntu server dengan GUI atau hanya cmd/terminal. Lalu kita ingin membuat daftar list server dan remote via website, maka bisa menggunakan Apache Guacamole. Jadi hanya satu pintu bisa memuat list server kita dan remote langsung di web browser.

link: https://guacamole.incubator.apache.org/

Setting single domain Yii2 advanced di webserver Apache

Cara setting single domain di yii2 sebenarnya beragam. Ada juga settingan rekomendasi dari dokumentasinya yiiframework langsung di : http://www.yiiframework.com/wiki/799/yii2-app-advanced-on-single-domain-apache-nginx/ .

Tapi cara disana tidak cocok setelah saya coba di lokal saya yg di folder htdocs saya terdapat banyak folder project, file di yii2 advanced harus diletakkan di root folder htdocs atau bisa menggunakan virtualhost terlebih dahulu. Sedangkan saya ingin yii2 advanced bisa diakses “locahost/yii2advanced” <- (Untuk /frontend), dan “localhost/yii2advanced/backend” <- (Untuk /backend).

Cara ini saya coba di webserver Apache, sedangkan untuk ngix saya belum explore. Saya tidak yakin cara berikut simple dan benar atau tidak, tapi setidaknya cara ini yang saya tau,hhe :v

  • Pertama Install Yii2 advanced di lokal anda dan buat folder baru di “htdocs/yii2advanced/{isi aplikasi}” atau www/yii2advanced/{isi aplikasi}
  • Setelah melakukan settingan dasar instalasi yii2 advanced, pastikan aplikasi anda bisa di jalankan di “localhost/yii2advanced/frontend/web/index” dan “localhost/yii2advanced/backed/web/index”
  • Buat file “.htaccess” dengan isi berikut ini dan letakkan di folder htdocs/yii2advanced/{.htaccess} , lokasinya sama dengan lokasi file composer.json
    # ----------------------------------------------------------------------
    # Adds some security for the Apache server configuration for use with
    # yii2-app-practical template.
    # @author Kartik Visweswaran <kartikv2@gmail.com>
    # @see http://demos.krajee.com/app-practical
    # ----------------------------------------------------------------------
    
    # "-Indexes" will have Apache block users from browsing folders without a default document
    # Usually you should leave this activated, because you shouldn't allow everybody to surf through
    # every folder on your server (which includes rather private places like CMS system folders).
    <IfModule mod_autoindex.c>
      Options -Indexes
    </IfModule>
    
    
    # Block access to "hidden" directories whose names begin with a period. This
    # includes directories used by version control systems such as Subversion or Git.
    <IfModule mod_rewrite.c>
      RewriteCond %{SCRIPT_FILENAME} -d
      RewriteCond %{SCRIPT_FILENAME} -f
      RewriteRule "(^|/)\." - [F]
    </IfModule>
    
    
    # Block access to backup and source files
    # This files may be left by some text/html editors and
    # pose a great security danger, when someone can access them
    <FilesMatch "(\.(bak|bat|config|sql|fla|md|psd|ini|log|sh|inc|swp|dist)|~|init|composer\.json|composer\.lock)$">
      Order allow,deny
      Deny from all
      Satisfy All
    </FilesMatch>
    
    # Increase cookie security
    <IfModule php5_module>
      php_value session.cookie_httponly true
    </IfModule>
    
    # Settings to hide index.php and ensure pretty urls
    RewriteEngine on
    
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # otherwise forward it to index.php
    RewriteRule . index.php
  • Buat file “index.php” di tempat yang sama. “htdocs/yii2advanced/{index.php}”
    <?php
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    defined('YII_ENV') or define('YII_ENV', 'dev');
    
    require(__DIR__ . '/vendor/autoload.php');
    require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
    require(__DIR__ . '/common/config/bootstrap.php');
    require(__DIR__ . '/frontend/config/bootstrap.php');
    
    $config = yii\helpers\ArrayHelper::merge(
     require(__DIR__ . '/common/config/main.php'),
     require(__DIR__ . '/common/config/main-local.php'),
     require(__DIR__ . '/frontend/config/main.php'),
     require(__DIR__ . '/frontend/config/main-local.php')
    );
    
    $application = new yii\web\Application($config);
    $application->run();
  • Edit file “htdocs/yii2advanced/backend/config/main.php”. Tambahkan baris yang saya tandai merah
    <?php
    
    use \yii\web\Request;
    $baseUrl = str_replace('/backend/web', '', (new Request)->getBaseUrl());
    
    $params = array_merge(
     require(__DIR__ . '/../../common/config/params.php'),
     require(__DIR__ . '/../../common/config/params-local.php'),
     require(__DIR__ . '/params.php'),
     require(__DIR__ . '/params-local.php')
    );
    
    return [
     'id' => 'app-backend',
     'basePath' => dirname(__DIR__),
     'controllerNamespace' => 'backend\controllers',
     'bootstrap' => ['log'],
     'modules' => [],
     'components' => [
     'request' => [
     'csrfParam' => '_csrf-backend',
     'baseUrl' => $baseUrl,
     ],
     'user' => [
     'identityClass' => 'common\models\User',
     'enableAutoLogin' => true,
     'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
     ],
     'session' => [
     // this is the name of the session cookie used for login on the backend
     'name' => 'advanced-backend',
     ],
     'log' => [
     'traceLevel' => YII_DEBUG ? 3 : 0,
     'targets' => [
     [
     'class' => 'yii\log\FileTarget',
     'levels' => ['error', 'warning'],
     ],
     ],
     ],
     'errorHandler' => [
     'errorAction' => 'site/error',
     ],
     
     'urlManager' => [
     'enablePrettyUrl' => true,
     'showScriptName' => false,
     'rules' => [
     ],
     ],
     
     ],
     'params' => $params,
    ];
  • Tambahkan file “index.php” di folder “htdocs/yii2advanced/backend/{index.php}”
    <?php
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    defined('YII_ENV') or define('YII_ENV', 'dev');
    
    require(__DIR__ . '/../vendor/autoload.php');
    require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
    require(__DIR__ . '/../common/config/bootstrap.php');
    require(__DIR__ . '/config/bootstrap.php');
    
    $config = yii\helpers\ArrayHelper::merge(
     require(__DIR__ . '/../common/config/main.php'),
     require(__DIR__ . '/../common/config/main-local.php'),
     require(__DIR__ . '/config/main.php'),
     require(__DIR__ . '/config/main-local.php')
    );
    
    $application = new yii\web\Application($config);
    $application->run();
  • Tambahkan juga file “.htaccess” di folder “htdocs/yii2advanced/backend/{.htaccess}”
    # ----------------------------------------------------------------------
    # Adds some security for the Apache server configuration for use with
    # yii2-app-practical template.
    # @author Kartik Visweswaran <kartikv2@gmail.com>
    # @see http://demos.krajee.com/app-practical
    # ----------------------------------------------------------------------
    
    # "-Indexes" will have Apache block users from browsing folders without a default document
    # Usually you should leave this activated, because you shouldn't allow everybody to surf through
    # every folder on your server (which includes rather private places like CMS system folders).
    <IfModule mod_autoindex.c>
     Options -Indexes
    </IfModule>
    
    
    # Block access to "hidden" directories whose names begin with a period. This
    # includes directories used by version control systems such as Subversion or Git.
    <IfModule mod_rewrite.c>
     RewriteCond %{SCRIPT_FILENAME} -d
     RewriteCond %{SCRIPT_FILENAME} -f
     RewriteRule "(^|/)\." - [F]
    </IfModule>
    
    
    # Block access to backup and source files
    # This files may be left by some text/html editors and
    # pose a great security danger, when someone can access them
    <FilesMatch "(\.(bak|bat|config|sql|fla|md|psd|ini|log|sh|inc|swp|dist)|~|init|composer\.json|composer\.lock)$">
     Order allow,deny
     Deny from all
     Satisfy All
    </FilesMatch>
    
    # Increase cookie security
    <IfModule php5_module>
     php_value session.cookie_httponly true
    </IfModule>
    
    # Settings to hide index.php and ensure pretty urls
    RewriteEngine on
    
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # otherwise forward it to index.php
    RewriteRule . index.php
  • Edit file “htdocs/yii2advanced/backend/assets/AppAsset.php”, ganti pada baris yang saya tandai merah
    <?php
    
    namespace backend\assets;
    
    use yii\web\AssetBundle;
    
    /**
     * Main backend application asset bundle.
     */
    class AppAsset extends AssetBundle
    {
        public $basePath = '@webroot';
        public $baseUrl = '@web/web';
        public $css = [
            'css/site.css',
        ];
        public $js = [
        ];
        public $depends = [
            'yii\web\YiiAsset',
            'yii\bootstrap\BootstrapAsset',
        ];
    }

 

  • Edit file “htdocs/yii2advanced/frontend/config/main.php”. Tambahkan baris yang saya tandai merah
    <?php
    
    use \yii\web\Request;
    $baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());
    
    $params = array_merge(
     require(__DIR__ . '/../../common/config/params.php'),
     require(__DIR__ . '/../../common/config/params-local.php'),
     require(__DIR__ . '/params.php'),
     require(__DIR__ . '/params-local.php')
    );
    
    return [
     'id' => 'app-frontend',
     'basePath' => dirname(__DIR__),
     'bootstrap' => ['log'],
     'controllerNamespace' => 'frontend\controllers',
     'components' => [
     'request' => [
     'csrfParam' => '_csrf-frontend',
     'baseUrl' => $baseUrl,
     ],
     'user' => [
     'identityClass' => 'common\models\User',
     'enableAutoLogin' => true,
     'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
     ],
     'session' => [
     // this is the name of the session cookie used for login on the frontend
     'name' => 'advanced-frontend',
     ],
     'log' => [
     'traceLevel' => YII_DEBUG ? 3 : 0,
     'targets' => [
     [
     'class' => 'yii\log\FileTarget',
     'levels' => ['error', 'warning'],
     ],
     ],
     ],
     'errorHandler' => [
     'errorAction' => 'site/error',
     ],
     
     'urlManager' => [
     'enablePrettyUrl' => true,
     'showScriptName' => false,
     'rules' => [
     'transaction/getrequestdetail/<id>/' => 'transaction/getrequestdetail',
     ],
     ],
     
     ],
     'params' => $params,
    ];
  • Edit file “htdocs/yii2advanced/frontend/assets/AppAsset.php”, ganti pada baris yang saya tandai merah
    <?php
    
    namespace frontend\assets;
    
    use yii\web\AssetBundle;
    
    /**
     * Main frontend application asset bundle.
     */
    class AppAsset extends AssetBundle
    {
        public $basePath = '@webroot';
        public $baseUrl = '@web/frontend/web/';
        public $css = [
            'css/site.css',
        ];
        public $js = [
        ];
        public $depends = [
            'yii\web\YiiAsset',
            'yii\bootstrap\BootstrapAsset',
        ];
    }
  • Terakhir buat folder “assets” di “htdocs/yii2advanced/assets
  • Selesai. Mudah-mudahan gk ada yang kelupaan

Membiarkan command di ubuntu server berjalan via ssh di vps (Menggunakan Screen session)

Baik, kali ini saya ingin share cara menjalankan command di vps ubuntu server saya. Idenya adalah membiarkan command berjalan secara terus menerus walaupun kita sudah disconnect dari ssh server vps kita menggunakan screen. Biasanya saya menggunakan Putty untuk connect ke server vps saya atau jika komputer anda menggunakan linux ubuntu anda tinggak ketikan “ssh xxx.xxx.xxx.xx” atau “ssh (IP server anda)”

Di server saya terinstal Ubuntu server 14.04 dan disana sudah terinstall screen secara default.

Setelah berhasil connect di ubuntu server, jalankan perintah “screen” di terminal, maka akan muncul :

screen command ubuntu server
screen command ubuntu server

Langsung tekan enter saja. Setelahnya anda akan masuk ke session terminal server baru. Ketikan perintah yang anda inginkan untuk berjalan secara continue meskipun jendela remote ssh sudah disconnect atau ditutup. Disini saya coba menjalankan perintah untuk menjalankan websocket php untuk chat yang saya buat menggunakan yii2. (abaikan error nya :D)

running-websocket-php-yii2-chat

Setelah itu langsung aja tekan  “Ctrl + a + d” atau langsung tutup/close terminal untuk detach dan membiarkannya running.

Selesai. Jika ingin menghetikan proses yg berjalan silahkan masuk lagi ke ssh server anda, lalu ketikan “screen -ls” maka akan muncul list screen yang sudah dibuat tadi.

screen -ls
screen -ls

Untuk masuk ke screen ketikan “screen -r (kode/nama screen)”. Contoh saya “screen -r 12803”. Maka akan masuk ke perintah terakhir yang anda jalankan. Anda bisa membiarkannya berjalan atau stop proses  (cnth dengan “ctrl+c”, dsb). Bisa juga membuat screen baru dengan cara “ctrl + a + c”.

Untuk stop screen bisa dengan masuk dulu ke screen nya lalu ketik “exit”. Bisa juga dengan lihat list screen seperti diatas lalu ketik “screen -X -S [session # you want to kill] quit”.

Untuk list perintah screen ada dibawah

Getting in

start a new screen session with session name screen -S <name>
list running sessions/screens screen -ls
attach to a running session screen -x
… to session with name screen -r <name>
the “ultimate attach” screen -dRR (Attaches to a screen session. If the session is attached elsewhere, detaches that other display. If no session exists, creates one. If multiple sessions exist, uses the first one.)
detach a running session screen -d <name>

Getting out

detach Ctrl-a d
detach and logout (quick exit) Ctrl-a D D
exit screen Ctrl-a \ Exit all of the programs in screen. (not recommended)
force-exit screen Ctrl-a C-\ (not recommended)
getting out of the screen session exit

Help

See help C-a ? (lists keybindings)

suber : http://aperiodic.net/screen/quick_reference