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 

Monday, February 24, 2014

Install and Configure Webmin & Virtualmin on CentOS



Download Webmin RPM
Webmin rpms are available on its official site. Download it from there or use below command to download.
# cd /opt
# wget http://prdownloads.sourceforge.net/webadmin/webmin-1.660-1.noarch.rpm
Step 2: Install Webmin Using rpm Command
Use following command to install webmin.
# rpm -Uvh webmin-1.660-1.noarch.rpm
Step 3: Access Webmin in Browser
Webmin by default works on port 10000. Access your server on port 10000 using FQDN or IP, and login with username root and system root password.
http://IP:10000/
 

How to Start/Stop Webmin Service

Webmin provides an init script to start or stop its service. Use below commands to do it.
# /etc/init.d/webmin start
# /etc/init.d/webmin stop
# /etc/init.d/webmin restart
# /etc/init.d/webmin status

How to Change/Reset Webmin root Password

In order to change webmin root account password use following command. ( Note: It will not change your systems root password )
# /usr/libexec/webmin/changepass.pl /etc/webmin root secretpassword

How to Change Webmin default Port

If you do not want to run webmin with default port, use below steps to change the default port.
Login Webmin as root >> Webmin >> Webmin Configuration >> Ports and Addresses… you can change port there.

Using the Webmin YUM repository

If you like to install and update Webmin via RPM, create the /etc/yum.repos.d/webmin.repo file containing :
[Webmin]
name=Webmin Distribution Neutral
#baseurl=http://download.webmin.com/download/yum
mirrorlist=http://download.webmin.com/download/yum/mirrorlist
enabled=1
 You should also fetch and install my GPG key with which the packages are signed, with the commands :
 wget http://www.webmin.com/jcameron-key.asc


rpm --import jcameron-key.asc
 You will now be able to install with the command :
 yum install webmin All dependencies should be resolved automatically.

CentOS - Installing VirtualMin

Update System

First we will update the system to ensure that we have all of the latest software installed.
# sudo yum -y update

Install pre-requisites

We need to install a few things before VirtualMin will install. Type the following:
# sudo yum -y install perl

Download VirtualMin Installer

Now we need to download the VirtualMin installer. Type the following to download it:
 # wget http://software.virtualmin.com/gpl/scripts/install.sh

Installation

Now it is time to install VirtualMin. To do so, use the command below:
# sudo sh install.sh
You will be prompted with a license agreement. Press Y followed by Enter to continue.
It will begin performing several checks and installing the required components.
Once it has completed you should see a line similar to the following:
ssapi mod_ssl ruby ruby-devel rubygems perl-XML-Simple perl-Crypt-SSLeay: Succeeded.

Logging In

You are now ready to log into your VirtualMin console. To do this point your web browser to https://IP:10000/ where you will be prompted with a login screen On your first login use the username root and type in your root password.

Post Setup Wizard

Once you login you will be prompted with a Post Setup Wizard. Click Next.

You will be prompted if you would like to pre-load certain libraries. Click Yes and then Next.

You will be prompted if you would like to run ClamAV virus scanner on your server. It is suggested that you select Yes and click Next.

You will be prompted if you would like to run the SpamAssassin e-mail spam scanner. If you are not running e-mail services it is not necessary to run this. However if you are hosting e-mail it is highly advised. Click Yes and Next if you are going to use SpamAssassin, otherwise click Next.
Next you will be prompted if you would like to run MySQL and/or PostgreSQL servers. This is entirely up to you as to which database servers you will provide to your customers (if any). Select your options and click Next. You will be prompted on the following screens for password information.

Once finished, you will be presented with an 'All Done' page. Click Next.

Once the main page loads you will need to reload your configuration. Click the Re-check and refresh configuration button in the yellow box.