Skip to main content
I try to write down as much useful systems administration info as I have time to.

"Customers who bought this product also purchased" extension, magento 1.6+ compatibility fix

To install Customers who bought this product also purchased extension for magento 1.6+, we need to apple a few fixes.

1st Fix. This will make this extension 1.5+ compatible.

app/code/local/Jain/Bought/etc/config.xml

How to install APC on CentOS and DirectAdmin

cd /usr/local/src
mount -o remount,exec,suid /tmp
yum install autoconf
yum install php-pear
yum install php-devel
yum install httpd-devel
yum install pcre-devel
wget wget http://pecl.php.net/get/APC
tar xvfz APC-VERSION.tgz
cd APC-VERSION
phpize
whereis php-config

This will give you the location of php-config, which you will put after --with-php-config=

Flush or Clear out Exim mail queue

Exim mail queue can get out of control. If your var is on a separate smaller sized partition it can quickly run out of space.

We can see what's using up all that space via:

cd /var
du -sh * | sort -n

and as with Exim, our culprit location should be:

/var/spool/exim/input

So to quickly clear out the exim mail queue we do the following:

cd /var/spool/exim/;rm -rf input msglog;/scripts/eximup --force

And that should do it.

Flush MySQL log-bin data and disable binary log files

If your disk is starting to run out of space due to an excess of mysql-bin.XXXXXXXX files here's what to do to fix that.

vi /etc/my.cnf

under 'log-bin=mysql-bin' (the destination could be different in your my.cnf) put:

expire_logs_days = 10

Change 10 to whatever you're comfortable with.

or you can simply disable the binary log files by uncommenting the line:

# log-bin=mysql-bin

You'll also want to remove all the excessive binary log files like so:

mysql -u root -p -e "PURGE BINARY LOGS BEFORE '2012-02-15 09:00:00';"

How to install Apache Solr 3.5 for Drupal 7

First we'll need to install Java 1.6 JDK, and be on PHP 5.2 or higher (You can check my PHP installation tutorial here. Also I'm on CentOS.

Install Java 1.6 JDK

yum install java-1.6*

Install Apache Solr

We're going to install Apache Solr into /usr/local/share; however you can install it somewhere else if you'd like (e.g. install it in the root dir / )

cd /usr/local/share

Download Apache Solr. We're going to use the latest version at the time of this writing: Apache Solr 3.5. Look for the latest version here: http://www.apache.org/dyn/closer.cgi/lucene/solr/

Magento Google Analytics goals setup

Ok... let's get right into it...

We'll assume you already have google analytics setup and working with magento...

So... we want to add Google Analytics Goals so we can track what people are doing at the different steps of checkout.

Alright... here we go...

  1. Log into your Google Analytics account
  2. Click "Admin" at the top right (of the new version of Google Analytics)
  3. Click the name of your domain
  4. Click "Goals" tab--towards the middle of page
  5. Click one of the non used "+ Goal" links
  6. Now we fill in all the info...

Update CentOS / DirectAdmin Server with custombuild 2.0

Here is how to use latest version of custombuild 2.0 . The commands for custombuild 2.0 are basically identical to custombuild 1.1 and 1.2, so all this stuff should look familiar.

Notice: At the time of this writing (2012-03-14) custombuild 2.0 doesn't support upgrading from php 5.2 to 5.4. If you're upgrading from php 5.2 to 5.4 please use custombuild 1.2.

cd /usr/local/directadmin
wget http://files.directadmin.com/services/custombuild/2.0/custombuild.tar.gz
tar xvzf custombuild.tar.gz
cd custombuild
./build

edit options.conf file, selecting whatever you want to upgrade and what version numbers... then run:

./build update_data

Drop all tables in MySQL via SSH

create a new file called 'drop_all_tables.sh'

vi drop_all_tables.sh

Magento can't reindex data through admin

If you're trying to reindex data under "Index Management" but can't, do the following to fix the problem...

in SSH.

rm -rf var/locks/*

Now try again, and you should be successful

If that doesn't work, also make sure the var/locks dir is writable.

chmod -R 777 var/locks

How to place drupal blocks anywhere in content.

If you're looking to place a block anywhere inside your content, simply do the following:

go to /admin/build/block

select the block you want to insert into your content to get the proper block references...

e.g. I created a custom views block called "latest_news" which, if you click it's url looks like:
/admin/build/block/configure/views/latest_news-block

so basically, you'll use "views" at the beginning of the function reference and "latest_news-block" at the end:

Drupal 7 method

Menu block

How to install safe-rm.

So, you're worried about accidentally wiping out your entire system or important directory by doing something like rm -rf / or rm -rf *

with safe-rm , it won't allow you to do that, you'll get something like:

$ rm -rf /
Skipping /

Here's how to install:

cd /usr/local/src
# get latest version here: http://www.safe-rm.org.nz/
wget http://launchpad.net/safe-rm/trunk/0.8/+download/safe-rm-0.8.tar.gz
tar xvfz safe-rm-0.8.tar.gz
cd safe-rm-0.8
# find out your $PATH;
echo $PATH # most systems should include /usr/local/bin, if not then select any other listed
cp /bin/rm /usr/local/bin/rm
mv /bin/rm /bin/rm-01
cp safe-rm /bin/rm
vi /etc/safe-rm.conf

httpd causing high CPU load in CentOS / DirectAdmin

If you did TOP in ssh, and noticed httpd process has a high cpu load, and has been running for a long time (e.g. over 5 minutes) then you might try lowering your MaxRequestsPerChild.

vi /etc/httpd/conf/extra/httpd-mpm.conf

Now change your MaxRequestsPerChild from 1000 to 20...

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers      10
    MaxSpareServers      20
    ServerLimit         812
    MaxClients          812
    MaxRequestsPerChild   20
</IfModule>
service httpd restart

Display file attachment information in Drupal

Here's a code snippet for Drupal to add filefield data to any node or block.

Basically this is used to pull information from a CCK filefield.

<?php

function downloads_files($nid) {
 
$node = node_load(array('nid'=>$nid));
 
$output_title = $node->title;
 
$output_file_url = $node->field_pdf_file[0]['filepath'];
 
$file_size = $node->field_pdf_file[0]['filesize'];
 
$output_file_size = format_size($file_size);
 
 
 
  return
'<a href="/'.$output_file_url.'">'.$output_title.' ('.$output_file_size.') <br /> <strong class="more">Download</strong></a>';
}

?>

Magento upgrade to 1.5.x or 1.6.x

UPDATED: 2012-03-16

As many magento users will know, Magento is no fun to work with-- mainly due to poor community support (the developers help paying customers; i.e. Magento Enterprise ... Only payed support there... Great for business but bad for the average or beginning user...)

Anyhow...

So here's how we do it.

MAKE A BACKUP!

You can skip this step all together, however, please make a backup of everything prior to beginning the upgrade.

Create a test environment somewhere on your server (preferably away from your production installation)

How to get 3TB HDD to work with NVIDIA motherboards

If you recently tried installing a 3TB Hard Drive you'll notice that only about 1/3 of the drive is recognized by Windows. The fix is quite simple:

1. Download NVIDIA nForce Drivers 15.58 or later
2. Install the NVIDIA NFORCE 15.58 drivers and reboot your system after the install is done.
3. You're done. Your PC should be able to see the entire 3TB drive (it should be around 2.72TB)

How to fix Traktor not keeping play count or mp3 comment changes

So... Here I was playing sets on my new Traktor S4 on my 2010 iMac, and noticed that Traktor was acting weird--comments were getting erased, ratings were disappearing, play counts weren't being kept. In other words,Traktor's explorer worked on some files and not others.

I tried changing file permissions, reinstalling Traktor, etc... nothing solved the problem... Doing research didn't show me any concrete solutions (e.g. change the play count settings; this didn't work).

Then it occurred to me, I haven't defragmented my Windows PC in over 2 months. And a few weeks before, I had my windows PC sync all my mp3 files to my iMac.

So long story short, the mp3 files were messed up ("garbage at the end of file")...

The solution

How to uninstall multipletablerates from magento

Multiple Table Rates (aka multipletablerates) was a very popular extension in the magento 1.3 and earlier days... However, after several magento versions this extension basically became completely unstable/buggy (this is normal as it only lists magento 1.1 compatability)... Even so, it still worked on magento 1.3 with a few minor bugs... Then later down the road other extensions came up (mostly paid) that provided similar functionality, plus some, and minus the bugs...

Magento Catalog Price Rules bugs

Magento's "Catalog Price Rules" was always a buggy experience, ever since magento 1.3... I don't know what's going with the development, but it's still buggy up to 1.4.1 ...

So here are a couple of fixes I found.

Magento 1.4.0.1:

source: http://www.magentocommerce.com/boards/viewthread/194930/#t245120

1. Open up Observer.php in /app/code/core/Mage/CatalogRule/Model/
2. Find the dailyCatalogUpdate() method
3. At the end of the method, before “return $this;”, add:
$this->applyAllRules( $this );
4. (Not sure if this step is necessary) Open up /app/code/core/Mage/CatalogRule/etc/config.xml
5. Find the crontab > jobs > catalogrule_apply_all area
6. Change
<cron_expr>0 1 * * *</cron_expr>

Repair and Optimize MySQL databases in SSH

SSH repair and optimize all MySQL databases:

/usr/bin/mysqlcheck --repair --all-databases --password
/usr/bin/mysqlcheck --optimize --all-databases --password=xxxxxx

Import/export MySQL in SSH

Export:

mysqldump -u USERNAME -p DATABASENAME > backupfile.sql

Import :

mysql -u USERNAME -p DATABASENAME  < backupfile.sql

Connect:

mysql -uusername -p DATABASENAME

Disable scroll wheel zoom in Firefox

This is probably an annoyance for all those that use keyboard CTRL commands (like, CTRL-C and CTRL-V) and accidentally keep hitting CTRL + mouse scroll wheel, which zooms in and out, or enlarges and decreases text size in your browser...

Here's how to disable that in firefox...

Firefox:

In your address bar, type in

about:config

search for

mousewheel.withcontrolkey.action

Change the value to "0"

Restart your browser, and you're all set.

Google Chrome

Nothing available at the time of this writing...

Magento default sort order

In order to specify the default sort order of the product listing open up your 'catalog.xml' (this is tested in magento 1.4): desc To order products by a specific order, e.g. to order products by the order specified under category listing: set in your admin: yoursite.com/admin/system_config/edit/section/catalog/
Product listing sort by: Best Value
And for those wondering where 'category products' is... it's located here: /admin/admin/catalog_category/ (under "Category Products" tab, when you click on any category)

How to add free shipping notice on product listing and product view in Magento

NOTE: This tutorial assumes you're using an extension that uses the "special_shipping_group" attribute... But you can also use this tutorial to output any attribute you'd like into the product view and product listing.

Ok... Say you're using the "special_shipping_group" attribute, to specify which products should receive free shipping.

You would, for example, add an attribute called: FREE SHIPPING

Make sure you also set this visible under product listing, and product view, or else it won't display.

Magento Featured Products Listing on Home Page

There are a few articles and extensions I've come across showing how to add "Featured Products" on the home page of Magento. The problem is that none that I have read, seem to fully tackle the issue of being compatible with Magento 1.4.x (Magento 1.4.0.1 at the time of this writing) AND fully using Magento's features while being fairly easy to implement (i.e. without adding complicated, unnecessary,redundant or outdated code)

Magento 1.4 toolbar error (How to properly upgrade to Magento 1.4)

In case you upgraded to magento 1.4, and noticed that your category listings that require pagination (page 1, 2, 3) no longer show, here's the fix...

1. copy the new 1.4 toolbar.phtml from

app/design/frontend/base/default/template/catalog/product/list/toolbar.phtml

and paste it into your custom theme

app/design/frontend/*/YOURTHEME/template/catalog/product/list/toolbar.phtml

(note: make sure you put this into your currently used theme directory. If you installed a theme via Admin-->System-->Design then get the name of the theme from there)

2. edit your app/design/frontend/*/YOURTHEME/layout/catalog.xml

Find:

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">

If you can't connect to magento admin after upgrade

In case you upgraded to magento 1.4 and can't connect to admin section (you get an error)...

Then do the following:

- SSH into your magento install directory.
- remove all files from ./app/code/core/Zend/Cache/

rm -rf app/code/core/Zend/Cache/*

How to remove Yoast MetaRobots from Magento

In case you want to upgrade to magento 1.4, and have Yoast MetaRobots installed, you'll have to uninstall it first, since it's not compatible with 1.4.

Here's how:

1. uninstall it from magento connect
2. Remove the config xml file from /app/etc/modules/Yoast_Metarobots.xml
3. Remove the module files and directories from /app/code/community/yoast/Metarobots/
4.Clear your cache
SSH into your root magento directory and:

rm -rf var/cache/*

5. run this SQL query (easily done in phpMyAdmin)

DELETE FROM `eav_attribute` WHERE `eav_attribute`.`attribute_code` = 'meta_robots';
DELETE FROM `core_resource` WHERE CODE = 'metarobots_setup';

You should be good to go after this...

Magento 1.4 product-name quotes are converted to html and then escaped

After upgrading from magento 1.3 to 1.4, if your product headings used quotes " " or ampersands & , then magento may convert these into HTML and then escape that HTML counterparts hence showing e.g.:

"Thermo Balance" Tub & Shower Valve Rough In Valve

like:

&quot;Thermo Balance&quot; Tub &amp; Shower Valve Rough In Valve

The fix is to go into "view.phtml" and change:

            <h1 class="product-name">
                <?php echo $_helper->productAttribute($_product, $this->htmlEscape($_product->getName()), 'name') ?>
            </h1>

to

            <h1 class="product-name">
                <?php echo $this->htmlEscape($_product->getName())?>
            </h1>

How to remove <br /> added by magento.

In case you're wondering why your product description is all spaced out, then that's because magento is adding automatic line breaks into the content description area...

To get rid of it... look for

nl2br

specifically in description.phtml you'll see

<div class="std">
    <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), nl2br($this->getProduct()->getDescription()), 'description') ?>
</div>

it should look like this after you take the nl2br out:

<div class="std">
    <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), ($this->getProduct()->getDescription()), 'description') ?>
</div>

Drupal: How to create a View that shows results only from the current node

Let's say you want to create a Views block that shows on a bunch of different pages/nodes that have multiple (imagefield) images per page, and you want the block to dynamically display ONLY the images from the particular node you're on--and not display images from other nodes.

This is how you would do it:

1. Create your view as you normally would.
2. Add "Node: Nid" under "Arguments".
3. Select "Provide Default Argument" under "Action to take if argument is not present:"
4. Select "Node ID from URL" under "Default argument type:"
5. Leave everything else as is...
6. Hit "Update" and then "Save"... and you're done.