As a newbie of Rails, we might need to try this web application on AWS server, especially AWS providing Free tier Server for us. I use t2.micro as a testing server in this scenario.

Step One—Install Ruby
1. sudo yum install ruby (in my server, ruby is already installed, you may check by using this command)

Install necessary packages and libraries
2. sudo yum install gcc g++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel

3. sudo yum install ruby-rdoc ruby-devel

Step Two—Install Ruby Gems
4. sudo yum install rubygems

Step Three—Install Rails
5. sudo gem update

6. sudo gem update –system

7. sudo gem install rails

Step 8 lacking repositories
8. gem install io-console
9. gem install json
10. sudo yum install nodejs npm –enablerepo=epel

Step 9 remember to open port 3000 from AWS security Group

Step 10 Try to create a blog web application
11. cd /home/ec2-user
12. rails new blog
13. cd blog

Step 11 Start the server!
14. rails server

Step 12 Open your browser and take a look
15 http://x.x.x.x:3000

 

15. cd /home/ec2-user/blog

16. vi Gemfile

17. add "gem ‘io-console’" at the top of the file, so that you can execute "rails generate controller welcome index"

1. How to UNDO git merge?

git reset --hard HEAD~1 #HEAD~2是UNDO兩步的一次, --soft 不會刪掉原本修改過的部分, --hard會直接刪掉已修改的部分

2. 如果我發現我不小心git merge了, 而且還push到了遠端, 我要怎麼辦?

git reset --hard HEAD~1 # 這個指令會讓你的狀態回到還沒MERGE的狀態
git push -f origin local/origin # 這個指令是迫使遠端的狀態跟我本機端的一樣

3. 希望將本機的BRANCH 還原得跟遠端一模一樣 (小心使用)

git fetch --all
git reset --hard origin/master #master代表 branch的名稱

pecl_http is required for the php function: http_build_url()
in order to use this function, we need to install the package manually,
below is the steps that required to install on your centOS server.

1. Install PHP Pear if not installed yet:
yum install php-pear

2. Install GCC if not installed yet:
yum install gcc

3. Install cURL if not installed yet:
yum install curl-devel

4. Install following library if not installed yet:
yum install php-devel
yum install zlib-devel
yum install pcre-devel

5. Start the main installation (use default value for answering installation)
As version 1.* is largely different with version 2.*, so we suggest install 1.7.6
/usr/bin/pecl install pecl_http-1.7.6

6. Add the following line to /etc/php.ini file
extension=http.so

7. restart apache server so the extension can be loaded
service httpd restart

——

我們有時候需要在專案中提供一個檔案上傳的功能,
讓所有的文件都可以以公開的方式讓使用者下載,
這時就需要依賴Google提供的gsutil 來處理

GSUTIL下載連結: https://developers.google.com/storage/docs/gsutil

按照以上網頁的安裝方式:
確認你的本機已經有 Python 與 Gsutil
這裡的範例是 Python 在 C:\Python27, GSUtil在 C:\gsutil

使用Google Cloud Storage, 將指定的Bucket 設定於設為公開的指令如下:
c:\Python27>python C:\gsutil\gsutil.py -m setdefacl public-read gs://mybucket_name

這樣未來透過程式上傳的的OBJECT都會是PUBLIC-READ的狀態喔

1) 安裝 AppServ
2) 安裝成功後你會在AppServ的bin資料夾中照到openssl.exe
3) 在cmd執行以下指令:

openssl req -config C:\AppServ\Apache2.2\conf\openssl.cnf -new -out C:\AppServ\Apache2.2\conf\server.csr -keyout C:\AppServ\Apache2.2\conf\server.pem

openssl rsa -in C:\AppServ\Apache2.2\conf\server.pem -out C:\AppServ\Apache2.2\conf\server.key
openssl x509 -in C:\AppServ\Apache2.2\conf\server.csr -out C:\AppServ\Apache2.2\conf\server.crt -req -signkey C:\AppServ\Apache2.2\conf\server.key -days 365

4) 在 C:\AppServ\Apache2.2\conf\httpd.conf 將
#LoadModule ssl_module modules/mod_ssl.so 的註解去掉
#Include conf/extra/httpd-ssl.conf 的註解去掉

5) 在 C:\AppServ\Apache2.2\conf\extra\httpd-ssl.conf 設定如下:
SSLCertificateFile "C:\AppServ\Apache2.2\conf\server.crt"
SSLCertificateKeyFile "C:\AppServ\Apache2.2\conf\server.key"

6) Window 鍵 + R
7) 輸入 services.msc
8) 重新啟動 Apache Server
9) 在瀏覽器輸入 https://localhost, 成功!

註: 如果PORT 443, 剛好被別的應用程式所使用, APACHE SERVER會重開失敗喔! 要怎麼知道伺服器PORT443 是否被使用? 請參考本篇文章 Windows 如何知道哪個應用程式正在使用哪個PORT?

Google Cloud Platform 開始支援PHP了!
雖然還是在BETA階段, 但還是讓人忍不住要測試一下呀~
這次的測試是使用CodeIgnitor來使用,
結合Google Cloud SQL,
在本機連資料庫MYSQL是沒問題,
但DEPLOY之後發現正式機一直沒辦法連上.
錯誤資訊如下:

A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346

查了stackoverflow之後才發現 /application/config/database.php的設定需要微調才能連到資料庫:

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '密碼';
$db['default']['database'] = '資料庫名稱';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = FALSE;
$db['default']['stricton'] = FALSE;
$db['default']['socket'] = '/cloudsql/PROJECT-ID:INSTANCEID';

最後一行的SOCKET是codeignitor預設沒有的參數,
要記得加上才能成功連線

連線之後, 你會發現網站雖然可以啟動了,
但都沒有資料!怎麼回事呢?
原來是因為他會一直預設連到localhost,
這時必須要修改mysqli的drivers.

到 application/system/database/drivers/mysqli/mysqli_driver.php 將 db_connect 取代成以下的函數:

function db_connect()
{
    if(isset($this->socket)){
        return mysqli_connect(null, $this->username, null, $this->database, null, $this->socket);
    }
    elseif ($this->port != ”)
    {
        return mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port);
    }
    else
    {
        return mysqli_connect($this->hostname, $this->username, $this->password, $this->database);
    }
}

就大功告成拉!

PhoneGap Tutorial

Windows 方法

Android
1. 找到/PhoneGap/lib/android

2. 開啟「Eclipse」確定其中已安裝Android SDK,並找出安裝路徑
3. 在PATH環境變數中加入(以下的變數請按照使用者的實際環境做調整, 勿照抄):
…;/Android SDK/platform-tools;/Android SDK/tools;C:\ANT\bin;
4. 執行「cmd」,並切換路徑至/PhoneGap/lib/android/bin
5. 執行建立專案的指令:
create.bat ~/Desktop/app/HelloWorld_android com.test.HelloWorld HelloWorld

6. 從「Eclipse」建立新專案對應到剛到剛才建立的專案並測試執行

iOS專案
在Windows上建立iOS專案後還是得去MAC作打包的動作,所以乾脆直接在MAC OS建立吧。

MAC OS 方法

How to Create Android Project?
1. 終端機上
export PATH=${PATH}:/Users/username/android-sdks/platform-tools:/Users/username/android-sdks/tools

2. cd ~/Desktop/app/phonegap-2.9.0/lib/android/bin

3. ./create ~/Desktop/app/AppName_android com.test.appname Appname

————

How to Create iOS Project?

1. 終端機上
cd ~/Desktop/app/phonegap-2.9.0

2. ./create ~/Desktop/app/AppName_ios com.test.appname Appname