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

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:

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

to

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

Now...

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.

How to disable PHP 5.3 Deprecated errors

If you installed PHP 5.3, then you may have noticed many deprecated errors from older web apps and even current ones--like some drupal modules.

NOTICE: this is not a true fix, you could be ignoring critical errors by doing the following... but most likely you should be fine... though make sure you do not log errors, or your log files will quickly grow to an unmanageable size.

anyhow...

via php.ini :

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
; change this to Off if you still get errors.
display_errors = On
log_errors = Off

also, some sites may be using their own .htaccess or error_reporting... therefore you may need to go to affected ones and modify the .htaccess file and insert the following to disable PHP 5.3 ... I had to do this for really old web apps.

php_flag display_errors off
php_flag log_errors off

after your done... as always, restart apache...

service httpd restart

How to search and replace text in multiple files in linux

Here's how to replace a string of text in multiple files under a specific directory and all it's sub directories.

cd /to/directory/containing/files
find . -name '*.php' | xargs perl -pi -e "s/OLDSTRING/'NEWSTRING'/g;"

Real world example:

Let's say we want to replace the following in every .php file:

'profile', 'load_profile'

with new string

'profile_load_profile'

Hence, we do the following...

cd /home
find ./ -name '*.php' | xargs perl -pi -e "s/'profile', 'load_profile'/'profile_load_profile'/g;"

How to install mod_expires using custombuild

cd /usr/local/directadmin/custombuild
mkdir -p custom/ap2
cp configure/ap2/configure.apache custom/ap2/configure.apache
vi custom/ap2/configure.apache

add: --enable-expires

so it looks like this:

#!/bin/sh
"./configure" \
        "--prefix=/etc/httpd" \
        "--exec-prefix=/etc/httpd" \
        "--bindir=/usr/bin" \
        "--sbindir=/usr/sbin" \
        "--sysconfdir=/etc/httpd/conf" \
        "--enable-so" \
        "--enable-dav" \
        "--enable-dav-fs" \
        "--enable-dav-lock" \
        "--enable-suexec" \
        "--enable-deflate" \
        "--enable-unique-id" \
        "--with-suexec-caller=apache" \
        "--with-suexec-docroot=/" \
        "--with-suexec-gidmin=100" \
        "--with-suexec-logfile=/var/log/httpd/suexec_log" \
        "--with-suexec-uidmin=100" \
        "--with-suexec-userdir=public_html" \
        "--with-suexec-bin=/usr/sbin/suexec" \
        "--with-included-apr" \
        "--with-pcre=/usr/local" \
        "--includedir=/usr/include/apache" \
        "--libexecdir=/usr/lib/apache" \
        "--datadir=/var/www" \
        "--localstatedir=/var" \
        "--enable-logio" \
        "--enable-ssl" \
        "--enable-rewrite" \
        "--enable-proxy" \
        "--with-ssl=/usr" \
        "--enable-headers" \
        "--enable-expires"
./build clean
./build apache
service httpd restart

you may need to recompile php after this

./build php

Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable.

if you try running the following:

phpize

and get this error

$PHP_PREFIX/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

Then it's because you don't have autoconf installed.

To fix this error, do the following:

yum install autoconf

or you can install from source (if you want to use the latest version)


cd /usr/local/src/

/* find latest version of m4 here: http://ftp.gnu.org/gnu/m4/ */

How to search for text inside files in Linux

To search for a text pattern in files in linux, do the following:

find / -type f -print0 | xargs -0 grep -i 'your pattern'

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:

<?php
$block
= module_invoke('views', 'block', 'view', 'latest_news-block');
print
$block['content'];
?>

Or if you want to do just a regular block... just click on it to get the url...

How to remove Paypal Quick Checkout button from Magento when using Paypal.

If you disable "guest checkout" in magento -- and are using PayPal -- guest check is still possible via Paypal button--it will show below the "Proceed to Checkout" button.

In order to completely remove the possibility of Guest checkout, you'll need to alter the following:

app/design/frondend/default/YOURTEMPLATE/template/paypal/link.phtml
  • copy link.phtml to link-01.phtml or whatever
  • open/edit link.phtml and delete (or comment out) everything.

How to add custom javascript into the drupal webform module <form> <submit>

Recently, one of our clients asked to have custom tracking code implemented into their form submissions.

Since the client's site is built on Drupal, all forms are dynamically generated using the Webform module.

Their marketing company instructed us to add an 'onclick' code to :

<input type="submit" class="form-submit" value="Receive Coupons" id="edit-submit" name="op" onclick=tracking("track_submit_quote") />

However, since the Webform module creates all forms dynamically, there was no convenient way of hard coding the code into the form... i.e. there was no way for this to be done via webform admin.

phpMyAdmin database export "Save as file" template

Whenever you do a database backup using phpMyAdmin, you are presented with a default file name structure for saves, usually like so:

__DB__

which basically gives you the name of the database you just backed up. Which is ok, however, most people would also like the date and time stamp included as well...

So...

This is how it's done... replace the above with :

__DB__-%F-%T

__DB__ = name of database Example: my_database
%F = Same as "%Y-%m-%d" (year-month-day) Example: 2009-11-25
%T = time stamp . (24 hour format, hour_minute_second) Example: 11_07_31

which will save a file with the naming structure similar to:

my_database-2009-11-25-11_07_31.sql

You can easily use other date/time structure, to suit your personal preference.

chmod directories only

To chmod only directories within the directory you're in...

find ./ -type d -exec chmod 755 {} \;

To chmod only files within the directory you're in...

find . -type f -exec chmod 644 {} \;

RESOLVED: mysqld won't start

In case your mysqld won't work with

# service mysqld restart
or
# service mysqld start
or
# service mysqld stop

do this:

# killall mysqld

followed by:

How to make a bootable USB thumb drive

For a Vista/Server 2008/Windows 7 install usb drive

  • format your disk as FAT32
  • click start: type 'cmd' enter
  • type:
    bootsect /nt60 X:

Linux server: Set date and time

Set your correct timezone:

# timeconfig

* You may need to install timeconfig 'yum install tzdata'

select your timezone.. select "system clock uses UTC"

How to install Windows 7 RC using a thumb drive

It's no secret, Windows 7 is the best windows ever--it doesn't matter that the RC build 7100 not the final version, it's still a LOT better and faster than the latest and most optimized Windows Vista.

OK... anyhow... some people don't have CD/DVD drives in their PCs, so using a thumb drive is usually the best way to go.

In Windows Vista

Start --> type 'cmd' --> right click on cmd and select "Run as administrator"
Diskpart
List Disk
Select Disk 1 (Replace 1 with number reflecting your USB Drive)
clean
create partition primary
active
format fs=ntfs
assign
Now that the thumb drive is done, extract all the files from the Windows 7 iso with 7zip
You're done
now reboot and go into your bios, and select your USB drive to boot first... or if your bios has boot menu selection, then use that and select your USB drive. (e.g. the boot menu can be accessed by hitting ESC for my PC)

And as always... to have the most hassle/trouble free installation, please do a CLEAN INSTALL.
Meaning: do no upgrade your old windows. At the Windows 7 Installation, do the custom/advanced install and format your HD that you're going to install windows 7 on.

How to install PECL uploadprogress

On Linux server:

  1. # cd /usr/local/src/
  2. get the latest version http://pecl.php.net/package/uploadprogress
  3. # tar xvfz uploadprogress-VERSION.tgz
  4. # cd uploadprogress-VERSION
  5. # export PHP_PREFIX="/usr/local"
    # $PHP_PREFIX/bin/phpize          
    # ./configure
    # make
    # make install
  6. open your php.ini
    e.g.
    # vi /usr/local/lib/php.ini

    add the line you received followed by "uploadprogress.so":

    extension=/usr/local/lib/php/extensions/no-debug-non-zts-20060613/uploadprogress.so
  7. # service httpd restart

chattr (in /usr/sbin)

If something refuses to run, try:

chattr -R -suSiadAc /usr/sbin

Example: if dovecot doesn't run or install/upgrade, try doing...

whoami
lsattr /usr/sbin/dovecot

Using SSH with Screen for Session Management

Customize your ~/.screenrc

source: http://magazine.redhat.com/2007/09/27/a-guide-to-gnu-screen/

update server with custombuild

source: http://www.directadmin.com/forum/showthread.php?t=19221


cd /usr/local/directadmin
wget http://files.directadmin.com/services/custombuild/1.2/custombuild.tar.gz

Dovecot Problems

We use dovecot on our servers to process email. However, with IMAP it keep freezings so here are possible solutions.

# vi /etc/dovecot.conf

change and/or uncomment :

Solution: Quickbooks won't print

I installed a new printer and Quickbooks Pro 2008 just would not print anything--it seemed like after you hit print, the print-job would just disappear (not even get submited)...

New Server Checklist for directadmin (2009)

-Add all your ips in directadmin under "IP management"
(and assign 2 ips to admin)
http://xx.xxx.xxx.xxx:2222/CMD_IP_MANAGER

-Register nameserver at registrar

How to enable SpamAssassin on DirectAdmin

Source