Installing Magento easy way, the blessing of n98-magerun

The blessings of n98-magenrun phar archive has really eased the pain of installing Magento. Also the beautiful post by Fabrizio Branca at this post http://www.fabrizio-branca.de/build-your-magento-playground-in-less-than-60-seconds.html is really comprehensive. Please do check it out.

You first need composer.phar to get the dependencies. After getting n98-magerun.phar, follow the steps in the previous post. You might be interested in setting up the n98-magerun.yaml in /etc/ directory (assuming you are in GNU Linux, Debian distro) run the install under the www root of your hosting:

n98-magerun.phar install

This will give you step by step prompt to install Magento. There is a gotcha though, when you are asked for Enter Installation Folder, this does not accept absolute directory, rather the path is relative to the parent folder i.e. ./magento_installation_document_root. The installation runs smoothly. When you are done, set up your virtual host and go the URL that will prompt you to complete the installation from GUI.

Also to uninstall Magento installation, go to the document root of Magento installation earlier from terminal, then hit

n98-magerun.phar uninstall -f

This will automatically remove the installation folders and database.

 

Enjoy!

Installing Magento on GoDaddy hosting and ‘No input file specified’ Error

Installing Magento on GoDaddy hosting was heck of a pain on my hosted environment. I scoured through the blogs and help forums. I even resorted to Magento forum for solution. Nothing worked. Especially the redirection to bogus file on the topic

http://www.magentocommerce.com/wiki/groups/227/error/no_input_file_specified:

as follows:

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+.php$ /bogusfil

did not work.

At last I found the solution here http://www.youtube.com/watch?v=YicBzxnrnOM. Thanks to the author for that.

The setting that worked is, you must change the php.ini in you hosting root (not the document root in case you might have more than one site in separate subdirectories) to php5.ini. Then add the following setting directive:

cgi.fix_pathinfo = 1

Also you might need to change the upload_tmp_directory to some writable directory under your host directory root. That did the trick.

For magento document root hosted in some child directory under host root you might consider

RewriteBase /yourbasepath

 

where yourbasepath is the directory path upto your Magento document root.

http://www.google.com.au/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CE4QtwIwAQ&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYicBzxnrnOM&ei=ritXUoDvDsTJkQWnooH4CA&usg=AFQjCNFB9AzWTRI7O7Fw27nbVyNpg_s7WA&bvm=bv.53899372,d.dGI

Dissecting the URL with PHP $_SERVER superglobals

I guess for URI routing, we all need dissecting the URL. Here is the component we can glean with the help of PHP $_SERVER superglobals (superior globals ;-)). For example I am taking this URL for operation (this is scary): http://localhost/codeigniter/index.php/home?a=sdfd&b=545#hash
Here is the list you can get:1. $_SERVER[‘SERVER_PROTOCOL’] will return HTTP/1.1 that is the HTTP version. But to get whether it is HTTP or HTTP over SSL (HTTPS) we can check $_SERVER[‘REQUEST_PORT’] or $_SERVER[‘HTTPS’]. The former will return 80 or 443 whereas the later will return no-empty if HTTPS or ‘on’ (for IIS).
2. $_SERVER[SERVER_NAME] will get localhost or whatever the virtual host name is.
3. The $_SERVER[‘REQUEST_URI’] returns /codeigniter/index.php/home?a=sdfd&b=545 (without the #hash part, this hash can be manipulated through JS using location.hash property).
4. $_SERVER[‘SCRIPT_NAME’] will return the segment upto the .php extension i.e. /codeigniter/index.php.
5. To get the query string you can use $_SERVER[‘QUERY_STRING’] that will return a=sdfd&b=545. Hope this helps some folks (may be I am the folk only)

Resetting AUTO_INCREMENT value for MySQL

Keep in mind that deleting rows or even all the rows in a table won’t reset the value of AUTO_INCREMENT of a field. After deleting, if you add a new row (by INSERT off-course), the AUTO_INCREMENT value will start from the last value+1 of the last record. To fully reset the value you need to truncate table.
To start AUTO_INCREMENT from a specific value use:
ALTER TABLE some_table AUTO_INCREMENT=10;
For more see: this link.

Allowing users to user folder in home dir to execute .php file from web interface

1. Check if you have got php and userdir module enabled. You can check this from you apache2 installation’s directory. Go to /etc/apache2/mods-enabled and look for php5.conf, php5.load, userdir.conf and userdir.load files. If they are not enabled enable them by using a2enmod utility tool or creating symlink whichever you like.

2. Now open the userdir.conf file and check the UserDir directive is pointing to correct folder in each user’s home directory. For my case I intended to share user’s public_html/cgi-bin, so my configuration was this: UserDir public_html/cgi-bin UserDir disable root ...(trimmed for brevity)

3. Open the php5.conf and uncomment the line php_admin_value engine Off. Then restart the apache2 service. In browser open http://localhost/~user/index.php that will map the file in /home/user/public_html/cgi-bin/index.php. Hope this works.

Dealing with null values in field

If you have mix of null values in a column and you want to replace null with some predefined string and no-null as usual, then try this:

If your table “t” is like:

a | b

—-

1 | 2

null | 4

4 | 6

 

then to process the values of column a in output query:

select case when a is null then “is_null” else to_char(a, ‘999’) end from t;

Note: the last argument of to_char(a, “999”) is text pattern and defines how many digits you want to have in the string output.

Dealing with null field values

1. If you have any null field value in a table and you want to identify it to be replaced by zero(0), use COALESCE(column_name, 0). COALESCE function returns the first non-null value it finds. But there is one gotcha, if the column value type is numeric (numeric, int, float) then COALESCE(column_name, ‘example_string’) would return error.

2. If you want to return a column that has got mix of NULL and numeric values and you want to return some custom string in place of those null values then you can try CASE. As an example:

Consider:

Select * from t

a
---
 1
 null
 3

SELECT a,
       CASE WHEN a is null THEN 'isNull'
            ELSE 'notNull'
       END
    FROM test;

 a | case
---+-------
 1 | notNull
   | isNull
 3 | notNull

Then depending upon the second field value you can create an output string, as I did:

if (field2 == “isNull”):

print “Null”

else:

print field1

 

Note, CASE…END only takes fixed output in the THEN statement, so you can’t use a column name to output the column value when any condition fulfills. Like the following will trigger error:

SELECT a,
       CASE WHEN a is null THEN 'isNull'
            ELSE a
       END
    FROM test;

Cheers

Under development

ZeroClipboard: Copying to clipboard made easy

IE has native method of copying to clipboard e.g. document.clipboardData.setText() or getText(). Another alternative is to use object.execCmd(‘copy’). But there are some native Firefox method to access terminals local resource described here. But zeroClipboard has got very nice flash based solution for this that is cross-browser compatible. Here is how.

1. Download the source code from google code here.

2. Include the javascript in the folder in your html code.
3. If you have got div like:

Click to copy to clipboard

Then use function something like:

// Create our clipboard object as per usual
// Enable Rich HTML support (Flash Player 10 Only)
ZeroClipboard.setMoviePath( ‘zeroclipboard/ZeroClipboard10.swf’); //the location of swf object
clip = new ZeroClipboard.Client();
clip.setHandCursor( true ); //to put hand cursor on mouseover

//attach the clip to the trigger copy element and container
clip.glue(‘button’,’container’);

// on mousedown (means click), call the set the text
clip.addEventListener(‘mouseDown’, function(client) {
clip.setText(Ext.get(‘hashString’).getValue());
});
clip.addEventListener( ‘complete’, function(client, text) {
//do something after completion
clip.destroy();
});

3. it is better to check the flash plugin version of browser with swfobject javascript helper found in google code CDN.

Magento and CURL

To install magento, you must set up CURL in PHP. Like me, if anyone is using XAMPP as server package, then CURL is not enabled by default. So, find out the php.ini files in the location (I guess there are three of this file under apache, PHP4 and PHP directory). In all of the php.ini uncomment

; extension=php_curl.dll

then restart the apache server.