Magento 2 installation on MEMP (Mac OS X + Nginx + MySQL + PHP-FPM) stack

September 7, 2015  |  6 Comments  |  by Raj (MagePsycho)  |  Mac OS-X, Magento, Magento 2

Magento is a highly customizable e-commerce platform and content management system that you can use to build online storefronts or web sites for selling merchandise. Magento provides common e-commerce features, such as shopping carts and inventory management, and encourages extensive customization to meet your organization’s specific goals.

Magento 2 Merchant Beta codebase was released on July 15, 2015. This is a significant milestone before the general availability of Magento 2 in Q4 2015.

Before you begin installation

1. MEMP(Mac OS X + Nginx + MySQL + PHP-FPM) stack should already be installed & configured in your system. And system should meet the requirements discussed in Magento system requirements.

If MEMP stack is not installed, I would recommend homebrew package manager for installation.
2. Some Assumptions
Magento Dir: ~/Sites/opensource/magento/magento2beta
Virtual Host:

Once your MEMP system is ready meeting all the requirements, you are ready to move ahead for the installation.

Installation Steps

1. Create the project folder & clone the magento2 codebase

mkdir ~/Sites/opensource/magento/magento2beta && cd ~/Sites/opensource/magento/magento2beta
git clone .
Git Clone Magento2

Git Clone Magento2

2. Checkout to master branch

git checkout master

OR you can directly use the following command while cloning:

git clone -b master
Git Checkout Master Branch

Git Checkout Master Branch

You can clone either the master or develop branch:
– master is more stable
– develop is more recent

Initially we had an issue installating the sample data with develop branch, which resulted in the following error:

Fatal error: Call to undefined method Magento\Catalog\Model\Resource\Product\Interceptor::getWriteConnection() in app/code/Magento/SampleData/Module/Catalog/Setup/Product/Gallery.php on line 144

Sample data installation error in Magento 2

Sample data installation error

Due to recent changes, you can now use sample data with either the develop branch (more current) or the master branch.

3. File permission

chmod -R 755 ./

4. Update Magento dependencies using Composer
Install Composer if it’s not already installed:

curl -sS | php
mv composer.phar /usr/local/bin/composer

Now run Composer to update dependencies:

composer install

This command updates package dependencies and can take a few minutes to complete.

Update Magento dependencies using Composer

Update Magento dependencies using Composer

5. Install sample data before Magento installation

– Edit composer.son:
In the first section, add “minimum-stability”: “beta”, before license.

then run the following commands:

composer config repositories.magento composer
composer require magento/sample-data:1.0.0-beta

Sample Data Installation

Sample Data Installation Result

Note: You can also install sample data after Magento installaiton

Magento 2 dev team has an updated version on how to install sample data:

6: Finally install Magento System
Run following command in order to install the Magento system:

php bin/magento setup:install --base-url= \
--db-host=localhost \
--db-name=magento2beta \
--db-user=root \
--db-password=root \
--admin-firstname=Raj \
--admin-lastname=KB \ \
--admin-user=admin \
--admin-password=pass123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--sales-order-increment-prefix="ORD$" \
--session-save=db \
--use-rewrites=1 \
--use-sample-data \

To find more information on command options, please check the following url:

Magento 2 - CLI Installation

Magento 2 – CLI Installation

Magento 2 - Installation Complete!

Magento 2 – Installation Complete!

7: Installation Complete!
Now you can explore the frontend and backend.
Some Screenshots:

Magento 2 - Homepage

Magento 2 – Homepage

Magento 2 - Category Page

Magento 2 – Category Page

Magento 2 - Product Page

Magento 2 – Product Page

Magento 2 - Cart Page

Magento 2 – Cart Page

Magento 2 - Checkout Page

Magento 2 – Checkout Page

Magento 2 - Admin Dashboard

Magento 2 – Admin Dashboard

Have fun with Magento 2!

Run Magento database repair tool from CLI using Ruby’s Mechanize

June 11, 2015  |  No Comments  |  by Raj (MagePsycho)  |  Linux, Magento, Ruby

Shell Scripting which is great for task automation, falls short when it comes to web browser automation.
In case of Magento, using Shell script you can do many operations like Installation, Migration, Deployment, Backup etc. & even more. But when it comes to run the Database Repair Tool(a great tool for repairing Magento database while upgrading) it becomes trickier and complex.

Magento Database Repair Tool

Magento Database Repair Tool

While Upgrading Magento say from to, running DB repair tool for every version manually from browser is repetitive & hectic. So I thought of writing a Ruby CLI script to automate it which will be a simple command with just two parameters(DB repair Url and Magento version).

This console script is a Ruby script which uses Mechanize gem/library.

The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follows redirects, and can follow links and submit forms. Form fields can be populated and submitted. Mechanize also keeps track of the sites that you have visited as a history.

Install Ruby

Ruby comes pre-installed in Mac. If you are in other operating system please refer to the Installation Document
To test if ruby is already installed, run the following command:

ruby -v

Which will give you the output like:

ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

Install Mechanize Gem

You need to install RVM(Ruby Version Manager) first.
First install the stable version of RVM stable with ruby:

\curl -sSL | bash -s stable --ruby

Update your gems:

sudo gem update --system

Now you can instally any gems. Here we will be installing mechanize gem:

gem install mechanize

Prepare & Run the Script

After installation of Ruby, RVM and all it’s required gems, we are ready to go for coding the script.
OS: Mac OS X Yosemite 10.10.4
Ruby: 2.0
Magento Reference Database: magento[version]_vanilla

1. Prepare the Script
Copy the following ruby script to the root of your Magento Dir:
File: mage-db-repair-tool.rb

#!/usr/bin/env ruby

# Magento DB Repair tool using CLI
# Uses Ruby's Mechanize gem
# @author   Raj KB <>
# @website
# Tested on Mac OS-X 10.X

require 'mechanize'
require 'fileutils'

def checkError(page)
  if'.msg_error').length > 0
    puts "[ERROR]"'.msg_error li').each do |li|
      puts li.text.strip

def checkResult(page)
  puts "[RESULT]"'.msg_success li').each do |li|
    puts li.text.strip

def checkNotice(page)
  puts "[NOTICE]"'.msg-note').each do |note|
    puts note.text.strip

  if'.msg-note').length > 1
    puts "See log for more details"

abort "#{$0} Argument Missing" if (ARGV.size < 1)

dbRepairUrl     = ARGV[0]
mageVersion     = ARGV[1]
mageDir         = Dir.pwd
dbRepairLogDir  = "#{mageDir}/var/dp-repair-tool"

FileUtils.mkdir_p "#{dbRepairLogDir}"
fp ="#{dbRepairLogDir}/mage-#{mageVersion}-result.html", "a+")

agent =
page = agent.get(dbRepairUrl)
puts "Loading page: #{page.title}..."
form = page.forms.first

puts "Setting db repair form values..."

# Get DB value from app/etc/local.xml
xmlFile ="#{mageDir}/app/etc/local.xml")
doc = Nokogiri::XML(xmlFile)
corruptedHostname = doc.xpath('/config/global/resources/default_setup/connection/host').text()
corruptedUsername = doc.xpath('/config/global/resources/default_setup/connection/username').text()
corruptedPassword = doc.xpath('/config/global/resources/default_setup/connection/password').text()
corruptedDatabase = doc.xpath('/config/global/resources/default_setup/connection/dbname').text()

form['post_form']           = 'true'
form['corrupted[hostname]'] = corruptedHostname
form['corrupted[database]'] = corruptedDatabase
form['corrupted[username]'] = corruptedUsername
form['corrupted[password]'] = corruptedPassword

# Edit reference database credentials
form['reference[hostname]'] = corruptedHostname
form['reference[database]'] = "magento#{mageVersion}_vanilla"
form['reference[username]'] = corruptedUsername
form['reference[password]'] = corruptedPassword

#p form; exit

puts "Submitting db repair form..."
result_page = form.submit(form.button_with(:id => "button-continue"))

# Check if there is an error & exit

# Continue if there is not an error
# Check if it further requires submission
if'button#button-continue').length > 0

    # Form found again?
    puts "Submitting again..."
    form = result_page.forms.first
    result_page = form.submit(form.button_with(:id => "button-continue"))


You can also download the script from: Magento DB Repair Tool Using CLI – Ruby + Mechanize

2. Run the Script
Give script the executable permission:

cd /path/to/mage-db-repair-tool.rb
chmod +x ./mage-db-repair-tool.rb

Now, You can run the script either by using command:

ruby mage-db-repair-tool.rb <magento-db-repair-url> <magento-version>

or simply using:

./mage-db-repair-tool.rb 1702


./mage-db-repair-tool.rb 1702
Ruby DB Repair Tool Console Output

Ruby DB Repair Tool Console Output

Apart from the results shown at the console output (refer to the above snapshot), You can also check the detailed output logged in your /path/to/magento/var/dp-repair-tool/mage-[magento-version]-result.html

Bonus Tips:

If you want to make system-wide command, then copy the file to the system-wide paths like /usr/local/bin, /usr/bin, /bin etc:

sudo cp /path/to/your/mage-db-repair-tool.rb /usr/local/bin/mageDbRepairToolRb

Now you can run the command from anywhere

mageDbRepairToolRb 1702

Shall you have any issues please post a comment below and I’ll try and help you out.

Send New Product Review Notification Email

January 13, 2015  |  1 Comments  |  by Raj (MagePsycho)  |  Latest, Magento

This is probably a feature which store owner might be looking for.
As of now store owner has to check for new product reviews from Magento backend in frequent manner.

Won’t it be better if admin gets a instant email whenever a new product review is posted? So that whatever action needs to be carried out with the pending review can be done quickly. You don’t need to buy expensive extension in order to get job done. Here I will be sharing a simple trick to achieve this.

1. Crate a skeleton module(for example: MagePsycho_Reviewnotifier) and register the event: review_save_after
File: app/code/local/MagePsycho/Reviewnotifier/etc/config.xml


2. Implement the observer model
File: app/code/local/MagePsycho/Reviewnotifier/Model/Observer.php


 * Observer Model for Review Notifier
 * @author MagePsycho<>
 * @package MagePsycho_Reviewnotifier
 * Class MagePsycho_Reviewnotifier_Model_Observer
class MagePsycho_Reviewnotifier_Model_Observer
     * Send notification email when product review is posted
     * @param Varien_Event_Observer $observer
    public function reviewSaveAfter(Varien_Event_Observer $observer)
        $review = $observer->object;
        if ($review) {
            $emails     = array('', ''); #Edit admin emails
            try {
                //@todo - use configurable email templates
                $this->_sendNotificationEmail($emails, $review);
            } catch (Exception $e) {
        } else {
            Mage::log('ERROR::UNABLE TO LOAD REVIEW');

    protected function _sendNotificationEmail($emails, $review)
        if (count($emails)) {
            $product        = Mage::getModel('catalog/product')->load($review->getEntityPkValue());
            $starRatings    = array_values($review->getRatings());

            $body = 'New product review has been posted!<br /><br />';
            $body .= 'Customer Name: ' . $review->getNickname() . '<br />';
            $body .= 'Product: ' . sprintf('<a href="%s" target="_blank">%s</a>', $product->getProductUrl(), $product->getName()) . '<br />';
            $body .= 'Star Rating: ' . (isset($starRatings[0]) ? $starRatings[0] : 'N/A') . '<br />';
            $body .= 'Review Title: ' . $review->getTitle() . '<br />';
            $body .= 'Review Description: ' . $review->getDetail() . '<br />';

            foreach ($emails as $toEmail) {
                $mail = Mage::getModel('core/email');
                $mail->setToName('YourStore Admin');
                $mail->setSubject('YourStore: New Product Review');

                try {
                catch (Exception $e) {

Please leave your comments if it works for you or if you have any queries.

Debugging Tips: Filename cannot be empty

November 21, 2014  |  No Comments  |  by Raj (MagePsycho)  |  Latest, Magento


You may have seen this kind of error frequently logged in your Magento log file var/log/system.log:

Warning: include(): Filename cannot be empty in /app/code/core/Mage/Core/Block/Template.php on line xxx

This error means Magento is trying to include a template block with an empty string set as it’s template.


In order to find which template file is missing, simply edit the code in Mage_Core_Block_Template::fetchView() as:

public function fetchView($fileName)
    try {
        $includeFilePath = realpath($this->_viewDir . DS . $fileName);
        if (strpos($includeFilePath, realpath($this->_viewDir)) === 0 || $this->_getAllowSymlinks()) {
            /* edit - start */
            if (!is_file($includeFilePath)) {
                Mage::log($fileName, null, 'missing-phtml.log', true);
            /* edit - end */
            include $includeFilePath;
        } else {
            Mage::log('Not valid template file:'.$fileName, Zend_Log::CRIT, null, null, true);

    } catch (Exception $e) {
        throw $e;

You will see the missing .phtml filenames being logged. And search for that name in your layout xmls which will show you where it went wrong.
Happy Debugging!