April 2010

Understanding Linux umask on Redhat / Centos

Understanding Linux umask on Redhat / Centos

umask is linux's way of determining default file/folder permissions when new files and folders are created. It's a little odd in that the umask is subtracted from 777 for folders and 666 for files to get the correct permissions. I don't claim to understand fully, but it just is.

What is your current umask?

umask
0002

By default, normal users will get a umask of 0002 = 775 on a folder and 664 on a file. This equates to

-rwxrwxr--

for a file.

I had a user that had a set umask of 0022, but all other users had a umask of 0002. This puzzled me, I looked in the normal areas that you can override the umask

/etc/profile

and

~/.bashrc

but didn't see anything obvious. Then looking in

/etc/passwd

I noticed this user had a groupid set to apache's group (48). This was done for reasons outside this discussion.

So if a userid or groupid < 99 then umask = 0022 (more restrictive).

Resources:
http://kbase.redhat.com/faq/docs/DOC-1373

Google Optimizer for a Magento CMS Home Page

Google Optimizer for a Magento CMS Home Page

This will guide you on how to set up Google Optimizer in Magento for the Home page. It's a little confusing, but isn't everything when you first encounter it?

Enable Google Website Optimizer in the Magento Configuration

This is located under System > Configuration > Google API > Google Website Optimizer. Change "Enable" to Yes, then click "Save Config"
Screen shot 2010-04-09 at 9.39.15 AM.png

Create Variant of your Home Page

In Magento go to:
CMS > Manage Pages

Select Your Home Page

Copy the content.

Go Back to the list of CMS pages, and now you'll want to create a new page. Give it the same title, a different SEF URL ID (e.g. home2), change status to Enabled, then paste in your original's code.

Change the home page variant any way that you like, this is the variant that Magento and Google will alternate between.

The Catch22

While you're in the Variant Home Page click on the "Page View Optimization" tab. For the conversion page select 'One Page Checkout'. This will give you the 'Conversion Page URL' that you'll need to copy and paste into the Google Website Optimizer during setup.

Sign up for Google Website Optimizer

Go to the URL:
https://www.google.com/analytics/siteopt/splash?hl=en

Sign in with your Google Account.

Get started with an experiment. Name the experiment, place your two different home page URLs to test, paste in the 'Conversion Page URL'
Screen shot 2010-04-09 at 9.51.23 AM.png

Click Continue. You want to select 'Your webmaster will install and validate JavaScript tags.' and copy the URL it gives you.
Screen shot 2010-04-09 at 9.59.22 AM.png

Back in Magento

Now back in Magento, for the Variant page you want to be on the Page View Optimization tab and paste in the Scrips Install URL. Select the Page Type to be Variant Page. Then click 'Install Scripts'. Some javascript will fill in below. Save this page.

Now go to the Original CMS Home Page.
Paste the Scripts Install URL, select Original Page for type and then click 'Install Scripts'

Flip Back to Google Website Optimizer

Now in Google Website Optimizer click 'Check Status'. It should work and now can click 'Continue' and then enable that test.

Test the pages to make sure they look like, if you're like me I forgot to set the Layout for the variation page and it really looked bad. From here you can enable the test.

Hey, you're done. Now go do something useful for a change :)

Resources:
http://www.google.com/support/forum/p/websiteoptimizer/thread?tid=50461d...

Lessons in Magento Today

Lessons in Magento Today

Printing the SKU in the cart Simple or Configurable

To print the sku in the shopping cart, even for Configurable (it will print the underlying simple product sku).

Place this code somewhere in:
app/design/frontend/default/default/template/checkout/cart/item/default.phtml

if (is_object($this->getChildProduct())): 
            echo $this->getChildProduct()->getSku();
        else: 
            echo $_item->getSku();
        endif; 

This will now print the sku... onto more work.

Reference:
http://www.magentocommerce.com/boards/viewthread/56728/#t214381

Concatentate data from a query into a single row (Transpose)

Concatentate data from a query into a single row (Transpose)

Let's say you have a query that returns this

cert_id
---------
100
200
300
500
600

What I want is to have it return this in a query

cert_id
----------
100,200,300.500,600

After much searching on the topic of transpose, with some complex solutions offered, I stumbled onto the GROUP_CONCAT function in Mysql.
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_...

So my query looks like this

        /* Show Gift Cert nubmers */
        (
          SELECT GROUP_CONCAT(cert_id) FROM ugiftcert_history uh
          WHERE so.entity_id = uh.order_id
          GROUP BY uh.order_id
        ) AS gc_numbers,

Onto greatness.

Spamassassin upgrade caused error of "exited or timed out without..."

Spamassassin upgrade caused error of "exited or timed out without..."

I just upgraded Spamassassin, and low, after I restarted it I received an error message while trying to start Spamassassin.

[root]# /etc/init.d/spamassassin start
Starting spamd: child process [21162] exited or timed out without signaling production of a PID file: exit 255 at /usr/bin/spamd line 2588.
[FAILED]

Per the article below, a simple sa-update at the command line updated the Spamassassin rules. Then it would start like normal.

Resources:
http://www.elehost.com/faq/web-tool-tips-and-fixes/54-spamassassin/172-f...

Zend Server Mysql Socket problem with PDO [Solved]

Zend Server Mysql Socket problem with PDO [Solved]

The Problem

This answer has eluded me for months. I have Zend Server CE installed on my Mac (and linux web servers). I would use a DSN similar to the following (please note that my real password is not 'root').

mysql://root:root@localhost/thedatabase

This would result in an error in a PHP Fatal error of

'Can't connect to local MySQL server through socket '/tmp/mysql.sock''

This drove me mad looking for an answer. I had not configured it to connect through a socket, why was it doing that? To add more injury to this insult, if I tried to connect to Zend Server's mysql socket (/usr/local/zend/mysql/tmp/mysql.sock) I would still get the same error message.

The Best Solution

It's as simple as specifying 127.0.0.1 in replace of localhost. I guess if you do this, you force PDO to use a TCP connection.

Solution Alternative

I haven't tried this, but you could also symlink from

/tmp/mysql.sock

to

/usr/local/zend/mysql/tmp/mysql.sock

.

I'm not a big fan of symlinks that reach outside of the application.

Cause

It seems there is a bug in PDO PHP 5.2.x that is not fixed until 5.3.x.

Resources:
http://forums.zend.com/viewtopic.php?f=44&t=568