Windows Firewall is enabled on your server, you will also need to adjust your firewall settings to allow FTP. The easiest way to do this is by command line.

Run command prompt as administrator

Paste the commands below according to your requirement

For open port 21 on the firewall, type the following syntax

netsh advfirewall firewall add rule name="FTP (non-SSL)" action=allow protocol=TCP dir=in localport=21

For enable stateful FTP filtering that will dynamically open ports for data connections, type the following syntax

netsh advfirewall set global StatefulFtp enable
For configure the firewall to allow the FTP service to listen on all ports that it opens, type the following syntax

netsh advfirewall firewall add rule name="FTP for IIS7" service=ftpsvc action=allow protocol=TCP dir=in

For disable stateful FTP filtering so that Windows Firewall will not block FTP traffic, type the following syntax

netsh advfirewall set global StatefulFtp disable

If Then also not work then do below from command prompt

mkdir “YourFTP Path”

ICACLS "Your FTP Root" /Grant IUSR:R /T

netsh int ipv4 set dynamicport tcp start=5000 num=5100

In IIS Manager, right-click on your server name, and enter the following port range

5000-1000
5000-5100

You can mention custom dynamic port as per your requirement. 


Wednesday, June 4, 2014

PHP Website migration tips

For Moving (or migrating) Wordpress Website

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com', 'http://www.new-domain.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

For Moving (or migrating) Magento Website

copy all of your local files to production server
dump your magento local db and import it into your production server db

editing in new server

now on your new server you need to follow these two steps:

edit app/etc/local.xml file and change database info
in new server db,in its core_config_data table, you should find every records containing the url of your local installation, then you need to update those values;which can be found with this query:

     SELECT *

     FROM `core_config_data`

     WHERE `value` LIKE 'http://%';

edit (thanks to comments):
3. Do not forget to delete var folder contents
4. it'd better if you remove the content of app/etc/use_cache.ser too

For Drupal website

Edit the file [drupal home]/sites/default/settings.php path and edit at the section where you enter the database, location, username and password. You CAN enter the password either encrypted or not encrypted there.

Change “$base_url”  “$db_url”

Chmod your "files" folder so it is writeable chmod to 755

Double check your .htaccess and [drupal home] /sites/default/settings.php and make changes in case they are needed.

Clear cache and watchdog folder cleanup (empty)

Don’t forget to turn on performance caching, disable error logging to the screen and set up a cron job






Wednesday, April 9, 2014

Shell Script for Daily mysql backup

#!/bin/bash

user="root"
password="your root user password"
host="localhost"

backup_path="backup path"
date=$(date +"%d-%b-%Y")

# Get list of databases
databases=$(mysql --user=$user --password=$password -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema)")

# Create folder using date
mkdir $backup_path/$date

# Create dumps for each database
for db in $databases
do
mysqldump --user=$user --password=$password --host=$host $db > $backup_path/$date/$db.sql
done
Tuesday, April 1, 2014

how to convert existing mysql slow queries log in csv file

http://stackoverflow.com/questions/14479199/mysql-slow-queries-visualize

This is a noddy script I use to help me sort them out. Change the file name at the top and execute it. Puts the details out in CSV format so you can manipulate them easily (note, delete the 2nd line of the CSV file as it is garbage). Note that I cannot confirm whether or not the file you have is exactly the same format, but hopefully you can play with this to sort out what you need.


php
$handle = fopen('C:\\somelocation\\mysql-slow.log', "rb");
$fp = fopen('someoutputfile.csv', 'w');
$inline = '';
$inline = fgets($handle, 8192);
$OutLine = array();
$OutLine['Time'] = 'Time';
$OutLine['Timestamp'] = 'Timestamp';
$OutLine['User'] = 'User';
$OutLine['Query_time'] = 'Query_time';
$OutLine['Lock_time'] = 'Lock_time';
$OutLine['Rows_sent'] = 'Rows_sent';
$OutLine['Rows_examined'] = 'Rows_examined';
$OutLine['Database'] = 'Database';
$OutLine['SqlOut'] = 'SqlOut';
WriteOut($fp, $OutLine);
$OutLine = array();
$OutLine['Time'] = '';
$OutLine['Timestamp'] = '';
$OutLine['User'] = '';
$OutLine['Query_time'] = '';
$OutLine['Lock_time'] = '';
$OutLine['Rows_sent'] = '';
$OutLine['Rows_examined'] = '';
$OutLine['Database'] = '';
$OutLine['SqlOut'] = '';
$PossibleUse = true;
$TimeTriggeredOut = true;
$CurrentTime = '';
$CurrentDatabase = '';

while (!feof($handle)) 
{
    switch (true)
    {
        case substr($inline, 0, 8) == '# Time: ' :
            WriteOut($fp, $OutLine);
            $PossibleUse = true;
            $Timings = explode(': ', $inline);
            $CurrentTime = $Timings[1];
            $OutLine = array();
            $OutLine['Time'] = $CurrentTime;
            $OutLine['Timestamp'] = '';
            $OutLine['User'] = '';
            $OutLine['Query_time'] = '';
            $OutLine['Lock_time'] = '';
            $OutLine['Rows_sent'] = '';
            $OutLine['Rows_examined'] = '';
            $OutLine['Database'] = $CurrentDatabase;
            $OutLine['SqlOut'] = '';
            $TimeTriggeredOut = true;
            break;
        case substr($inline, 0, 6) == '# User' :
            if (!$TimeTriggeredOut)
            {
                WriteOut($fp, $OutLine);
                $PossibleUse = true;
                $OutLine = array();
                $OutLine['Time'] = $CurrentTime;
                $OutLine['Timestamp'] = '';
                $OutLine['User'] = '';
                $OutLine['Query_time'] = '';
                $OutLine['Lock_time'] = '';
                $OutLine['Rows_sent'] = '';
                $OutLine['Rows_examined'] = '';
                $OutLine['Database'] = $CurrentDatabase;
                $OutLine['SqlOut'] = '';
            }
            $OutLine['User'] = $inline;
            $TimeTriggeredOut = false;
            break;
        case substr($inline, 0, 12) == '# Query_time' :
            $Timings = explode(' ', $inline);
            //print_r($Timings);
            $OutLine['Query_time'] = $Timings[2];
            $OutLine['Lock_time'] = $Timings[5];
            $OutLine['Rows_sent'] = $Timings[7];
            $OutLine['Rows_examined'] = $Timings[10];
            $PossibleUse = true;
            break;
        case substr($inline, 0, 14) == 'SET timestamp=' :
            $Timings = explode('=', $inline);
            $OutLine['Timestamp'] = $Timings[1];
            $PossibleUse = true;
            break;
        case $PossibleUse AND substr($inline, 0, 4) == 'use ' :
            $Timings = explode(' ', $inline);
            $CurrentDatabase = $Timings[1];
            $OutLine['Database'] = $CurrentDatabase;
            $PossibleUse = false;
            break;
        default;
            $OutLine['SqlOut'] .= $inline;
    }
    $inline = fgets($handle, 8192);
}
fclose($fp);
fclose($handle);

function WriteOut($fp, $OutLine)
{
    foreach($OutLine as &$aOutLine)
    {
        $aOutLine = str_replace("\n", " ", $aOutLine);
        $aOutLine = str_replace("\r", " ", $aOutLine);
        $aOutLine = str_replace("\t", " ", $aOutLine);
    }
    fputcsv($fp, $OutLine);
}
?>
Wednesday, March 5, 2014

Ioncube Loader & Zend Guard Loader with php



Ioncube Loader:

Download and Install
Code:
wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz

1. Unzip / Untar
Code:
tar -zxvpf ioncube_loaders_lin_x86.tar.gz

2. Move ioncube into /usr/local/lib
Code:
sudo mv ioncube /usr/local/lib/


3. Adding zend_extension = "/usr/local/lib/ioncube/ioncube_loader_lin_5.3.so" at the end of your php.ini
Code:
vi /etc/php.ini

4. Restart your Apache service
Code:
service httpd restart

Zend Guard Loader


Notes on installing zend optimiser for PHP 5.3:

CentOS 6.2

Download attachment below and upload it into your server:

Code:
tar -xf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
Code:
cd ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/
Code:
mkdir -p /usr/local/php/

Code:
cp ZendGuardLoader.so /usr/local/php/

Code:
vi /etc/php.ini

## at the end of your php.ini , right after Ioncube Loder... put the following line:
## zend_extension = "/usr/local/php/ZendGuardLoader.so"

## save and exit :OX ctrl+O ctrl_X

## service httpd restart

## verify php has loaded the zend loader

## php -m

you'll see
PHP Code:
[Zend Modules]
Zend Guard Loader