2014年4月9日 星期三

安裝debian server

RAM: 2G
硬碟:8G

欲安裝的軟體:
screen, sudo, vim, git, mysql( mysql-server, mysql-client,  ),

安裝sudo
http://sharadchhetri.com/2013/08/07/sudo-command-not-found-debian-7/
$ apt-get update
$ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
$ sudo apt-get install vim
bash: sudo: command not found
$ su -
# apt-get install sudo
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  sudo
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 0 B/851 kB of archives.
After this operation, 1,885 kB of additional disk space will be used.
Media change: please insert the disc labeled
 'Debian GNU/Linux 7.4.0 _Wheezy_ - Official i386 CD Binary-1 20140208-12:25'
in the drive '/media/cdrom/' and press enter => 要你插光碟
解法:
http://askubuntu.com/questions/236288/apt-get-asks-me-to-insert-cd-why
$ sudo gedit /etc/apt/sources.list
把這行註解掉:
# deb cdrom:[Ubuntu 12.10 _Quantal Quetzal_ - Release amd64 (20121017.5)]/ quantal main restricted
然後別忘了: sudo apt-get update
就能 # apt-get install sudo 了

user_name@linux:~$ sudo apt-get install vim
出現錯誤:
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for user_name:
user_name is not in the sudoers file.  This incident will be reported.
解法:
用root 編輯這個檔案:
# vi /etc/sudoers
加入這一行:
user_name ALL=(ALL:ALL) ALL
user_name就能使用sudo安裝套件了

vim 沒highlight
在~/.vimrc裡面加入這行: syntax on
或將 /etc/vim/vimrc 的" syntax on 註解拿掉

安裝mysql
http://ariejan.net/2007/12/12/how-to-install-mysql-on-ubuntudebian/
$ sudo apt-get update
$ sudo apt-get dist-upgrade  # 什麼是apt-get dist-upgrade
※ upgrade: 系統將現有的 Package 升級, 如果有相依性的問題, 而此相依性 需要安裝其它新的 Package 或 影響到其它 Package 的相依性時, 此 Package 就不會被升級, 會保留下來.
※ dist-upgrade: 可以聰明的解決相依性的問題, 如果有相依性問題, 需要 安裝/移除 新的 Package, 就會試著去 安裝/移除 它. (所以通常這個會被認為是有點風險的升級)
$ sudo apt-get install mysql-server mysql-client  # 我安裝時他就提示要我設置mysql的root密碼,故不用另外用指令設置了
如果裝好mysql和apache後需要裝php5-mysql才能讓php用mysql( mysql, mysqli 擴展 )
$ sudo apt-get install php5-mysql

安裝php
$ sudo apt-get install php5  # 網路上找到的都要安裝 libapache2-mod-php5 ,但php5安裝完就有裝libapache2-mod-php5了
$ dpkg --get-selections | grep php
libapache2-mod-php5                             install
php5                                            install
php5-cli                                        install
php5-common                                     install

新增資料庫
# mysqladmin create xxx
錯誤訊息:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
解法:
照這篇改密碼後就可以了
http://magicsun.pixnet.net/blog/post/25768313-mysqladmin%3A-connect-to-server-at-'localhost'-failed-%E8%99%95%E7%90%86
雖然改的密碼前後都一樣( 我原本mysql -u root -p 可以登入 ),估計是mysql> FLUSH PRIVILEGES; 的關係


2014年4月7日 星期一

KDE常見問題

因為GNOME的cinnamon在雙螢幕時無法像zbar或UltraMon 一樣底下有兩個工作列( dual monitor panel ),所以改用KDE plasma(雖然KDE也是有一堆不習慣的缺點... 用linux辦公深深體會到linux is free if your time is no value)
ex.
1. panel 在左右時會浮在視窗上面無法固定
2. 桌面沒有東西,需要新增一個資料夾的panel,然後將這個panel指到桌面資料夾去,而且這個panel還不能調整大小
3. 在左下角K中搜尋程式,中文會找不到,只能打英文
KDE Plasma上仍使用cinnamon 軟體的軟體:
終端機 - gnome-terminal
File manager - nemo

用了KDE遇到的問題:
skype選取聯絡人時顏色無法閱讀
解法:
1. 編輯 ~/.config/Trolltech.conf
2. 在 [Qt%20Plugin%20Cache%204.8.false] 區間內找到這行:
usr\lib\kde4\plugins\styles\oxygen.so=0, 1, , 2014-02-01T10:37:25
然後把他刪掉
3. 重啟skype
(重開機後就無效了,改用下面方法)
http://ubuntuforums.org/showthread.php?t=2098775
for me, only the following actions made stable effect:
1. install kde-config-gtk gtk2-engines-oxygen:i386
2. go to Sytem Settings -> Application Appearance ( KDE: K=>設定=>系統設定=>應用程式外觀 )
a. colors - select Oxygen Gold ( 顏色=>機制=>選Oxygen Gold => 套用 )
b. GTK+ appearance - select oxygen-gtk  ( 左邊那個GTK分頁 )

KDE更改預設file manager:
http://ubuntuforums.org/showthread.php?t=893591&p=5615038#post5615038
expand KDE Components -> File Associations -> expand Inode -> Directory
Then move Konqueror above Dolphin in the Application preference order, apply

在桌面新增gnome-terminal捷徑(因為konsole的screen被選取標題的會閃爍)
~/桌面 $ ln -s /usr/bin/gnome-terminal

gnome-terminal 在 KDE 桌面啟動時會自動縮小
http://blog.roodo.com/rocksaying/archives/25394946.html
目前在 KDE 下解決 gome-terminal 縮小的方法是利用 KDE 的「視窗行為」微調。從「系統設定」/「視窗行為」/「視窗規則」(System Settings/Window Behavior/Window Rules)頁面,增加一條規則,其內容如下列:
※ 視窗比對 - 「視窗類別」,「完全符合」: gnome-terminal。
※ 大小與位置 - 勾選「遵循位置限制」,「強制」,「否」。 ("Obey geometry restrictions", "Force", "No")

Kde 不要透明=>左右無解,需換桌面主題=>放棄
https://forum.kde.org/viewtopic.php?f=67&t=94807 (未試)
換主題需清cache => delete the entire /var/tmp/kdecache-$USER/ directory
http://forum.kde.org/viewtopic.php?f=17&t=89913  (未試)
換主題:
K->Settings->System Settings->Workspace Appearance->Desktop Theme->Details.
Select Panel Background and choose "file." Then select your new panel-background.svgz image.
I chose /usr/share/kde4/apps/desktoptheme/default/opaque/widgets/panel-background.svgz

讓kde plasma左右兩視窗工作列taskbar只顯示在同一個螢幕的面板上
在”工作管理員”元件(需在面板上新增工作管理員元件)上點右鍵=>工作管理員設定=>一般=>過濾器=>勾選”只顯示目前螢幕上的工作”和”只顯示目前活動裡的工作”

KDE桌面上的那块桌面图标面板怎么调出来?
http://www.guokr.com/question/354783/
桌面點右鍵 => 新增元件 => 選”資料夾” => 新增後點元件設定圖示 => 位置 => 顯示桌面資料夾

KDE 4 滑鼠單擊啟動改成雙擊啟動 
左下角應用程式選單->應用程式->設定->系統設定->輸入裝置->滑鼠->「點兩下開啟檔案或目錄」

安裝新酷音詞庫
https://github.com/chewing/chewing-utils
$ wget https://github.com/chewing/chewing-utils/archive/master.zip
$ unzip master.zip
$ cd chewing-utils-master/hash-editor/
$ make
$ cd src
$ ./che  #可以把他建立連結到桌面
(後來發現不用這麼麻煩,新酷音新增詞庫,你打好字把他選好後enter,他就會自動記憶了)

延長螢幕變暗時間
K => 搜尋 powerdevil ( 省電模式 )

chrome和firefox在linux按backspace無法上一頁
1. 使用alt + <- 上一頁  和 alt+->下一頁
2. chrome安裝套件: Backspace As Back/Forward for Linux
3. firefox :
    a. 開新分頁網址列打上: about:config
    b. 搜尋"browser:backspace_action",将其值由2 修改成0 即可


2014年3月27日 星期四

cinnamon 常見問題

更改日曆開頭為星期日
http://forums.linuxmint.com/viewtopic.php?f=90&t=104413#p590231
$ gksudo gedit /usr/share/i18n/locales/en_US #即使使用中文界面也是改這隻而不是zh_TW或zh_CN,
first_weekday   2 => first_weekday   1 # 1為週日,2為週一
$ sudo locale-gen
重新登入即可

鎖定螢幕
$ cinnamon-screensaver-command -l #cinnamon的鎖定螢幕
$ gnome-screensaver-command -l #傳統ubuntu的鎖定螢幕
(兩個都下會變成要解鎖兩次,過陣子登入menu中文界面會漏字)

雙螢幕雙工作列(taskbar)
像windows的UltraMon 或zbar在左右兩個螢幕下面都有taskbar
原來linux內建就有這功能了 http://scott.cm/create-new-panel-on-second-monitor/
但是cinnamon(kubuntu)不支援這功能 http://unix.stackexchange.com/questions/56523/adding-the-panel-to-the-second-monitor
Unfortunately Cinnamon does not have this functionality. (yet?) It only shows a panel on your primary monitor.
而gnome(ubuntu)內建就有這功能了




2014年3月23日 星期日

支付寶+浦發網銀買點評網團購券

去浦發銀行 點 个人网银登录 ( 建議使用IE瀏覽器開 )
tab上有動態密碼版和理財版
登录方式:
客戶號/暱稱 就是 個人業務憑證/回單 上面的客戶號(10位號碼)
卡號 就是 借記卡 上面的16位號碼
查詢密碼是動態密碼鍵盤,第一次使用時需安裝動態密碼鍵盤,下載下來的程式簡體中文有亂碼
http://forum.gamer.com.tw/C.php?bsn=12980&snA=2492  (使用 pAppLocale )
( 原本使用 Microsoft AppLocale公用程式
但出現以下錯誤:
There is a problem with the Windows Installer package. A program required for this install to complete could not be run.Contact your support personnel or package vendor
=> 請在剛剛儲存的 apploc.msi 程式上按滑鼠右鍵,選擇 [內容],切換到 [相容] 索引標籤,勾選 [以相容模式執行這個程式],並選擇 [先前的Windows 版本]
)
在登錄網銀時登錄表單旁邊他會提示你裝 "上海浦东发展银行网银管家" ,這個是用來檢測你系統設定有沒有正確(看起來只能檢查),我沒有全部都修復成功(即有發現錯誤項),也能使用IE登入
網銀網頁沒有出現輸入密碼的input=> 打開"上海浦东发展银行网银管家" =>點右邊的"清理IE緩存"和"清理SSL緩存"=>重開IE 就能看見表單了

使用Linux的Firefox開浦發網銀相關新聞:
http://digi.163.com/14/0327/07/9OB1LM4900162OUT.html
http://digi.163.com/14/0329/23/9OHS4B8H00162OUT.html


支付寶 - 通常淘寶登入了什麼帳號,支付寶就同步登入了
登入支付寶後,選擇充值(勿充值到餘額寶上,因為台灣人不能用餘額寶)
點 儲蓄卡  點下面的 選擇其他 (務必使用IE登入,不然這裡不會出現。chrome或firefox也許裝IE tab就能使用)
千萬不要選到浦發銀行企業版 他會要你使用U-key + 證書(CA) 才能登入
快捷支付請勿勾選
導到浦發銀行頁面後 請選上方的網銀支付 ,這邊登錄時只能使用客戶號登入,勿使用借記卡上面號碼登入 接著他就會傳動態密碼的簡訊(有浦發網址)到你浦發銀行當初榜定的手機
然後就登入了網銀後台,記得去 安全设置>限额设置>个人网银限额>>交易限额设置 設定"单笔限额"和"单日限额"
然後回
缴费支付>网上支付>网上支付订单>>网上支付
繼續交易
這時候他又會傳 手机动态密码 的簡訊(有訂單號)到你手機
手機版的支付密碼與網頁版不同,打錯三次就會被鎖,印象中沒設過網頁版支付密碼...

點評 -
支付寶裡面沒錢時會導到要你榜定銀行卡的步驟,千萬不能進這步驟,因為會要你輸入大陸身份證字號(網頁和app版步驟都一樣),所以支付寶裡面要先存錢

20140621
手機重灌後,手機支付寶需要支付密碼才能登進去
上支付寶網站跑取回支付密碼流程,需上傳台胞證照片,台灣身份證無效
護照類別選中國大陸的其他
通過認證後會傳連結到你申請時寫的email,然後重設密碼

20141202
登錄支付寶充值後又再次跳出要實名認證的要求
https://cshall.alipay.com/lab/help_detail.htm?help_id=215427&keyword=%25CC%25A8%25CD%25E5%25C8%25CF%25D6%25A4
會自動導到2、点击【台湾】;這個步驟
這次要填的欄位有:
真實姓名(請用簡體字)
身份證號碼(我填台灣身份證,台胞證號碼補0前端驗證無效)
台胞證圖片
入境證明圖片
常用地址
聯繫電話
驗證碼

点击【下一步】,要榜定銀行卡,欄位有:
開戶銀行
銀行所在城市
銀行卡號
点击【下一步】,幾分鐘後,剛剛榜定的銀行帳戶支付寶會入賬一筆小於1塊的金額
7、输入打款金额,点击【确认】,然後再等一兩天等消息...





2014年3月19日 星期三

cakePHP 心得

使用cookie
http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html
在你的Controller加入
public $components = array('Cookie');
public function beforeFilter() {
parent::beforeFilter();
$this->Cookie->name = 'baker_id';
$this->Cookie->time = 3600;  // or '1 hour'
$this->Cookie->path = '/';
$this->Cookie->domain = 'cake.localhost';
//$this->Cookie->secure = true;  // i.e. only sent if using secure HTTPS
//$this->Cookie->key = 'qSI232qs*&sXOw!adre@34SAv!@*(XSL#$%)asGb$@11~_+!@#HKis~#^';
$this->Cookie->httpOnly = false;  //設為false,才能使用js去讀他
}

$this->Cookie->write('name', 'Larry', false); //設為 false 在cookie前端才不會編碼,cakePHP預設為編碼

使用jQuery存取cookie
https://developers.google.com/speed/libraries/devguide#jquery
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
jQuery 1.x 兼容IE
jquery.cookie
http://cdnjs.com/libraries/jquery-cookie/
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.js"></script> //速度沒google cdn快
使用方法:
$.cookie('baker_id[name]')

在View中使用cookie
http://stackoverflow.com/questions/7525428/cakephp-cookie-does-not-read-at-view
There is no Cookie helper in CakePHP, neither a method to access it in View.
所以只能在Controller用set(),然後在view讀取那個變數
Controller:
$this->set('myValue', $this->Cookie->read('cookieValue'));
View:
<?php echo $myValue; ?>
或使用$_COOKIE ( break the MVC pattern )  => 使用$_COOKIE叫時,cakePHP的Cookie不能加密 - $this->Cookie->write('myValue', $value, false);

http://stackoverflow.com/questions/19741075/cakephp-reaching-cookies-from-the-view-files
在你的Controller的beforeFilter() 加入這行
$this->set('cookie', $this->Cookie->read('cookie_key'));
但是該cookie_key在controller後面有被改,該值會是舊的

http://stackoverflow.com/questions/3264498/how-to-read-cookie-value-in-cakephp-view-file ( 採用 )
Use Cookie components in AppController:
$components = array('Cookie');
Define following in AppController's beforeFilter():
$this->set('cookieHelper', $this->Cookie);
So that you could use it in view:
$cookieHelper->read('something');
用上面這方法cookie在view取會lag,還是使用傳統方法:
$this->set('myValue', $this->Cookie->read('cookieValue'));


取目前domain
http://stackoverflow.com/questions/4298552/base-url-in-cakephp
Router::fullbaseUrl();  // http://one.com
Router::url('/', true);  // http://one.com
$_SERVER['SERVER_NAME'];  //one.com
$pieces = parse_url(Router::url('/', true));
echo $pieces['host']; //one.com

在view中抓現在的網址
http://stackoverflow.com/questions/13034267/in-viewcakephp-the-proper-way-to-get-current-controller
$this->params['controller']; //抓現在的controller
echo $this->here; //  抓現在的位置,/Users/login
echo Router::url( $this->here, true );  // true或false 選擇是否為完整網址

取最後五筆資料
http://stackoverflow.com/questions/10150717/output-last-5-rows-in-database-cakephp
Controller:
$alltext = $this->Text->find('all', array('limit' => 5,'order'=>array('id DESC')));

Controller 裡面的 $this->data 是表單post的資料,注意不能設這邊的值

recursive
http://book.cakephp.org/2.0/en/models/model-attributes.html#recursive
※ -1 CakePHP fetches Group data only, no joins.  // 建議的值,可以在AppModel裡設置public $recursive = -1; ,在pagiante時要用joins必須設-1
※ 0 CakePHP fetches Group data and its domain
※ 1 CakePHP fetches a Group, its domain and its associated Users //預設值
※ 2 CakePHP fetches a Group, its domain, its associated Users, and the Users’ associated Articles

cakePHP表單裡用echo $this->Form->create();產生的隱藏input :  _method
<input type="hidden" value="POST" name="_method">
官網文件: Since this is an edit form, a hidden input field is generated to override the default HTTP method.
測試結果: 只對 $this->request->is('post') 和 $this->request->is('get') 影響,$_GET , $_POST, $this->reuqest->query (GET),$this->request->data (POST) 沒影響

移除表單Helper input的label和外層div
$form->input('Project/name', array('label' => false, 'div' => false));
或在Form->create裡設定
$this->Form->create('Device', array(
'inputDefaults' => array(
'label' => false,
'div' => false
)
));
或 在表單之前設定
$this->Form->inputDefaults(array(
'label' => false,
'div' => false,
));

必須設定對應的View,即使在Layouts/default.ctp裡extend成另一個view
不然雖然畫面正常,但在view或elements裡面的變數叫不出來
在$this->viewVars['name'] 會顯示 Missing ...xxx.ctp
在ajax request可以使用 $this->autoRender = false; 讓cakephp停止叫view



2014年3月11日 星期二

google 搜尋結果底線不見

網路上搜到的都是老外抱怨底線出來想把他弄不見,但我還是習慣看有底線的結果

解法: 清除goolge網域的cookie

(會將有登入狀態的所有網站登出)

如何只對google清除cookie?

安裝這個plugin
Remove cookies for site.
https://chrome.google.com/webstore/detail/remove-cookies-for-site/lmfdblomdpkcniknaenceeogpgepocmm

安裝好後開google => 點右上角plugin圖示 => 刷頁搜尋(底線又回來了)

只是要重登入google

看來是google的改版,全球都一樣

http://searchenginewatch.com/article/2332515/New-Google-Search-Layout-Has-No-Underlines-Makes-Titles-Bigger

看來只能用油猴子自己把底線加回去了

2014年2月19日 星期三

RT-N12HP刷機tomato

接續前篇:區網設定

為了要架openvpn(GFW會擋),所以將RT-N12HP刷機tomato

參考了:新手為華碩RT-N12刷Tomato韌體的經過與心得
1.電腦上必須先安裝ASUS RT-N12公用程式
- 上官網 http://www.asus.com/tw/support
- 搜尋RT-N12HP後到該產品頁面
- 下載驅動程式 UT_RT_N12HP_4267.zip (我電腦win7 32bit)
- 解壓縮後安裝
- 開始程式集會出現ASUS Utility => RT-N12 Wireless Router => Firmware Restoration

2.TOMATO 或是 DDWRT 的韌體
如果是要刷TOMATO中文化的韌體請從這邊下載:
http://code.google.com/p/twtomato/downloads/list
我用的是 tomato-K26-1.28.RT-N5x-MIPSR2-110-Max-cht-0621.trx  Tomato Shibby R2 110 MAX 正體中文版 (RT-N12B/C/HP 適用)

刷機步驟:
1. 把ASUS RT-N12和電腦連接(有線連結)

2. 將你的網路卡IP位址改成 192.168.1.10 子網路遮罩 255.255.255.0(聽說可不做,不過我還是做了)

3. 執行Firmware Restoration 按瀏覽選擇你要刷的韌體檔案, 選好之後先不要按上載

4. 把RT-N12的電源線拔掉 =>電源線與RT-N10E通用

5. 按住RT-N12背面的 Reset 鈕不放

6. 接上RT-N12的電源線

7. 注意當RT-N12的電源燈(PWR)緩慢閃爍的時候放開 Reset鈕並立刻按Firmware Restoration的"上載"按鈕

8.如果成功的話你會看到狀態底下的進度由左到右開始跑(如下圖,如果過了十幾秒都沒有動作,表示太慢了,請從步驟4開始再試一次。),這時候請不要關閉任何程式和RT-N12的電源。更新完Firmware Restoration會告訴你Router必須重開,請至少等一分鐘之後再拔掉RT-N12的電源重插。

9. RT-N12更新完之後把網路卡的IP改回自動取得IP位址,重新取得IP之後就可以用瀏覽器連上http://192.168.1.1 進設定畫面進行後續的設定了

10.刷完後的馬上第一件事, 在設定之前, 別忘了把 NVRAM 的資料完全清除掉.
     Erase all data in NVRAM memory(thorough) =>這步不知道去哪邊做

不過在設定pppoe連線那裡又遇到困難了,剛開始找不到在哪裡輸入hinet帳密,後來找到是在:基本設定--網路--連線類型,把DHCP取得IP改成PPPoE撥接,可以輸入帳密的地方就出來了(只需輸入帳號密碼) =>但我一直連不上
解法:進tomato管理介面=>路由器管理=>韌體升級=>
1. 勾選"刷機後, 清除 NVRAM 全部資料"
2. 上傳剛剛下載的 tomato-K26-1.28.RT-N5x-MIPSR2-110-Max-cht-0621.trx 重新刷機一次,這次無須拔插頭

完成後去"基本設定--網路--連線類型"重新輸入帳號密碼
然後去"系統狀態--系統資訊",右邊的"廣域網路(WAN)" 點連線,就連線成功了

問題:連線後連線不穩
> ping tw.yahoo.com
回覆自 116.214.8.103: 位元組=32 時間=1212ms TTL=56
回覆自 116.214.8.103: 位元組=32 時間=297ms TTL=56
回覆自 116.214.8.103: 位元組=32 時間=1476ms TTL=56
回覆自 116.214.8.103: 位元組=32 時間=964ms TTL=56

使用tomato工具測試( 診斷工具--Ping ) => 看起來正常
ping 無線AP=> ping 無線ap就慢了..
C:\Windows\System32>ping 192.168.1.1 -t
Ping 192.168.1.1 (使用 32 位元組的資料):
回覆自 192.168.1.1: 位元組=32 時間=571ms TTL=64
回覆自 192.168.1.1: 位元組=32 時間=446ms TTL=64
回覆自 192.168.1.1: 位元組=32 時間=2ms TTL=64
回覆自 192.168.1.1: 位元組=32 時間=425ms TTL=64
結果:
網路線有問題,換一條線就好了

連SSH
http://my-fish-it.blogspot.tw/2011/10/ss-asus-rt-n16-ssh.html
去tomato後台=> "路由器管理--連線登入與密碼" => 勾選"遠端登入(Remote)" => 儲存
開putty -> ssh 192.168.1.1,帳號root,密碼與tomato密碼相同

tomato無線網路設密碼:
"基本設定--網路" => 右邊"無線網路"
加密方式:WPA2 個人版(PSK)
編碼方式:AES
公用金鑰:xxx(設你要的密碼)

警告:(2015/1/6更新)
有鑑於本篇文章是本blog人氣最高的文章,我刷機後大概半年多(2014/2~2014/10),有一次回家發現 RT-N12HP 已經壞了,接有線網路抓不到ip,重置路由器無效。目前打算過年再拿去華碩皇家修。