2018年9月18日 星期二

Codeigniter使用OracleDB 備忘

1. 下載 Oracle Instant Client,建議下載32位元的貌似使用在Windows環境下的PHP的php_oci12c.dll是編譯在32位元的,當然自行下載source code編譯的就依照自己設定的為主。

※ 透過phpinfo()看所安裝的PHP是x86 or 64然後下載相對應的Oracle Client版本回來,不過通常是32位元的就是了。

2. 將下載回來的Oracle Client (建議:Instant Client Package - Basic )解壓縮後的路徑位址( N:\instantclientXX\ ) 新增到系統環境變數內,請記得重新開機以利生效。

3. 至php.ini將php_oci12c.dll前面的分號";"拿掉,然後重啟web server(ex. IIS or Apache)。

4. 在CI的config\database.php
$db['default'] = array(
'dsn' => '',
'hostname' => '(IP or DomainName)/(SID)',
'username' => 'account',
'password' => '******',
'database' => '',
'dbdriver' => 'oci8',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

5. 若依舊是顯示oci_connect() 未定義的錯誤,那麼就再下載含有Net Manager 的 Oracle Client。之前碰到Oracle Client裝64位元但:Instant Client裝x86,這樣PHP是沒法啟用oci8的套件。

備忘:
1. 改Oracle後table & column name都變大寫,好用的AI沒了得改sys_guid() ... 還有很多很多 =.=
2. CI在Sql Query會加雙引號,若使用Oracle須改system\db_driver.php 把雙引號拿掉。
3. CI2使用Oracle是悲劇的(ex. rownum()),後來直接改使用CI3就順多了。

2018年7月19日 星期四

aws EC1 設定 samba 備忘

最近又在搬家了,從自建機房->Azure->Jcloud到現在的AWS,貌似GCP, alibabacloud評估中~這~ =.= 工程師是無敵的吧? 每個環境都有些小眉角,放在這邊貌似比存在硬碟來的方便,所以就備忘一下。

安裝服務
yum install samba samba-client
chkconfig smb
service smb start/restart/stop

得在AWS的儀表版Security Group 設定Inbound PORT
open TCP 139 如果有windows設備要連線,則加開445
open UDP 137-138

設定分享資料夾位置
vim /etc/samba/smb.conf
---------------------------------------------------------------
security = user             #使用者驗證

[smb_folder]
valid users = @smbgrp       #群組授權
...

---------------------------------------------------------------

測試設定檔
testparm

新增使用者,將該使用者群組設定到smbgrp
useradd smb_account -G smbgrp
passwd smb_account
smbpasswd -a smb_account

測試連線
本地: smbclient //localhost/smb_folder -U smb_account
遠端: smbclient //smb-server-ip/smb_folder -U smb_account


2018年7月17日 星期二

json_decode 將json轉成陣列或object


再配合WebAPI時,常使用JSON來作為交換的格式,不過在多維陣列下的JSON組合就多了些眉角,把從資料庫取回的JSON紀錄轉換成ARRAY若成object再進行encode,此時JSON的地方將會有array("\"", "''", ":',", "\ufeff")這類的DATA跑出來造成還原解析上的異常,所以加個true成array在轉換就單純多了,做個備忘。
$json '{"a":1,"b":2,"c":3,"d":4}';
var_dump(json_decode($json));var_dump(json_decode($jsontrue));
Output:
object(stdClass)#1 (5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
}

array(5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
}

2018年6月22日 星期五

Centos 查詢對外IP位址

租用雲端空間的虛擬機器,使用ifconfig往往看到的都是內網IP,要查詢實際外網IP可使用下列指令

curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//' 
or shorter
curl ipinfo.io/ip 

2018年6月7日 星期四

jenkins執行shell script中無法使用sudo的解法

再導入DotNet Core專案在CentOS環境,欲利用Jenkins進行發布時發現在建置時尚需重啟DotNET Core Project.service,不過這服務jenkins原生的權限不足,所以加上sudo前墜後出現錯誤"sudo: no tty present and no askpass program specified",改善方式如下:

1. 在終端輸入 sudo visudo

2. 於文件最後增加 jenkins ALL=(ALL) NOPASSWD: ALL

3. 重啟jenkins