Awnist

Zend Framework: Listing contents of Zend_Registry

$registry = Zend_Registry::getInstance(); 
foreach ($registry as $index => $value) {
  echo "Registry index $index contains:\n";
  var_dump($value);
}

Apache: Force SSL by redirecting everything to https from .htaccess


RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

 

Adding init.d Dropbox service in Ubuntu/Debian


### BEGIN INIT INFO
# Provides:          dropbox
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     false
# Short-Description: dropbox service
### END INIT INFO
#!/bin/sh
# dropbox service
DROPBOX_USER="dev"
 
DAEMON=/opt/bitnami/dropbox/dropbox
 
start() {
    echo "Starting dropbox..."
    if [ -x $DAEMON ]; then
	start-stop-daemon -b -o -c $DROPBOX_USER -S -u $DROPBOX_USER -x $DAEMON
    fi
}
 
stop() {
    echo "Stopping dropbox..."
    if [ -x $DAEMON ]; then
        start-stop-daemon -o -c $DROPBOX_USER -K -u $DROPBOX_USER -x $DAEMON
    fi
}
 
status() {
    dbpid=`pgrep -u $DROPBOX_USER dropbox`
    if [ -z $dbpid ] ; then
        echo "dropboxd for USER $DROPBOX_USER: not running."
    else
        echo "dropboxd for USER $DROPBOX_USER: running (pid $dbpid)"
    fi
}
 
case "$1" in
 
    start)
        start
        ;;
 
    stop)
        stop
        ;;
 
    restart|reload|force-reload)
        stop
        start
        ;;
 
    status)
        status
        ;;
 
    *)
        echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
        exit 1
 
esac
 
exit 0

Creating color swatches with Imagemagick and bash

#!/bin/bash

if [ ! -d colors ]; then
mkdir colors
fi

for color in "$@"
do
convert -size 100x100 xc:$color colors/$color.jpg
done

Run with:

./colors.sh blue black green purple

Add a hash # in front of $color to generate by hex.

 

Overriding Magento’s form error mechanisms

Magento’s form error classes are pretty ugly and poorly designed. Luckily, it’s easy to override the methods located in prototype/validation.js.

Let’s allow validation on hidden form elements and start working on better looking advice when errors occur.

	Object.extend(Validation, {
		isVisible : function(elm) {
			return true;
		},
		insertAdvice : function(elm, advice){
			// advice contains the div that would normally be inserted.
		}		
	});

This code needs to happen anytime after validation.js is loaded.

apache2: Could not reliably determine the server’s fully qualified domain name, using xx.xx.xx.xx for ServerName

If Apache is bugging you with

apache2: Could not reliably determine the server’s fully qualified domain name, using xx.xx.xx.xx for ServerName

Get your hostname

$ hostname

production

and tell Apache by putting

ServerName production

in

/etc/apache2/apache2.conf

You can also do this in one line:

$ sudo echo “ServerName “`hostname` >> /etc/apache2/apache2.conf

 

Magento – Downloader: Failed to download within preferred state “beta”, latest release is version x.x.x, stability “alpha”, use “channel://…” to install PEAR ERROR: install failed

When installing a Magento extension with Downloader, you may see this message:

Failed to download magento-community/xxxx within preferred state “beta”, latest release is version x.x.x, stability “alpha”, use “channel://connect.magentocommerce.com/community/xxx” to install

PEAR ERROR: install failed

Following instructions, you may try and download using the method suggested and see:

Invalid package identifier provided:

channel://connect.magentocommerce.com/community/xxx

Magento Connect 1.0 and 2.0 don’t play nicely together. Did you know you can install via the commandline? Magento’s downloader is a frontend for a local PEAR installation. You will need shell access to your host, but you can type this in magento root:

./pear install channel://connect.magentocommerce.com/community/xxxx

and somewhere among the noise, you will see:

install ok: channel://connect.magentocommerce.com/community/xxxx

And the extension is installed.

Magento – Downloader error: Invalid file permissions, could not save configuration

If you see

Invalid file permissions, could not save configuration

in Magento’s downloader, usually when making changes to Settings such as Preferred state, make sure this file:

(magento root)/downloader/config.ini

is writeable by the webserver. If you don’t know how to do this properly,

chmod 777 (magento root)/downloader/config.ini

should fix your problems.

Magento – APC causes downloader error: Cannot redeclare class pear in /usr/share/php/PEAR/Registry.php

If Magento’s downloader is showing

Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error.

and Apache is throwing

[apc-error] Cannot redeclare class pear in /usr/share/php/PEAR/Registry.php on line 22.

make sure this is enabled in your /etc/php5/apache2/apc.ini file:

apc.include_once_override = 1

if that doesn’t work, you can disable APC in the downloader/ directory by putting

php_flag apc.cache_by_default Off

inside (magento root)/downloader/.htaccess.

 

Restrict access to Magento admin based on IP

Add this to .htaccess after “RewriteBase /”:

# Restrict admin access

RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123

RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123

RewriteCond %{REQUEST_URI} admin [NC]

RewriteRule ^(.*)$ / [F,L]