Wednesday, September 29, 2010

file manipulation

1) output total number of input file
awk 'END {print NR}' input_file

2) output #3 line Number of Field(NF)
awk 'NR==3 {print NF}' input_file

3) output lines that contains "INFO"
awk '/INFO/ {print}' input_file
less input_file | grep INFO

4) output lines that doesn't contain "INFO"
awk '!/INFO/ {print}' input_file
less input_file | grep -v INFO

5) output the second colum
awk -F "delimter" '{print $2}' input_file
cut -d "delimiter" -f2 input_file

6) output the first and the third colum
awk -F "delimter" '{print $1 $3}' input_file
cut -d "delimiter" -f1,3 input_file

Friday, September 24, 2010

Install Apache and PHP on Window XP

Apache: 2.2.16
httpd-2.2.16-win32-x86-openssl-0.9.8o.msi
http://www.apache.org/dist/httpd/binaries/win32/httpd-2.2.16-win32-x86-openssl-0.9.8o.msi

PHP: 5.2.14
php-5.2.14-Win32-VC6-x86.zip
http://windows.php.net/downloads/releases/php-5.2.14-Win32-VC6-x86.zip

Mysql: 5.1.50
mysql-essential-5.1.50-win32

---------------------------------------------------------------------------------------------

Apache:
1) Download and unpack
I used httpd-2.2.16-win32-x86-openssl-0.9.8o.msi
http://www.apache.org/dist/httpd/binaries/win32/httpd-2.2.16-win32-x86-openssl-0.9.8o.msi


2) Install
When you install Apache, you'll get a prompt for "Server Information." Here is the settings I used:
Network Domain: localhost
Server Name: localhost
Admin Email: (any email. real or fake)

[checked]: for All Users, on Port 80, as a Service


3) Starting/Stop Apache
After installing, Apache2 automatically starts. The GREEN icon in the System Tray means it started. The RED icon means the "Monitor Apache Servers" is running, but Apache2 isn't started.

You can easily start/stop/restart Apache and Apache2 via that icon in your System Tray. If you get "The requested operation has failed!" error while starting apache use the "Test Configuration" shortcut in the Start Menu to find the error (if the text window pops up then closes before you can read it, your config file is fine).

4) Testing
Now the ultimate test. To see if it's serving. Open your browser and head to: http://127.0.0.1/ or http://localhost/
If it shows the It works! you have your server software installed and running.

5) Configuration:
Making Apache point to your files, using Notepad open C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf (in the start-menu there should also be a "Apache HTTP Server 2.2 > Configure Apache Server > Edit the Apache httpd.conf Configuration File" shortcut) and search for DocumentRoot.

Change it from something like

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
DocumentRoot "C:/public_html"


it will locate where your HTML files and site are located, then scroll down about one page and change

Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs" >
Directory "C:/public_html >


PHP:
http://www.php.net/manual/en/install.windows.manual.php

1) Download and unzip
I select to install PHP manually, php-5.2.14-Win32-VC6-x86.zip
http://windows.php.net/downloads/releases/php-5.2.14-Win32-VC6-x86.zip

Unzip the file to C:\php

2) Configuration
Rename C:\php\php.ini-dist to php.ini and edit php.ini file for parameters:

doc_root = "C:\public_html"
extension_dir = "C:\php\ext"


Edit Apache Conf File in
C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd

add following at the begin of apache configuration file
 
LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php
PHPIniDir "C:/php"


Then Reboot Microsoft Windows system(very important)

3) Testing
Restart Apache if it is already running (if it doesn't start or you get errors, use your Apache "Test Configuration" shortcut in the Start Menu to see why).

To test your PHP simply create a test.php file in your Apache "DocumentRoot" folder (C:\public_html\ in my case). In your test.php file, type these 3 lines and then load the file in your browser like http://localhost/test.php (you should get a whole long list of php variables, settings, etc):




Mysql:
1) Download and installation for mysql-essential-5.1.50-win32
Install path is in
C:\Program Files\Mysql\mysql server5.1\

log files, databases is installed in
C:\public_html\mysql_data

start mysql using
C:\Program Files\Mysql\mysql server5.1\bin\mysqld --console

stop mysql using
C:\Program Files\Mysql\mysql server5.1\bin\mysqladmin -u root shutdown

2) Mysql server instance configuration wizard and keep use default

Hint: if you reinstall Mysql, you have to delete mysql data 1) C:\public_html\mysql_data; 2) Ran RegEdit, searched for every instance of MySQL, and deleted it from the registry.

then install again