Regular expressions

Some handy regular expressions terms

If you want to remove only specific tags from the html, you can use following regular expression. I use it along with PHP storm.

For example here is my sample code

    <a href="/samplelink/5656/565">
        <i class="fa fa-trash-o fa-2x" aria-hidden="true"></i>
    <a href="/samplelink/21112/21">
        <i class="fa fa-trash-o fa-2x" aria-hidden="true"></i>
    <a href="/samplelink/99/997"> 
        <i class="fa fa-trash-o fa-2x" aria-hidden="true"></i>

if you want to replace all a tags

<a href="/samplelink/99/997">

I will use the following code in regular expressions to find

<a href=".*?"\s*[/>]* 


Dispaly error of Yii validation

This is how we can display errors for yii validation in controller


foreach ($errors as $key=>$value)
 echo "

echo CHtml::link('Continue',array('servicecall/update','id'=>$model->servicecall_id));

Calling controller from a View in Yii

There are two ways to call a controller from a view.

$this->forward('/enggdiary/optimiseroutebygoogleapi',true, array('engineer_id'=>$isAdmin));?>






Redirecting all URLs to .com rather than .biz,, .info

I was having this problem with my current site. I have several domains like

Even the problem was Google was indexing all these pages separately and which is not good from the SEO perspective. Therefore, we

This thing is also called as CANONICAL DOMAIN

I used the following code to force all URLs to go to

RewriteBase /
RewriteCond %{HTTP_HOST} !^(www\.)?ukwhitegoods\.co\.uk$ [NC] ////This means was anything other than this pattern is fired, follow the rule

///NC means case sensitive URL
RewriteRule ^(.*)$$1 [R=301,L] ////Its a permanent redirect and LAST RULE

So now all my landing pages goes to

Extending Root Partition in Cent OS from Home directory

For all newbies, it is a common problem when we quickly run out of space (especially if you are a web developer)

Therefore, this tutorial is for users who have much space in home directory but still runs of out space in root

Help from

Make sure all your hd is ext4 formatted and you are logged in as Root

Now install the software

yum install lvm2

Firstly check the directory structure of CentOS


To reduce space from home directory type following:

lvreduce --resizefs --size -700G /dev/centos/home 

To Extend space in root directory type following:

lvextend --resizefs --size +700G /dev/centos/root 

Installing CentOS7 on Raid 1 Proliant microserver Gen8

This blog is for installing the CentOS 7 on HP Proliant Microserver Gen8. It can work on other raid devices too.

The tutorial covers the manual partition as some servers are not able to find the boot devices.

Please proceed to following steps.

First of all Go in the

Step1: Go into Bios enter BIOS (press F9 during boot)
– press CTRL+A (Service Option is hidden by default)
– select “Service Options” -> Processor Power and Utilization Monitoring -> Disable


please see for details

Also setup System Options -> SATA Controller Options -> Embedded SATA Configuration and select RAID configuration


Step2: Go to system Storage configuration by pressing F5 and in it create a RAID 1 logical drive using both the harddisks

Step 3: Now boot system and insert your centos dvd

Step4: Select Language and the version you want to install

Step5: Go in select disk section and select both the disk. At the bottom select manual partition

Step 6: Select New mount point as LVM and click on +

Step 7: Mount point is Boot and desired capacity as 512MB (make sure it is 512 MB on main screen too)

Step 8 Device Type as RAID, File System: ext4, Raid Level is Raid1

Step 9: click on update settings

Step 10: Again click on + from bottom and select new Mount point as ‘/’. Add space how much you want to allot leaving atleast 7GB. I am adding desired capacity as 215GB

Step 11: Now here Device Type is LVM, filesystem as ext4 and now click on Modify for Volume Group

Step 12: Select Raid level in this as RAID1, size policy as Fixed, name as shavg1 and save and then click on update settings

Step 13: Again click on + and now Mount point as SWAP and desired capacity as 6GB

Step 14: Select filesystem as SWAP, device type as LVM and then click on volume group and Modify

Step 15 : Select size policy as Fixed, Raid Level as RAID1 and click save.

Step 16: Check all the values again and click on done

Step 17: There will be summary of changes with top 2 as Destroy format in Red on sdb

Step 18: Accept changes and Click on Begin installation

Step 19: This will take its own time, By the time you can create your root password and create user

Step 20: Reboot the system and it should be good to go.






.htacess redirect and rewrites

I am writing this blog for a very simple usage of htaccess for redirects and rewriting the url

The first things that needs to be understand for the htaccess REWRITE and REDIRECT modules are the synstax


marks the start of line. It means anything that starts with

$ marks the end of line.

(.*) means any character within the url. This gets replaced by $1 at first occurence and $2 as second occurence

L means last code and do not execute anything after this.

R means redirect the page, so the url will be changed. However if you do not add that, it will be same.



Now here are some sample code


RewriteRule ^styles/ - [L,NC]

Now the above code means that if any url starts with style, just let it go through it. for example


RewriteRule ^resources/image/thumb/(.*)/?$ /download/file.php?id=$1&t=1 [NC,L] # Handle product requests

If any url starts with resources/image/thumb/(.*){THIS COULD BE ANY STRING}/

Go to looking for$1&t=1

Here $1 is (.*){THIS COULD BE ANY STRING}/



RewriteRule ^resources/image/(.*)/rokbox.jpg?$ /download/file.php?id=$1&mode=view/rokbox.jpg [NC,L] # Handle product requests

RewriteRule ^(.*)/$ $1.html [R,NC,L] # Permanent Move
RewriteRule ^(.*)/(.*)$ $2 [R,NC,L] # Permanent Move



To exclude a file from htaccess rule: follow this

RewriteCond %{REQUEST_URI} !^/google89b2a81fd1609a6e\.html$

Magento Order email not sent but cron job running | exception ‘Zend_Mail_Transport_Exception’ with message ‘Missing To header’ in /var/www/html/shop/lib/Zend/Mail/Transport/Sendmail.php:182

Solution 1

Are you getting following message in your magento shop /var/exception.log

2015-10-28T00:05:02+00:00 ERR (3):
exception 'Zend_Mail_Transport_Exception' with message 'Missing To header' in /var/www/html/shop/lib/Zend/Mail/Transport/Sendmail.php:182
Stack trace:
#0 /var/www/html/shop/lib/Zend/Mail/Transport/Abstract.php(337): Zend_Mail_Transport_Sendmail->_prepareHeaders(Array)
#1 /var/www/html/shop/lib/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#2 /var/www/html/shop/app/code/core/Mage/Core/Model/Email/Queue.php(236): Zend_Mail->send()
#3 [internal function]: Mage_Core_Model_Email_Queue->send(Object(Mage_Cron_Model_Schedule))
#4 /var/www/html/shop/app/code/core/Mage/Cron/Model/Observer.php(326): call_user_func_array(Array, Array)
#5 /var/www/html/shop/app/code/core/Mage/Cron/Model/Observer.php(72): Mage_Cron_Model_Observer->_processJob(Object(Mage_Cron_Model_Schedule), Object(Mage_Core_Model_Config_Element))
#6 /var/www/html/shop/app/code/core/Mage/Core/Model/App.php(1357): Mage_Cron_Model_Observer->dispatch(Object(Varien_Event_Observer))
#7 /var/www/html/shop/app/code/core/Mage/Core/Model/App.php(1336): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Cron_Model_Observer), 'dispatch', Object(Varien_Event_Observer))
#8 /var/www/html/shop/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('default', Array)
#9 /var/www/html/shop/cron.php(77): Mage::dispatchEvent('default')
#10 {main}
As you might understand that the problem is due to sender missing. But, in Magento 1.9, this is serious problem as it might stop all your order emails to stop sending. The solution is finding the order with the null email address and deleting the email_queue cron job of that order. Here are the tricks

First find the order that have no email with following command

 FROM `sales_flat_order`
 WHERE `customer_email` IS NULL

Now I recommend to update that order

UPDATE `sales_flat_order` SET `customer_email` = '*******' WHERE `sales_flat_order`.`entity_id` =YOUR_ORDER_ID ;

Now find this order in core_email_queue

select * from `core_email_queue` WHERE entity_id='YOUR_ORDER_ID'; ///Note this is not order number. 
////you can get order id from the url of admin of order

There should be 2 entries if you send yourself as well order copy

And now find the corresponding in core_email_queue_recipients

select * from `core_email_queue_recipients` WHERE message_id='MESSAGE_ID_FROM_core_email_queue'
select * from `core_email_queue_recipients` WHERE message_id='MESSAGE_ID_FROM_core_email_queue'

If you do not have message_id in core_email_queue_recipients, then you should delete it from core_email_queue


DELETE FROM core_email_queue WHERE message_id='MESSAGE_ID_MISSING_FROM_core_email_queue'

Solution 2: Quick & Dirty one

Other quick and dirty solution which I have not tried, but you can try on test server first is to

TRUNCATE core_email_queue_recipients;
TRUNCATE core_email_queue;

This should clear all your email queues but will delete the working email queues too.

Magento Cron jobs not running and no error: Flush Storage Cache

This is from post

Sometimes you can find the cron jobs for your Magento store just aren’t running, or are running intermittently even though everything has been setup correctly and there is apparently no reason for it.

Surprisingly you might find the problem is actually down to a simple caching issue with a one line code fix. Magento caches it’s cron schedule and reads this cached content on subsequent runs of cron rather than recreating the schedule each time to determine which jobs it should execute. The problem is sometimes jobs just don’t get cached despite them being configured correctly so when the time comes for them to execute nothing actually happens.

It’s worth noting that the cron schedule is cached even if all caching is disabled in admin, and the only way to clear the cached schedule through admin is to Flush Cache Storage under System->Cache Management. Unfortunately this doesn’t then cause the jobs to be correctly cached the next time cron is run.

So the fix is to simply disable the caching of the cron schedule, and don’t worry, benchmarks with caching disabled shows this to have no negative impact on site performance.

if it’s not already there. Open the copied file and find the following line inside the generate() method:
Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array(‘crontab’), null);
This is the line that initiates caching of the cron schedule, so just comment it out:
//Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array(‘crontab’), null);
Save the changes and Flush Cache Storage to clear any currently cached cron jobs and your store should now always execute properly configured cron jobs.

Google Facebook Twitter Unified social media Login in Magento

There are several paid as well as free extensions for social media login that allows you to login into magento shop. However, my idea is several options creates confusion for the user, therefore I want to use the most popular ones and that too FREE.

The first step is to download the extension. I am using the following extension

CedCommerce Social Login


Social Login Magento

After installing this extension in your magento store ( I am using magento 1.9.1), you need to obtain keys from each site

I will start with Google login First

Login into magento via gmail or Google account

Login with google in Magento

  1. Go to the
  2. Create a new project with any name
  3. In the sidebar under “APIs & auth”, select Credentials, and click the OAuth consent screen tab.
  4. Choose an Email Address, specify a Product Name, and click Save.
  5. Now in the sidebar under “APIs & auth”, select Credentials.
  6. Click on Add Credentials and select oauth2 clientID
  7. Select Web Application
  8. Fill up the details and click create
  9. In Authorized JavaScript origins enter your domain name like :
  10. In Authorized redirect URIs, enter the page location from where the account login will be called like:: OR OR
  11. You will get a Client ID and client secret. SAVE it in a notepad
  12. Now login into your magento shop backend and go in  SYSTEM -> CONFIGURATION ->CEDCOMMERCE EXTENSION->SOCIAL LOGIN
  13. Use these credentials in Social Login Google Options
  14. Give 5-10 mins for google server to update your details
  15. Now go to your magento frontend and try to login via google plus

I used the following link as guide


Login into magento via facebook account

Login with facebook in MagentoLogin with facebook in Magento

  1. First step is go to
  2. Click on add a new app and select website
  3. Name the project and click on the app
  4. Add the website URL
  5. Now click on Finish
  6. Go again to
  7. Select your app
  8. Copy the App ID & App secret. You need to enter your password to get the app secret.
  9. Copy the details and paste it to your magento backend (SYSTEM -> CONFIGURATION ->CEDCOMMERCE EXTENSION->SOCIAL LOGIN->FACEBOOK)
  10. Give 5-10 mins for google server to update your details
  11. Now go to your magento frontend and try to login via facebook
  12. Sometimes in facebook you need to submit an application and get approval to make this thing work. All these things can be managed from facebook apps page



Login into magento via Twitter account

Login Via twitter to Magento Login Via twitter to Magento Login Via twitter to Magento

  1. First step is go to
  2. Create a new app
  3. Fill in the details like domain name , description, website and call back url
  4. Click save
  5. Now copy the Consumer Key (API Key) Consumer secret to your magento backend (SYSTEM -> CONFIGURATION ->CEDCOMMERCE EXTENSION->SOCIAL LOGIN->TWITTER)
  6. Now go to your magento frontend and try to login via twitter