顯示具有 php 標籤的文章。 顯示所有文章
顯示具有 php 標籤的文章。 顯示所有文章

星期六, 1月 03, 2015

「Linux」架設 RSS 伺服器

自從 google reader 掛了後,
用了 其他 rss 服務(feedly...) 就再也找不到 以前那種使用習慣的感覺了。

前往官方網站 tt-rss 下載他的專案, 系統需要 php 5.3以上 
解壓縮在 你的 web 伺服器 設好自己的目錄,
前往 <www.xxx.xxx>/<project>/install 即可進入安裝畫面,
需要事先建立好 要給他運作的 資料表,按照安裝畫面填寫,
很容易就可以安裝成功。

之後 需要在手機APP 看自己伺服器的RSS ,
丟到 plugins 的資料夾 plugins/fever  之後 開啓 fever


設定個人密碼:


開啓第三方 API:


server 路徑 要設定 <www.xxx.xxx.xx>/<project_name>/plugins/fever/









星期二, 7月 22, 2014

「PHP」Laravel osx 設定 .htaccess

「PHP」Laravel osx 設定 .htaccess


apache config

  1. 設定 vim httpd.conf 的 AllowOverride All
  2. sudo apachectl restart
<VirtualHost *:80>

    DocumentRoot /Library/WebServer/Documents
    <Directory /Library/WebServer/Documents>
        AllowOverride All
        Allow from all
    </Directory>

    RailsEnv development

    Alias /noteBox /Users/cake/Web_www/noteBox/public
    <Directory  /Users/cake/Web_www/noteBox/public>
        #PassengerAppRoot  /home/User/web_ror/home/public
        PassengerAppRoot  /Users/User/Web_www/noteBox
        Allow from all
        Options -MultiViews
        #RailsBaseURI /rails
    </Directory>

</VirtualHost>

Laravel 中 public/.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
%23%23%23%20%u300CPHP%u300DLaravel%20osx%20%u8A2D%u5B9A%20.htaccess%0A---%0A%0A%23%23%23%23%20apache%20config%0A1.%20%u8A2D%u5B9A%20vim%20httpd.conf%20%u7684%20AllowOverride%20All%0A2.%20sudo%20apachectl%20restart%0A%0A%60%60%60%20conf%0A%3CVirtualHost%20*%3A80%3E%0A%0A%20%20%20%20DocumentRoot%20/Library/WebServer/Documents%0A%20%20%20%20%3CDirectory%20/Library/WebServer/Documents%3E%0A%20%20%20%20%20%20%20%20AllowOverride%20All%0A%20%20%20%20%20%20%20%20Allow%20from%20all%0A%20%20%20%20%3C/Directory%3E%0A%0A%20%20%20%20RailsEnv%20development%0A%0A%20%20%20%20Alias%20/noteBox%20/Users/cake/Web_www/noteBox/public%0A%20%20%20%20%3CDirectory%20%20/Users/cake/Web_www/noteBox/public%3E%0A%20%20%20%20%20%20%20%20%23PassengerAppRoot%20%20/home/User/web_ror/home/public%0A%20%20%20%20%20%20%20%20PassengerAppRoot%20%20/Users/User/Web_www/noteBox%0A%20%20%20%20%20%20%20%20Allow%20from%20all%0A%20%20%20%20%20%20%20%20Options%20-MultiViews%0A%20%20%20%20%20%20%20%20%23RailsBaseURI%20/rails%0A%20%20%20%20%3C/Directory%3E%0A%0A%3C/VirtualHost%3E%0A%60%60%60%0A%0A%23%23%23%23%20Laravel%20%u4E2D%20public/.htaccess%0A%0A%60%60%60%0A%3CIfModule%20mod_rewrite.c%3E%0A%20%20%20%20%3CIfModule%20mod_negotiation.c%3E%0A%20%20%20%20%20%20%20%20Options%20-MultiViews%0A%20%20%20%20%3C/IfModule%3E%0A%0A%20%20%20%20RewriteEngine%20On%0A%0A%20%20%20%20%23%20Redirect%20Trailing%20Slashes...%0A%20%20%20%20RewriteRule%20%5E%28.*%29/%24%20/%241%20%5BL%2CR%3D301%5D%0A%0A%20%20%20%20%23%20Handle%20Front%20Controller...%0A%20%20%20%20RewriteCond%20%25%7BREQUEST_FILENAME%7D%20%21-d%0A%20%20%20%20RewriteCond%20%25%7BREQUEST_FILENAME%7D%20%21-f%0A%20%20%20%20RewriteRule%20%5E%20index.php%20%5BL%5D%0A%3C/IfModule%3E%0A%60%60%60%0A%0A%0A%0A

星期三, 9月 25, 2013

Arch linux Linode Web Server(Apache ,MariaDB ,PHP ,ROR)

Arch linux Linode Web Server(Apache ,MariaDB ,PHP ,ROR)

 最近租了個VPS,把EC2停掉了,也順便體驗一下什麼是開發速度極快的ROR,

在設定上還蠻麻煩的,也參考了些網路一些大大的資料。

最後可以跑 PHP 和 ROR 在同一個伺服器。

Set local

  1. vim /etc/locale.gen
  2. locale-gen

Add user(CAKE)

  1. useradd CAKE -m -s /bin/bash
  2. passwd CAKE

Pacman Update

  1. pacman -Syu
  2. pacman-db-upgrade
    • [發生無法更新時]
    • pacman-key --init
    • pacman-key --populate archlinux

Install

  1. pacman -S base base-devel
  2. pacman -S sudo
  3. pacman -S bash-completion
  4. pacman -S git
  5. pacman -S nodejs
  6. pacman -S ruby

Set Sudo User

  1. visudo
  2. [ADD username(CAKE) ]
    • CAKE ALL=ALL (ALL)
  3. [SAVE & EXIT ]
  4. 鎖住 root : passwd root -l
  5. logout

防火牆

  1. pacman -S ufw
  2. sudo ufw enable
  3. port
    • sudo ufw limit 22/tcp
    • ufw allow 80/tcp
  4. [開機啟動]
    • systemctl enable ufw.service

Mysql

  1. install MariaDB
  2. sudo systemctl start mysqld
  3. sudo systemctl enable mysqld
  4. sudo mysql_secure_installation

ROR

  1. gem install rails
    • gem install rails --no-ri --no-rdoc
    • gem update
    • [Apache]
      • [$] gem install passenger
      • [$] passenger-install-apache2-module
      • set config [apache config]
  2. gem install mysql2
  3. in your porject Gemfile file 設定套件檔案
    • 增加 gem 'mysql2' #增加mysql套件
  4. bundl e update raiils

apache config

##### IN LoadModule(load passenger_module(ror) )
LoadModule passenger_module /home/cake/.gem/ruby/2.0.0/gems/passenger-4.0.18/buildout/apache2/mod_passenger.so
PassengerRoot /home/cake/.gem/ruby/2.0.0/gems/passenger-4.0.18
PassengerDefaultRuby /usr/bin/ruby

…

##### VirtualHost and Alias(set php alias and ror alias)
<VirtualHost *:80>

DocumentRoot /srv/http
<Directory /srv/http>
    Allow from all
</Directory>

Alias /_test2013/ /home/cake/web/
<Directory "/home/cake/web/">
    Options Indexes
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

RailsEnv development

Alias /home /home/cake/web_ror/home/public
<Directory  /home/cake/web_ror/home/public>
    #PassengerAppRoot  /home/cake/web_ror/home/public
    PassengerAppRoot  /home/cake/web_ror/home
    Allow from all
    Options -MultiViews
    #RailsBaseURI /rails
</Directory>

</VirtualHost>

ROR create DB

  1. rails g model YOUR_MODEL_NAME name:string phone:integer birthday:date
  2. db/migrate/20130923065726_create_pbooks.rb
    • 為模組設定檔
  3. app/models/pbook.rb
    • 模組端
  4. rake db:migrate # (建立)模組設定檔

---- 2014 01/10 UPDATE ----

Mac ROR 設定 以及 別名設定

Apache config

<VirtualHost *:80>

DocumentRoot "/Library/WebServer/Documents"
<Directory /Library/WebServer/Documents>
    Allow from all
</Directory>

Alias /_test2014/ /Users/cake/www_web/php_web/
<Directory "/Users/cake/www_web/php_web/">
    Options Indexes
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

RailsEnv development

Alias /ruby_blog /Users/cake/www_web/ror_web/blog/public
<Directory  /Users/cake/www_web/ror_web/blog/public>
    PassengerAppRoot  /Users/cake/www_web/ror_web/blog
    SetEnv RAILS_RELATIVE_URL_ROOT /ruby_blog
    Allow from all
    Options -MultiViews
    #RailsBaseURI /rails
</Directory>

</VirtualHost>


ROR routes your Application add

  scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do    # get "home/index" => "home#index"    resources :home     # resources :another_controller  end



Myapp::Application.routes.draw do
  scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
    resources :controller
   resources :another_controller
   match 'welcome/', :to => "welcome#index"
   root :to => "welcome#index"
end end


### 2014 01 22 update
如果使用 ubuntu 設定時
1. 將 passenger 設定資料 建立檔案 放入 /etc/apache2/modes-available/ 並且建立連結到 mods-enabled
     # ln -s /etc/apache2/modes-avaliable/ror.load /etc/apache2/modes-enabled/ror.load
2. 虛擬目錄設定 放入 sites-available 同樣建立捷徑至 sites-enabled
3. 也可以使用 sudo a2ensite XXXXX 建立捷徑
4. sudo apache2ctl configrtest  測試是否有誤
5. sudo apache2ctl restart

PS  如果發生 403 錯誤,則/etc/apache2/apache.conf 註解掉
<Directory />
...
</Directory>







星期四, 4月 11, 2013

「veryLittlePHP」 CREATE DB MODLE

「 My Framework API 」

糟糕,自己寫的鬼框架都記不住了  。 :(

關於自動判別 insert or update DB 函數

特色:
1.提供自動判別 INSERT AND UPDATE
2.DATALIST儲存值 KEY 自動過濾

1.繼承 cx_db
2.在 __construct() 設定 Drives ( mysql or mssql)
3. $this->autoSave( $TableName , $Pk , $DataList  );

$TableName  :  表名稱
$Pk : pk主鍵
$DataList :  儲存資料陣列
      + 結構: $DataList[  {欄位名稱}  ]  =  {儲存的值} ;


範例:
<?php
class mod_file extends cx_db{
    var $mTableName = 'sign_up_file';
    public function __construct( ) {
        $this->setDrives('mysql');
        parent::__construct( );
    }

    public function getFileDataByXno($_year , $_sid){
        $this->mConn->setCxTitle( "mod_file::getFileDataByXno 取得教師服務資料" );
        $_sql = "SELECT * FROM sign_up_file where year=? and sid=? ;";
        return $this->sqlExec( $_sql, array($_year, $_sid )  )->getArray(0);
    }

    public function saveFile($_arr){
        $this->mConn->setCxTitle( "mod_file::saveFile 寫入資料" );
        //檢查 是否有資料
        $_uFData = $this->getFileDataByXno($_arr['year'] , $_arr['sid']);

        if($_uFData == null or $_uFData == false or $_uFData == ''){
            // "insert";
        }else{
            // "update";
            $_arr['id'] = $_uFData['id'];
        }

        return $this->autoSave( 'sign_up_file', 'id', $_arr );
    }

}
?>

星期三, 7月 04, 2012

「PHP CI」Form Validation

關於CI的單表驗證
網站介紹的很詳細:http://codeigniter.com/user_guide/libraries/form_validation.html


1.建立規則


$config=array(  //設定驗證規則
         array(
         'field'=>'name',  //input的name
         'label'=>'帳號',     //設定名稱,在輸出錯誤訊息時出現的名稱
         'rules'=>'trim|required|min_length[4]|max_length[23]|xss_clean'  //驗證使用的規則
           ),
         array(
          'field'=>'passwd',
          'label'=>'密碼',
          'rules'=>'required|min_length[4]|max_length[25]|md5'
           ),  


2.設定規則
$this->CI->form_validation->set_rules($config);  
3.頁面POST回傳是否正確
$this->CI->form_validation->run()

他提供相當多的驗證規則,相當方便,可以少寫很多CODE。



星期五, 3月 02, 2012

「archLinux」 Postfix 使用 Gmail smtp

最近需要用到 MailServer ,以前也沒有這個經驗,
純粹是PHP smpt 寄信速度的問題,最後選擇了 postfix。
文章參考
  1. http://sherlock.heroku.com/blog/2012/02/03/setting-up-postfix-to-use-gmail-as-an-smtp-relay-host-in-archlinux/ 
  2. archLinux WIki Postfix
「安裝 postfix」

    #pacman -S postfix

「設定」在 /etc/postfix/main.cf   加入

    # 設定 gmail
    relayhost = [smtp.gmail.com]:587

    # 啟用 tls 認證
    smtp_use_tls=yes

    # use sasl when authenticating to foreign SMTP servers
    smtp_sasl_auth_enable = yes

    # 設定密碼路徑
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

    # list of CAs to trust when verifying server certificate
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

    # eliminates default security options which are incompatible with gmail
    smtp_sasl_security_options =

 「建立」在 /etc/postfix/sasl_passwd  (即密碼檔案路徑)

     [smtp.gmail.com]:587  username:password

 「執行」建立資料庫檔案

    # postmap /etc/postfix/sasl_passwd

 「啟動服務」

    # rc.d start postfix

 「CodeIgniter」 使用 Email 類別

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

    $config['protocol'] = 'sendmail';

    $config['mailpath'] = '/usr/sbin/sendmail';

    $config['charset'] = 'UTF-8';

    $this->email->initialize($config);

星期三, 12月 15, 2010

「YII」關聯 relations 和 CGridView

在資料上設定關聯

public function relations()
{
'types'=>array(self::BELONGS_TO, 'Commodity',
'type','alias'=>'category',
'joinType'=>'LEFT JOIN',
),
........


在呼叫search() 函數中加入

$criteria->with = array('types',);


之後設定VIEW

$this->widget('zii.widgets.grid.CGridView', array(
....
'types.name',
....
);


自定 name 和 value 可以加入array

$this->widget('zii.widgets.grid.CGridView', array(
array(
'name'=>'Type',
'value'=>'date("Ymd",strtotime(".$data->time. 00:00:00")).$data->id',
),
'types.name',
....
);

最後 要插入自己的變數 在ARRAY 變數除了用$data->之外 還要用 "."這個該死的東西,
第一次用 根本不曉得要加。

星期日, 12月 05, 2010

「YII」CJuiDatePicker 筆記

YII 實在是太強了!!!
CJuiDatePicker 日期的widget,封裝了jquery UI 的 DatePicker,
使用上 會發現有問題 就是跑不出來,需要在中間加入
'htmlOptions' => array('name'=>'YOUR NAME',),

$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'cakexdp',
'flat' => true,//不使用隱藏
'htmlOptions' => array('name'=>'cakexdp',),//再多加入才不會有錯誤
'options'=>array(
'showAnim'=>'fold',
'altFormat'=>'yy-mm-dd',//設定格式
'dateFormat' => 'yy-mm-dd',//設定格式
//onSelect 爲 DatePicker 的方法。
'onSelect'=>'js:function(dateText, inst){alert(dateText);}',
),
));
echo "</div>";//最後需要加上 /DIV 沒加入 會有問題。


。。。

星期六, 12月 04, 2010

「YII」隱藏 index.php

YII 是個非常酷的PHP網頁框架,只是那個 index.php 越看越不順眼。

「參考」http://bbs.php.la/thread-323-1-1.html
「參考」http://blog.jsdan.com/20


在 /your project file/config/main.php 中,
需要在 urlManager 陣列中加入資料

'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
.......
),

在 .htaccess 加入 規則

Options +FollowSymLinks
IndexIgnore */*
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


Linux Apache2 需啟動 rewrite

sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart


設定 httpd.conf ,中加入
sudo vim /etc/apache2/httpd.conf

<directory /var/www/xxxxxxxx >
AllowOverride all
</directory>

星期四, 4月 08, 2010

【網路空間設定】

最近作專題,需要用到一些在PHP.INI 裡面設定路徑,
然而 空間是免費的所以很多都沒有辦法條....


ini_set("display_errors",1);//可以顯示錯誤

set_include_path( "/...../pear_data/PEAR");//裡面填 需要用的路徑


星期六, 4月 03, 2010

【fancybox】AJAX來進行POST傳送

html 裡面的href 在網址的最後面
 放入#1 意思就是 $_POST['selector'] = 1

【html】
<a href="http://.../SummaryView/#1" class="adinfo2">
title="摘要"&gt;顯示摘要</a>
</code>

【JS】
<script type="text/javascript">
...
$(".adinfo2").fancybox({
ajax : {
  type: "POST"
}
});
....
</script>


【PHP】
//使用 selector 接收
echo $_POST['selector'];
?>