Thursday, July 5, 2012

CRON and other Linux command

-----------------linux command Start--------------------------------
chmod -R uog=rwx /var/www/html/htdocs/dev.link.in/filename.php give read wrie execute command to user,owner,group
tar xzvf filenae.tar extract file
tar czvf newfile.tar existingfile.php compress the file
cd / press enter to go to back direcotory
pwd present working direcory
ls -l list of all files and folders in current directory
chown root /var/www/html/dev.link.in/cronfile.php change the owner of the file

made a cron file

In the crontab file, there are six fields for each entry, each field separated by spaces or tabs.

* The first five fields specify when the command will be run.
* The sixth field is the command itself.

Minute - 0-59.
Hour - 0-23 24-hour format.
Day - 1-31 Day of the month.
Month - 1-12 Month of the year.
Weekday - 0-6 Day of the week. 0 refers to Sunday.


crontab -e
press i
add cron comand
* * * * * /usr/bin/php /var/www/html/dev.link.in/cronfile.php it wiil execute the command in every miniute
*/2 * * * * /usr/bin/php /var/www/html/dev.link.in/cronfile.php it wiil execute the command in every 2 miniute
*/5 * * * * /usr/bin/php /var/www/html/dev.link.in/cronfile.php it wiil execute the command in every 5 miniute

This crontab entry would run the command every 15 and 30 minutes after every hour, during the month of May:

15,30 * * 5 * /usr/bin/command

To run a backup script on just Sundays, Mondays, and Tuesdays at 2:12 AM, the entry would be:

12 2 * * 0-2 sh /root/backup.sh

To run a script at 12 minutes after every 3rd hour of every day, the entry would look like this:

12 */3 * * * sh /root/script.sh


press Esc then :wq press enter
you will exit from the vi editor
then show all cron commands
crontab -l

tail -f var/log/cron to see all cron file excution
php -f /var/www/html/dev.link.in/cronfile.php php file execution command (debug the error)
ctral z exit from executing commands


-----------------linux command End----------------------------------

Tuesday, August 3, 2010

Import a mysql database from a linux command line

restore data from a backup or to import from another MySQL server

mysql -u username -ppassword database_name < FILE.sql

mysql -u idkadm -pTryTh1sN0w idkadm_anila < /home/idkadm/BACKUPS/qry.sql


svn checkout https://svn.brickred.com/src/FHV/link.in/trunk/ /home/linkadm/public_html --username prashanta --password

Thursday, July 29, 2010

HTACCESS RULE

HTACCESS RULE

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(GET|POST)$ [NC]
RewriteCond %{REQUEST_URI} !.*\.(css|jpg|ai|doc|bin|ogg|mp3|pdf|rtf|ps|ppt|jpeg|png|gif|rar|zip|bz|bz2|gz|tar|iso|chm|z|cue|deb|rpm|ac3|au|snd|mid|midi|wav|bmp|jpe|psd|avi|mpg|mpeg|mpe|mp4|ico|rdf)$ [NC]
RewriteCond %{QUERY_STRING} !nl=1$ [NC]
RewriteRule ^(.*)$ coyotero.php [L]
RewriteRule ^pagename pagename.php (if we write http://localhost/pagename then the file pagename.php will execute internaly)
RewriteRule ^pagename.html pagename.php (if we write http://localhost/pagename.html then the file pagename.php will execute internaly)


The following permalink rewrite code should be included in our .htaccess file:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Users of XAMPP (Windows): Some versions of XAMPP do not enable mod_rewrite by default (though it is compiled in Apache). To enable it — and thus enable WordPress to write the .htaccess file needed to create pretty permalinks — you must open apache/conf/httpd.conf and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound sign at the front of the line).

AllowOverride Not Enabled
Your server may not have the AllowOverride directive enabled. If the AllowOverride directive is set to None in your Apache httpd.config file, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem. When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files. Example of enabled AllowOverride directive in httpd.config:

<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
<Directory>


-------------Start HTACCESS REWRITE RULES---------------------------
RewriteCond %{HTTP_HOST} ^petdex.com [NC]
RewriteRule ^(.*)$ http://localhost/$1 [L,R=301]

RewriteCond is the condition if url is HTTP_HOST (localhost or other like google.com) is petdex.com
^ is strating point and $ is ending point
if condition is true then RewriteRule rule will apply
^(.*)$ menas any thingh except localhost will be transfer to http://localhost/$1
$l is the value anythingh except localhost
L means last rule r=301 means comlpete redirect NC means no case
QSA means query string allowed
--------------End HTACCESS REWRITE RULES---------------------------


HTACCESS HELP LINK:
htaccess tutorial

Wednesday, July 28, 2010

AJAX And Table, Forms Example

AJAX:

AJAX stands for Asynchronous JavaScript And XML.

AJAX is a type of programming made popular in 2005 by Google (with Google Suggest).

AJAX is not a new programming language, but a new way to use existing standards.

With AJAX you can create better, faster, and more user-friendly web applications.

AJAX is based on JavaScript and HTTP requests.

The keystone of AJAX is the XMLHttpRequest object.

Different browsers use different methods to create the XMLHttpRequest object.

Internet Explorer uses an ActiveXObject, while other browsers uses the built-in JavaScript object called XMLHttpRequest.

The readyState Property

The readyState property holds the status of the server's response. Each time the readyState changes, the onreadystatechange function will be executed.

Here are the possible values for the readyState property:
State Description
0 The request is not initialized
1 The request has been set up
2 The request has been sent
3 The request is in process
4 The request is complete

Example

function createRequestObject()
{
var request_o;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
request_o = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_o = new XMLHttpRequest();
}
return request_o;
}

var http = createRequestObject();
function getTypeVal(a)
{
document.getElementById('subtype_name_before').style.display="block";
document.getElementById('subtype_name_after').style.display="none";
http.open('get', 'index2.php?option=com_helpdesk&func=HDDepartmentRelatedType&departmentid='+a.value);
http.onreadystatechange = handleType;
http.send(null);
}

function handleType()
{
if(http.readyState == 4)
{
var response = http.responseText;
document.getElementById('type_name_before').style.display="none";
document.getElementById('type_name_after').style.display="block";
document.getElementById('type_name_after').innerHTML = response;
}
}

Ajax Table Grid (ajax_table_grid) example (zip file) on mail.yahoo.com(manojavasthimca)

VSS(Microsoft Visual Source Safe) and Eclipse Integration

VSS(Microsoft Visual Source Safe) and Eclipse Integration

Open VSS software right click on dashboard
Select get latest version select folder in which we want to get copied folder’s files suppose d:\\brworks and check recursive and build tree (override working folders) then click ok. We will get latest version of dashboard in d:\\brworks folder.

Close the VSS explorer

Open eclipse and create a new workspace
File->switch workspace select D:\brworks and click ok.

Then in this workspace go to File->New->Project select PHP->PHP Project

Give project name in project name text box project will also appear in project contents portion in directory which will be disabled it will be D:\brworks\dashboard
Then click finish.

Now dashboard folder will appear in navigator which can also be viewed by window->show view->navigator

Now right click on dashboard folder go to Team->share Project this will be shared from vss. Fill the entries (vss username, vss password vss mapped folder and vss working folder i.e. BR Website)and finish the task.

Now go to File->Properties->File synchronization sync d:/brworks from htdocs’s dashboard folder

1-Available synchronizing mappings will be VSS folder which can be add by clicking
Add Folder button
Add folder dashboard with checked text box.

2-Default target folder will be (htdocs folder which can be run on server)
C:\Program Files\xampp\htdocs\idk
Or
Y:\dashboard or v:\brickred(location is \\172.16.10.22\www\brickred) or v:\blog(location is \\172.16.10.22\www\blog)

Click ok button.

There are three locations
1-Work space folder (D://BRWorks)
2-Server Folder (which may be localhost (htdocs/dashboard)) or other server with mapping to our system (this is default target folder)
3-Other is on VSS which will be created by system admin department

Note: We can make more project in a wok space.
For example htdocs folder is the workspace and floder in side htdocs are projects like dashboard, Template_Design_New, Drupal etc.

there are some steps for working in dashboard.
1) Get latest version
2) Update Status
3) Check out
4) Check in with comment
We can add a new folder or file with right click on folder->new->folder or file.
Then add it to vss (Right click on file->Team->add to VSS)

Note: Main script is on VSS. We Copied the file from VSS to local folder (for example D:/brworks). Then sync it with development server which may be
C:\Program Files\xampp\htdocs\idk OR Y:\dashboard (map network drive of development server) in right click->properties->file synchronizationin default folder we give the development server path which is mapped using map network drive.

Chart for VSS implementation with synchronization:
sync local folder to development server (htdocs or other (Y:\dashboard))
^
|
|
VSS SERVER ----> Local Folder having script from VSS


for source jammer first to set default directory->get folder we will get folder from source jammer to local direcotry


Note: if not synch then right click on root folder and do force file synchronization

Thursday, May 13, 2010

CAKEPHP

beforeRender()
Suppose you needed an array of colors to be available to every view rendered by your controller but you don't want to have to define this data in every action. Using the beforeRender() callback will allow you to do this:
function beforeRender() {
$this->set('colors',array('red','blue','green');
}

This would make $colors accessible in every view rendered by that controller. beforeRender() is called after the controller logic and just before a view is rendered.


beforeFilter()
If you define a beforeFilter in your controller, it will be executed before each action. Sometimes, that behaviour is not desired, and you want to exclude an action from the application of the beforeFilter. The following simple example gives you an idea of how to accomplish that:


// app/controllers/users_controller.php
class UsersController extends AppController
{
function beforeFilter()
{
if ($this->action != 'login')
{
// execute beforeFilter logic
}
}

function login()
{
// do login
}

function edit($id)
{
// do edit
}

function delete($id)
{
// do delete
}
}


Containable behavior:
To use the new behavior, you can add it to the $actsAs property of your model:
class Post extends AppModel
{
var $actsAs = array('Containable');
}

For example, Let's say that Post hasMany Comment, and Post hasAndBelongsToMany Tag, so to get only the post-related information, you can do the following:
$this->Post->contain();
$this->Post->find('all');

If we wanted to fetch all posts and their related tags (without any comment information), we'd try something like this:

$this->Post->contain('Tag');
$this->Post->find('all');

Containable also goes a step deeper: you can filter the data of the associated models.
If you are interested in the posts and the names of the comment authors — and nothing else — you could do something like the following:
$this->Post->contain('Comment.author');
$this->Post->find('all');


find('first', $params)
'first' is the default find type, and will return one result.

$alsoLastCreated = $this->Article->find('first', array('order' => array('Article.created DESC')));
$specificallyThisOne = $this->Article->find('first', array('conditions' => array('Article.id' => 1)));


find('count', $params)
find('count', $params) returns an integer value. Below are a couple of simple (controller code) examples:


function some_function() {
$total = $this->Article->find('count');
$pending = $this->Article->find('count', array('conditions' => array('Article.status' => 'pending')));
$authors = $this->Article->User->find('count');
$publishedAuthors = $this->Article->find('count', array('fields' => 'COUNT(DISTINCT Article.user_id) as count','conditions' => array('Article.status !=' => 'pending')));
}


find('all', $params)
find('all') returns an array of (potentially multiple) results.

function some_function() {
$allArticles = $this->Article->find('all');
$pending = $this->Article->find('all', array('conditions' => array('Article.status' => 'pending')));
$allAuthors = $this->Article->User->find('all');
$allPublishedAuthors = $this->Article->User->find('all', array('conditions' => array('Article.status !=' => 'pending')));
}


updateAll(array $fields, array $conditions)
Updates many records in a single call. Records to be updated are identified by the $conditions array, and fields to be updated, along with their values, are identified by the $fields array.

For example, to approve all bakers who have been members for over a year, the update call might look something like:

$this_year = date('Y-m-d H:i:s', strtotime('-1 year'));
$this->Baker->updateAll(array('Baker.approved' => true),array('Baker.created <=' => $this_year));


deleteAll(mixed $conditions, $cascade = true, $callbacks = false)
$conditions_itdays = array('ItineraryDay.itinerary_id' => $arrGetItineraryInfoarr['Itinerary']['id']);
$this->ItineraryDay->deleteAll($conditions_itdays);


hasMany
User hasMany Comment (user is main table and comment is table having user_id as foreign key (Comment.user_id))

We can define the hasMany association in our User model at /app/models/user.php using the string syntax as follows:

class User extends AppModel {
var $name = 'User';
var $hasMany = 'Comment';
}
?>


hasOne
Let’s set up a User model with a hasOne relationship to a Profile model.

User hasOne Profile (means user is main table and profiles is table having field user_id (profiles.user_id))

The User model file will be saved in /app/models/user.php

class User extends AppModel {
var $name = 'User';
var $hasOne = 'Profile';
}
?>


belongsTo
Profile belongsTo User (profiles.user_id means user is main table and profile table has user_id field)

We can define the belongsTo association in our Profile model at /app/models/profile.php using the string syntax as follows:

class Profile extends AppModel {
var $name = 'Profile';
var $belongsTo = 'User';
}
?>

Wednesday, December 16, 2009

Make Virtual Host in PHP

Step1:
Go to the path: C:\WINDOWS\system32\drivers\etc

Step2:
Open file hosts
for linux open vi /etc/hosts 

Step3:
Add line at bottom of file: 127.0.0.1     zend.local

Step4:
Go to the path: C:\Program Files\xampp\apache\conf\extra

Step5:
Open file httpd-vhosts.conf

Step6:
Add the following:
<VirtualHost *:80>
DocumentRoot "c:/program files/xampp/htdocs/trackingguru"
ServerName zend.local
</VirtualHost>

Step7:
Type the following URL on browser: http://zend.local/

Note:Include conf/extra/httpd-vhosts.conf file must be uncommented in file wamp/bin/apache/apache2.2.6/conf/httpd.conf

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-6