2014年9月24日 星期三

CentOS 6.5 Upgarde PHP 5.3.3 to PHP 5.4

https://webtatic.com/packages/php54/

1.
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
2.
yum install yum-plugin-replace
 
yum replace php-common --replace-with=php54w-common
=============================================================================================================================================================================
 Package                                      Arch                                Version                                        Repository                             Size
=============================================================================================================================================================================
Installing:
 php54w                                       x86_64                              5.4.32-1.w6                                    webtatic                              2.5 M
 php54w-bcmath                                x86_64                              5.4.32-1.w6                                    webtatic                               34 k
 php54w-cli                                   x86_64                              5.4.32-1.w6                                    webtatic                              2.4 M
 php54w-common                                x86_64                              5.4.32-1.w6                                    webtatic                              1.1 M
 php54w-devel                                 x86_64                              5.4.32-1.w6                                    webtatic                              2.4 M
 php54w-gd                                    x86_64                              5.4.32-1.w6                                    webtatic                              118 k
 php54w-mbstring                              x86_64                              5.4.32-1.w6                                    webtatic                              918 k
 php54w-mcrypt                                x86_64                              5.4.32-1.w6                                    webtatic                               25 k
 php54w-mysql                                 x86_64                              5.4.32-1.w6                                    webtatic                              110 k
 php54w-pdo                                   x86_64                              5.4.32-1.w6                                    webtatic                               94 k
 php54w-pear                                  noarch                              1:1.9.4-7.w6                                   webtatic                              389 k
 php54w-tidy                                  x86_64                              5.4.32-1.w6                                    webtatic                               29 k
 php54w-xml                                   x86_64                              5.4.32-1.w6                                    webtatic                              145 k
Removing:
 php                                          x86_64                              5.3.3-27.el6_5.1                               @updates                              3.5 M
 php-bcmath                                   x86_64                              5.3.3-27.el6_5.1                               @updates                               29 k
 php-cli                                      x86_64                              5.3.3-27.el6_5.1                               @updates                              6.2 M
 php-common                                   x86_64                              5.3.3-27.el6_5.1                               @updates                              2.9 M
 php-devel                                    x86_64                              5.3.3-27.el6_5.1                               @updates                              3.0 M
 php-gd                                       x86_64                              5.3.3-27.el6_5.1                               @updates                              324 k
 php-mbstring                                 x86_64                              5.3.3-27.el6_5.1                               @updates                              2.1 M
 php-mcrypt                                   x86_64                              5.3.3-3.el6                                    @epel                                  46 k
 php-mysql                                    x86_64                              5.3.3-27.el6_5.1                               @updates                              216 k
 php-pdo                                      x86_64                              5.3.3-27.el6_5.1                               @updates                              168 k
 php-pear                                     noarch                              1:1.9.4-4.el6                                  @base                                 2.2 M
 php-tidy                                     x86_64                              5.3.3-27.el6_5.1                               @updates                               48 k
 php-xml                                      x86_64                              5.3.3-27.el6_5.1                               @updates                              307 k
Installing for dependencies:
 pcre-devel                                   x86_64                              7.8-6.el6                                      base                                  318 k
 t1lib                                        x86_64                              5.1.2-6.el6_2.1                                base                                  160 k

Transaction Summary
=============================================================================================================================================================================


2014年7月1日 星期二

CodeIgniter Installation

1. download CodeIgniter 3.0 release from github


2. extrace all the file into /var/www/html/CI



3. to remove index.php (http://127.0.0.1/Test instead of http://127.0.0.1/index.php/Test

A: modify httpd.conf, add a virtualhost with  AllowOverride All

B: in /var/www/html/CI , add a .htaccess with rewrite rule
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|assets|robots\.txt|$)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]


C: modify config.php and set index_page to blank
$config['index_page'] = '';

4. In   /var/www/html/CI/application/controllers  

add a Test.php
class Test extends CI_Controller {

        public function index()
        {
                echo 'Hello World!';
        }
}
?>

Browser : http://127.0.0.1/Test  or http://127.0.0.1/index.php/Test



5. Install Ion Auth 2

download Ion Auth 2 from https://github.com/benedmunds/CodeIgniter-Ion-Auth

copy controllers / language / libraries / models / views to /var/www/html/CI/application
rename  files to support V3 UpperCaseFirst class name


config/ion_auth.php               =>   config/Ion_auth.php
models/ion_auth_model.php         =>   models/Ion_auth_model.php
models/ion_auth_mongodb_model.php =>   models/Ion_auth_mongodb_model.php
execute sql

remember to set Selinux , httpd_can_network_connect_db
setsebool -P httpd_can_network_connect_db 1

Browser : http://192.168.1.155:8080/Auth/

and Login with default email and password

6. Add CSS / JS Folder

mkdir /var/www/html/CI/assets
mkdir /var/www/html/CI/assets/css
mkdir /var/www/html/CI/assets/javascript

make sure in the .httaccess
RewriteCond $1 !^(index\.php|images|assets|robots\.txt|$)

in the view
<link type="text/css" rel="stylesheet" href="/assets/css/test.css" media="all" />

Apache AllowOverride in Virtual Host


    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /var/www/html/default
    ServerName dummy-host.example.com
    ErrorLog logs/default-error_log
    CustomLog logs/default-access_log common
           
               AllowOverride All
           





in /var/www/html/default

[root@test-20140423 test]# ls -al /var/www/html/default/test/
總計 12
drwxr-xr-x. 2 root root 4096 2014-07-01 15:36 .
drwxr-xr-x. 3 root root 4096 2014-07-01 15:23 ..
-rw-r--r--. 1 root root   17 2014-07-01 15:36 .htaccess

[root@test-20140423 test]# more .htaccess
Options -Indexes


try to http://127.0.0.1/test/

Forbidden

You don't have permission to access /test/ on this server.


in error-log
[Tue Jul 01 15:38:37 2014] [error] [client 10.10.50.57] Directory index forbidden by Options directive: /var/www/html/default/test/
 

2014年6月16日 星期一

MySQL Performance Tunning

MyISAM


1.  Table Row_Format

http://dev.mysql.com/doc/refman/5.1/en/static-format.html

show table status

Row_format =  Fixed / Dynamic

Fixed is better for select , but the table can't contain variable-length columns (VARCHAR, VARBINARY, BLOB, TEXT)

ALTER TABLE DBNAME.TABLENAME ROW_FORMAT=Fixed

Static-format tables have these characteristics:
  • CHAR and VARCHAR columns are space-padded to the specified column width, although the column type is not altered. BINARY and VARBINARY columns are padded with 0x00 bytes to the column width.
  • Very quick.
  • Easy to cache.
  • Easy to reconstruct after a crash, because rows are located in fixed positions.
  • Reorganization is unnecessary unless you delete a huge number of rows and want to return free disk space to the operating system. To do this, use OPTIMIZE TABLE or myisamchk -r.
  • Usually require more disk space than dynamic-format tables.


2. OPTIMIZE TABLE
http://dev.mysql.com/doc/refman/5.1/en/optimize-table.html

After deleting a large part of a MyISAM or ARCHIVE table, or making many changes to a MyISAM or ARCHIVE table with variable-length rows (tables that have VARCHAR, VARBINARY, BLOB, or TEXT columns). Deleted rows are maintained in a linked list and subsequent INSERT operations reuse old row positions. You can use OPTIMIZE TABLE to reclaim the unused space and to defragment the data file. After extensive changes to a table, this statement may also improve performance of statements that use the table, sometimes significantly.

For MyISAM tables, OPTIMIZE TABLE works as follows:
  1. If the table has deleted or split rows, repair the table.
  2. If the index pages are not sorted, sort them.
  3. If the table's statistics are not up to date (and the repair could not be accomplished by sorting the index), update them.
By default, the server writes OPTIMIZE TABLE statements to the binary log so that they replicate to replication slaves. To suppress logging, specify the optional NO_WRITE_TO_BINLOG keyword or its alias LOCAL.






2014年6月15日 星期日

MySQL Status

1. Dispaly Table locks / cache hit Info


mysql> show global status like 'Table%';
+----------------------------+----------+
| Variable_name              | Value    |
+----------------------------+----------+
| Table_locks_immediate      | 71626997 |
| Table_locks_waited         | 26169971 |
| Table_open_cache_hits      | 97796908 |
| Table_open_cache_misses    | 108      |
| Table_open_cache_overflows | 0        |
+----------------------------+----------+
5 rows in set (0.00 sec)

2. Display Command (Insert/Update etc Count)

mysql> show global status like 'Com_%';
 select * from information_schema.GLOBAL_STATUS WHERE VARIABLE_NAME like 'Com_%';
 select * from information_schema.GLOBAL_STATUS WHERE VARIABLE_NAME IN ('COM_UPDATE','COM_INSERT','COM_SELECT','COM_DELETE');
+---------------+----------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+---------------+----------------+
| COM_DELETE    | 120892         |
| COM_INSERT    | 202796         |
| COM_SELECT    | 60755185       |
| COM_UPDATE    | 37150062       |
+---------------+----------------+

3. Show Process List from a Host

SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE HOST like '192.168.1.203%';


4. Show Global Query Cache status

mysql> show global status like 'Qca%';


5.  set slow_query_log  on/off

set global slow_query_log = 'on';
set global slow_query_log = 'off';


7. Show Index status from Table;

mysql> show index from DBNAME.TABLENAME;



8. show global variables;

show global variables;







2014年6月14日 星期六

mysqldumpslow


Usage :

mysqldumpslow slowlog

mysqldumpslow slowlog -s t
sort by total query time

mysqldumpslow slowlog -g "TEST"
regular expression match TEST



to display more digital in time

vim mysqldumpslow

167c167
<     printf "Count: %d  Time=%.2fs (%ds)  Lock=%.2fs (%ds)  Rows=%.1f (%d), $user\@$host\n%s\n\n",
---
>     printf "Count: %d  Time=%.6fs (%.2fs)  Lock=%.6fs (%.2fs)  Rows=%.1f (%d), $user\@$host\n%s\n\n",


Awk Samples

1.

awk -v COLUMN=2 '{ sum += $COLUMN } END { print sum}'

set 2nd to COLUMN and sum ,
after process all lines , print the sum

2.

awk -F"[()s]" -v Q=3 '{qSum += $Q} END { print qSum}'

set separater to  ( , ) , s

set 3nd to Q and sum it,
after process all lines , print the sum

3.

awk -F"[()s]" '{qSum += $3; lSum += $7; rSum += $11} END { print qSum,lSum,rSum}'
set separater to  ( , ) , s
sum 3 fileds
print them


4.

#!/usr/bin/awk -f
NR%4 == 0{
        print ARGC
        for ( k=0 ; k < ARGC ; k++) {
                print "ARGV[" k "] = [" ARGV[k] "]"
        }
}



5. regular expression


EX1 :

test.awk
#!/usr/bin/gawk -f
$0 ~ /Time:/{
        #print $0;
        match($0, /Time: ([0-9]+)/, arr)
        if( arr[1] != "")
                print arr[1];
#               print NR;
}

Search String "Time:"

Match the   Time: 140613 22:26:16   to arr
print arr[1]

Output
140613
140613
140613

#!/usr/bin/gawk -f
$0 ~ /Time: [0-9]+ [0-9][0-9]:[0-9][0-9]/{
        print $0
}

Seach String " Time:  [d]+ dd:dd:dd"

Output :

# Time: 140613 22:26:16
# Time: 140613 22:26:17
# Time: 140613 22:26:18
# Time: 140613 22:26:19
# Time: 140613 22:26:20
# Time: 140613 22:26:21