[★★★★] debian / ubuntu LAMP : 裝 oracle instant client / sqlplus / oci8 / apache2 config / steps by steps

2016.0202

Screenshot 2016-02-02 16.02.21

-rw-r–r–@ 1 rimmon  staff  62587782  8  2  2014 oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm

-rw-r–r–@ 1 rimmon  staff    634803  8  2  2014 oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

-rw-r–r–@ 1 rimmon  staff    852271  8  2  2014 oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

 

// 2016.0202 —-

裝 pecl/oci8 command:

pecl install oci8-2.0.10

 

 

2013.1225 added

3  apt-get install alien

6  apt-get install nfs-common

8  apt-get install sshfs

 

// —— INSTALL LAMP

apt-get install  apache2 libapache2-mod-php5 php5 php5-dev php5-gd  php5-mysql php5-memcache memcached php-pear

 

 

————————-

2011.0530 整理的 install step by step:
OS : uname -a
Linux ubuntu 2.6.38-8-server #42-Ubuntu SMP Mon Apr 11 03:49:04 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

Oracle client : 11.2 R1

google "oracle instant client download"
到 oracle 網頁找 Instant Client for Linux x86-64 / Version 11.2.0.1.0 (PS: Version 11.2.0.2.0 這版有問題)
download 這兩個
oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.rpm (47,811,007 bytes)
oracle-instantclient11.2-devel-11.2.0.1.0-1.x86_64.rpm (606,343 bytes)
用 alien 裝起來
  102  alien -i *basic*
  103  alien -i *devel*

新增這個檔 /etc/ld.so.conf.d/oracle.conf , 內容:
/usr/lib/oracle/11.2/client64/lib/

  104  cat /etc/ld.so.conf.d/oracle.conf
  105  ls -l /usr/lib/oracle/
  106  ls -l /usr/lib/oracle/11.2/client64/lib/

安裝 LAMP :
  108  export http_proxy="http://172.30.1.123:8080"
  109  apt-get install apache2 libapache2-mod-php5 php5 php5-dev php5-gd mysql-server php5-mysql

安裝 libaio 套件
  138  apt-get install libaio1

安裝 pear 套件
  112  apt-get install php-pear

安裝 pecl 的 oci8 套件
pear config-set http_proxy http://172.30.1.123:8080/

  114  pecl update-channels
  115  pecl install oci8

  117  find /etc -name php.ini
這兩個檔要加入 oci8 的 extentsion
/etc/php5/cli/php.ini
/etc/php5/apache2/php.ini

install ok: channel://pecl.php.net/oci8-1.4.5
configuration option "php_ini" is not set to php.ini location
You should add "extension=oci8.so" to php.ini <------ 加這行

跑看看測試code:

$conn = oci_connect('oracle_user', 'oracle_pass', 'ip_address/instant_id');

$stid = oci_parse($conn, "select to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') from dual" );
oci_execute($stid);

$row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
print_r( $row );

oci_close( $conn );

// ——————————–
以下是 2011.5.25 修改

   69  find / -name sqlplus -print
   70  /usr/lib/oracle/11.2/client64/bin/sqlplus
   71  cat > /etc/ld.so.conf.d/oracle.conf

   73  ls -l /usr/lib/oracle/11.2/client64/lib/

   76  vi /etc/ld.so.conf.d/oracle.conf
   77  apt-get install apache2 libapache2-mod-php5 php5 php5-gd mysql-server php5-mysql

   86  apt-get install php-pear

   91  pear config-set http_proxy http://172.30.1.123:8080/
   92  pecl update-channels

   95  pecl install oci8

2010.0630 : 今天又在 debian 裝一次 發現, 這個版本沒辦法裝 oracle-instantclient11.2.* , 所以繼續用 instantclient11.1.*

Ubuntu 安裝 RPM 要用 alien …
sudo apt-get install alien

Ref. https://help.ubuntu.com/community/HowToBuildToraWithOracle

先去 http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html

download 這幾個 files (rpm)

Instant Client Package – Basic Lite
oracle-instantclient11.1-basiclite-11.1.0.7.0-1.i386.rpm

Instant Client Package – SQL*Plus
oracle-instantclient11.1-sqlplus-11.1.0.7.0-1.i386.rpm

Instant Client Package – SDK
oracle-instantclient11.1-devel-11.1.0.7.0-1.i386.rpm

下 alien 指令安裝 rpm

alien -i oracle-instantclient11.1-basiclite-11.1.0.7.0-1.i386.rpm
alien -i oracle-instantclient11.1-sqlplus-11.1.0.7.0-1.i386.rpm
alien -i oracle-instantclient11.1-devel-11.1.0.7.0-1.i386.rpm

裝好後用 sqlplus 聯看看 , 因為我得到一個 lib error

所以我要裝 apt-get install libaio1

在 /etc/ld.so.conf.d 加一個檔 cat > /etc/ld.so.conf.d/oracle.conf

內容是 oracle lib 的 path /usr/lib/oracle/11.1/client/lib

然後

apt-get install php5

apt-get install php5-dev

因為 oci8 是由 pecl 來安裝的, 所以要 apt-get install php-pear

再來裝 oci8 : pecl install oci8

在 /etc/php5/conf.d 下建一個 oci8.ini 檔 , cat > /etc/php5/conf.d/oci8.ini 內容是

extension=oci8.so

重新啟動 apache2 :

service apache2 restart

看看 phpinfo 有沒有出現 oci8 等字樣就 ok 了

53420fcc8f6596bc2b6cd3511eae7d84
cebcda336140c38e51b889ec7f9319c3

加一個 virtual host :

在 /etc/apache2/sites-enabled 增加一個 xxx.conf 檔

CodeIgniter 需要用 rewrite module :

ls -sf /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled

wordpress 的 schema

ver 2.7:

wp_2.7

幾個查詢例:

SELECT m.* FROM  wp_posts  p , wp_postmeta m
where p.id=m.post_id
order by post_id desc


SELECT tr.* 
FROM  wp_posts  p , wp_term_relationships tr  
where p.id=tr.object_id
order by p.id desc


SELECT p.id , w.*
FROM  wp_posts  p , wp_term_relationships tr , wp_term_taxonomy t
where p.id=tr.object_id
and tr.term_taxonomy_id=t.term_taxonomy_id
order by p.id desc


SELECT p.id , w.*
FROM  wp_posts  p , wp_term_relationships tr , wp_term_taxonomy t ,  wp_terms w
where p.id=tr.object_id
and tr.term_taxonomy_id=t.term_taxonomy_id
and t.term_id = w.term_id
order by p.id desc

gentoo emerge php options

2009.0630 Monster LAMP Pack:

取消 :
ncurses pdo readline spell

增加 :
ctype json sockets
berkdb gdbm
xmlreader xmlwriter
oci8-instant-client

USE="apache2 berkdb bzip2 calendar cjk cli crypt ctype curl gd gdbm hash iconv json mysql mysqli nls oci8-instant-client pcre reflection session simplexml sockets spl ssl tokenizer truetype unicode xml xmlreader xmlwriter zlib" emerge -av php

2009.0630 發現 wordpress code 裡面有用到 token_get_all ( tokenizer 所以不能取消)

sqlrelay sample code / prepare statement / bind value 寫法

3ae0efb3712cf634d78c33a54bd460ca

include dirname(__FILE__) . '/local_config.php';
$__oradb=_fn_connect_sqlrelay();
$__oradb->setOption('portability', DB_PORTABILITY_LOWERCASE);

$sql = '
select g_no,ctrl_rowid,g_storage,g_img
from goods_file
where g_no=?
';

foreach ( $items as $g_no => $v ) {
  $prepare = $__oradb->prepare($sql);
  $result = $__oradb->execute($prepare,$g_no);
  if ( $result ) {
    $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
    $items[ $g_no ]['ctrl_rowid'] = $row['ctrl_rowid'];
    $items[ $g_no ]['g_storage'] = $row['g_storage'];
    $items[ $g_no ]['g_img'] = $row['g_img'];
    $result->free();

  } else continue;
}
$__oradb->disconnect();

Monster LAMP Pack Lite – ver.317

Basic install emerge
lilo dhcpcd openssh syslog-ng vixie-cron screen ntp cronolog net-mail/mpack app-arch/sharutils unzip bind-tools trafshow traceroute

Linux  : 2.6.24-gentoo-r7
Apache : 2.2.10
Mysql  : 5.0.70-r1
PHP    : 5.2.8-pl2

PHP 的編法是

USE="apache2 berkdb bzip2 calendar cjk cli crypt curl gd gdbm hash iconv json mysql mysqli ncurses nls oci8-instant-client pcre readline reflection session simplexml spell spl ssl truetype unicode xml zlib" emerge -av php

package 有

samba :
postfix :
oracle instant client :
open-vm-tools : vmware 的 tools

emerge 這些 package:

重要軟體:
mysql php apache postfix

中等重要:
screen ntp samba

工具類軟體:
subversion vim open-vm-tools cronolog net-mail/mpack app-arch/sharutils unzip

記得

  • /etc/udev/rules.d/70-persistent-net.rule 砍掉
  • 改 net_DHCP
  • 砍 /tmp/*
  • check /etc/conf.d/clock , /etc/hosts , /etc/resolv.conf

Hypertext Transfer Protocol — HTTP/1.1 – 這可是現今最偉大的 protocol 呀!

The Hypertext Transfer Protocol (HTTP) is an application-level
protocol for distributed, collaborative, hypermedia information
systems. It is a generic, stateless, protocol which can be used for
many tasks beyond its use for hypertext, such as name servers and
distributed object management systems, through extension of its
request methods, error codes and headers
http://tools.ietf.org/html/rfc2616

Status Code Definitions
http://tools.ietf.org/html/rfc2616#section-10

204 No Content

The server has fulfilled the request but does not need to return an
entity-body, and might want to return updated metainformation. The
response MAY include new or updated metainformation in the form of
entity-headers, which if present SHOULD be associated with the
requested variant.

If the client is a user agent, it SHOULD NOT change its document view
from that which caused the request to be sent. This response is
primarily intended to allow input for actions to take place without
causing a change to the user agent’s active document view, although
any new or updated metainformation SHOULD be applied to the document
currently in the user agent’s active view.

The 204 response MUST NOT include a message-body, and thus is always
terminated by the first empty line after the header fields.

可以利用這點作一些事, 譬如記錄 user 的訪問, log 等等

PHP Coding Standards

參考: Mantis : http://www.mantisbt.org/guidelines.php

中文翻譯: http://www.ichiayi.com/wikipage/tech/mantis_coding

First, start off by reading the PHP Coding Standards document. I’ve deviated in a few places but just about everything in the document applies here as well.

Above all, write code that is easy to read and maintain. Comment blocks of code and functions at all times. And get on my case if I deviate too much as well!

Naming Variables
  • Use all lower case.
  • Use _ to separate words, e.g. $green_color_value
  • Use descriptive names (except loop variables).
  • Loop variables can be of the usual variety: $i, $j, $k, etc.
  • Count variables should follow the format $*_count, e.g. $bug_count
  • Global variables should be prefixed with g_
  • Temporary variables should be prefixed with t_
  • Parameters and variables passed from forms that have been cleaned of any special SQL chars (i.e. slashes) should be prefixed with c_
  • Uncleaned function parameters should be prefixed with p_
  • Uncleaned variables passed from forms should be prefixed with f_
  • Other variables are prefixed with v_, v2_, etc.
  • Never prefix with l_ or o_ or q_ (visually confusing)
  • $query and $result should be used for SQL query and results respectively
Naming Functions
  • Use all lower case.
  • Use _ to separate words, e.g. setup_page_breaks()
  • Keep functions to 5 words or less
  • Functions that print should be prefixed with print_.
  • Try to use prefixes to group functions (i.e., email_, news_, etc.)
Naming Classes
  • Use FirstLetterOfWordIsCaptilized style
  • Variables that are class objects should have the prefix coo_
Naming Files
  • Use all lower case.
  • Use _ to separate words, e.g. view_new_bugs_page.php
  • Use .php file extensions
  • Filenames must be less than 32 characters in length. This plays nice with older file systems like Mac OS.
  • Included files should be suffixed by _inc.php
SQL formatting
  • UPPERCASE all SQL keywords:
    $query = "SELECT *
    	FROM $g_mantis_bug_table
    	WHERE id='1'";
  • Always assign a query string to a variable. This makes code easier to debug when problems occur. Do not create the query in the call to the function.
  • Break up SQL queries over multiple lines to be easy to read.
General Formatting
  • Use TABS with a size of 4
  • Follow the table formatting of existing pages
  • Use <?php ?> for php delimiters.
  • Try not to print/echo HTML unless it’s short or in a function loop
  • Do not use the EOF construct
Miscellaneous
  • Don’t use the ?: construct except in very rare cases. It is confusing and has a lot of bug potential.
  • Avoid magic numbers. The only magic numbers in use should be 1 and 0 and their meaning should be obvious.
Page Guidelines
  • The first item should be the copyright notice
  • At the bottom will be the footer information and closing print_ functions.
Braces and Parantheses
  • Parantheses should be right after a function name, e.g. function() not function ()
  • Parantheses should have a space right after a keyword (if, while, for), e.g. for (…)
  • Formatting of braces is illustrating below. We use unmatched placing.
  • Arrays should be referenced with no spaces, e.g. $arr[‘index’] not $arr[ ‘index’ ]
    for (...) {
        blah
    }
    
    or
    
    if (...) {
        blah
    }
  • if … else blocks should be in this format:
    if (...) {
        blah1
    } else {
        blah2
    }
Comparisons
  • The NOT operator should be placed next to its operand. No spaces, e.g. !$value
  • Parentheses should be used for grouping, especially with multiple comparisons, e.g. if ( ( null == $val ) && ( null == $val2 ) )
Strings
  • Use spaces around the string concatenation operator, e.g. ‘str ‘ . $value . ‘ str2’;
  • Use ‘ instead of " if there are no variables or special characters.
Comments
  • Use the # symbol for line commenting, not //
  • Use /* */ for block commenting unless you nest /* */ comments. Generally, only use this during development.
  • Use @@@ followed by a brief message (BROKEN, TEMPORARY, etc) as a "look at this" indicator. Leaving your name next to is a good idea. This way critical items can easily be found.
Editor Features
  • Search and replace in multiple files
  • Goto line number
  • Syntax highlighting
  • Adjustable TAB spacing