Saturday, January 28, 2012

PHP - Yii Development

Installing Yii


1. Download the Yii Framework from http://www.yiiframework.com/
download/.
2. Unpack the downloaded file to a web-accessible folder.


To invoke the tool and have it verify the requirements for your installation, simply point
your browser to:
http://yourhostname/path/to/yii/requirements/index.php

The following screenshot shows the results we see for our configuration:



Creating a new application


To create a new application, we are going to use a little powerhouse of a tool known
as yiic that comes packaged with the framework.


For the purpose of this demo application, we will
assume the following:
• YiiRoot is the folder where you have installed Yii
• WebRoot is configured as the document root of your web server
• From your command line, change to your WebRoot folder and execute
the following:
% cd WebRoot
% YiiRoot/framework/yiic webapp demo
Create a Web application under '/Webroot/demo'? [Yes|No]
Yes
mkdir /WebRoot/demo
mkdir /WebRoot/demo/assets
mkdir /WebRoot/demo/css
generate css/bg.gif
generate css/form.css
generate css/main.css
Your application has been created successfully under /Webroot/demo.


Configuring Gii:


Before we can start using Gii, we have to configure it for use within our application.
At this point you probably know enough to guess we would do that in our main
application configuration file, protected/config/main.php. This is correct. To
configure Gii for use, open this file and add the following highlighted code to the
returned array:



return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web Application',


// preloading 'log' component
'preload'=>array('log'),


// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),


'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
//'password'=>'Enter Your Password Here',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),

),







Reference:
http://www.yiiframework.com/wiki/83/netbeans-ide-and-yii-projects/

Friday, January 27, 2012


 SSH Remote Access



1. SSH Client Version:

Sometimes it may be necessary to identify the SSH client that you are currently running and it’s corresponding version number, which can be identified as shown below. Please note that Linux comes with OpenSSH.

$ ssh -V
OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010

2. Login to remote host:

  • The First time when you login to the remotehost from a localhost, it will display the host key not found message and you can give “yes” to continue. The host key of the remote host will be added under .ssh2/hostkeys directory of your home directory, as shown below.
$ ssh -l jsmith remotehost.example.com

Host key not found from database.
Key fingerprint:
xabie-dezbc-manud-bartd-satsy-limit-nexiu-jambl-title-jarde-tuxum
You can get a public key’s fingerprint by running
% ssh-keygen -F publickey.pub
on the keyfile.
Are you sure you want to continue connecting (yes/no)? yes
Host key saved to /home/jsmith/.ssh2/hostkeys/key_22_remotehost.example.com.pub
host key for remotehost.example.com, accepted by jsmith Mon May 26 2008 16:06:50 -0700
jsmith@remotehost.example.com password:
remotehost.example.com$
  • The Second time when you login to the remote host from the localhost, it will prompt only for the password as the remote host key is already added to the known hosts list of the ssh client.
         $ ssh -l jsmith remotehost.example.com
         jsmith@remotehost.example.com password: 
         remotehost.example.com$

3. File transfer to/from remote host:

Another common use of ssh client is to copy files from/to remote host using scp.
  • Copy file from the remotehost to the localhost:
 $ scp jsmith@remotehost.example.com:/home/jsmith/remotehostfile.txt remotehostfile.txt
  • Copy file from the localhost to the remotehost:
 $ scp localhostfile.txt jsmith@remotehost.example.com:/home/jsmith/localhostfile.txt

Reference:

Thursday, January 26, 2012

Unix Cron Scheduling

1. Logfile
The log files for cron daemon can be found under any of the following file
/var/log/cron
/var/log/syslog


2. View/List Cronjobs
$ crontab -l

3. Schedule Cronjobs
a. Create the cronjob entries as mentioned in Step-4 in a textfile (cron_jobs.txt).
b. Run the following command
$ crontab cron_jobs.txt

4.Linux Crontab Format

MIN HOUR DOM MON DOW CMD
Table: Crontab Fields and Allowed Ranges (Linux Crontab Syntax)
FieldDescriptionAllowed Value
MINMinute field0 to 59
HOURHour field0 to 23
DOMDay of Month1-31
MONMonth field1-12
DOWDay Of Week0-6
CMDCommandAny command to be executed.


Reference:
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/


PHP - Send Email using GMAIL

1. Download PHPMailer from Sourceforge website

2. Extract the files to your folder.

3. Create a php file email.php with the following contents.


<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer(); 
$mail-&gt;IsSMTP(); // send via SMTP
IsSMTP(); // send via SMTP
$mail-&gt;SMTPAuth = true; // turn on SMTP authentication
$mail-&gt;Username = "username@gmail.com"; // SMTP username
$mail-&gt;Password = "password"; // SMTP password
$webmaster_email = "username@doamin.com"; //Reply to this email ID
$email="username@domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail-&gt;From = $webmaster_email;
$mail-&gt;FromName = "Webmaster";
$mail-&gt;AddAddress($email,$name);
$mail-&gt;AddReplyTo($webmaster_email,"Webmaster");
$mail-&gt;WordWrap = 50; // set word wrap
$mail-&gt;AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail-&gt;AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail-&gt;IsHTML(true); // send as HTML
$mail-&gt;Subject = "This is the subject";
$mail-&gt;Body = "Hi,
This is the HTML BODY "
; //HTML Body

$mail-&gt;AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail-&gt;Send())
{
echo "Mailer Error: " . $mail-&gt;ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>




4. Paste the following lines to class.smtp.php(Line#103 - in Connect method) inside phpmailer directory.


$host = "ssl://smtp.gmail.com";
$port = 465;


5. Open the newly created email.php in the browser.


That's it. Mission Complete.