Magento Error: Integrity constraint violation: 1062 Duplicate entry ‘123456’ for key ‘PRIMARY’

Following a database export/import as part of a migration  or copy to a new development environment some database problems can occur, even if the entire db is copied.  Sometimes the problem can be the log files references, as is likely with the error:

Integrity constraint violation: 1062 Duplicate entry  ‘123456’ for key ‘PRIMARY’

Where 123456 is some number.
Continue reading Magento Error: Integrity constraint violation: 1062 Duplicate entry ‘123456’ for key ‘PRIMARY’

Facebook Comments

Mysql: Export entire database via command line (and import it again)

Sometimes, when migrating servers or copying data to a development environment for example, one needs to take a copy of an entire mysql database. Here is how you do this via the command line on a redhat/centos server:

Continue reading Mysql: Export entire database via command line (and import it again)

Facebook Comments

Mysql: Change the full text index minimum word length

So you are trying to do a fulltext search but your searches for “cat” or “dog” always return zero results, even though you have articles all about cats and dogs. By default the minimum search text length for full index searches is 4 characters, anything less than that returns nothing, zip, nada, jack-all.  You need to change the minimum word length.

This can throw people using something like Magento whose product types or names are short, such as “bag”,”cup”, or “mug”.  The problem isn’t actually in Magento but a server setting. You might be kind of stuck if you are using a shared hosting environment – you can contact your hosting service and ask nicely.

Continue reading Mysql: Change the full text index minimum word length

Facebook Comments

Centos: Create new SSL certificate for https

  1. Generate a new certificate signing request (.csr) and key file (.key)

    openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr

    where server is the name of your server

  2. Fill in the details but you can leave email, challenge password and optional company name blank. Please note: The following characters cannot be accepted: < > ~ ! @ # $ % ^ / \ ( ) ?.,&
  3. Chek the contents of the csr:  https://www.sslshopper.com/csr-decoder.html  or enter this in the SSH console:

    openssl req -in server.csr -noout -text

    (again where server.csr is the name of the newly genererated csr file)

  4. Submit csr to commercial ssl provider.
  5. Copy the new certificate information into the correct location for the host.  You may need to look at the virtual host settings or apache config file to see where an existing one is. * See below
  6. Do the same for the intermediate certificate file if there is one.
  7. Move (or copy) the key
  8. Change the apache (or virtual host) config file to point at the new certificates.
  9. Restart the webserver.  For Debian this is “service apache2 restart”.  For Centos this would be “service httpd restart” or “systemctl restart httpd” for newer Centos versions.
  10. Make sure the server restarts – any typos in the config will stop it from running – you will be notified.

Additional resources:

Country Codes: https://www.digicert.com/ssl-certificate-country-codes.htm

https://www.digicert.com/csr-creation-apache.htm

https://www.digicert.com/ssl-certificate-installation-apache.htm

https://access.redhat.com/solutions/43575

Check they are working correctly: https://www.sslshopper.com/ssl-checker.html

Facebook Comments

Centos: Checking and Renaming the Server Hostname

A quicky this, for personal reference more than anything else.

Checking the Hostname
From within the console, run hostname to check the current hostname.

Changing the Hostname
To change the hostname run

hostname  mynewhostname.com

check it has happened with hostname and then restart the network

systemctl restart network

(or simply network restart on older centos versions)

Facebook Comments

Magento Useful Template Snippets

Create a block object inside a phtml template file:

<?php
$myBlockObject = $this->getLayout()->getBlock(“my_block_name”);
echo $myBlockObject->blockFunction();
?>

Insert a phtml template file into another phtml file

<?php echo $this->getLayout()->createBlock(‘core/template’)->setTemplate(‘page/html/someother.phtml’)->toHtml(); ?>

Get current product from registry

<?php
if( Mage::registry(‘current_product’) ){
$product = Mage::registry(‘current_product’);
}
?>

Insert static block into phtml file

<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘block_identifier’)->toHtml();
?>

Get request (querystring) parameter

<?php
$myVar = Mage::app()->getRequest()->getParam(“myVar”);
?>

Get controller name
Can use this to check whether you are on a product or a category page

<?php
if($this->getRequest()->getControllerName()==’product’){
if(Mage::registry(‘current_product’)){
//do something useful
}
}
?>

Facebook Comments

mySQL (mariaDb) Useful User Management Via Command Line

Here is a collection of useful and common mysql commands for managing database users using the command line, perhaps whilst logged in to the server via ssh. The following commands work for MySql and mariaDb. Don’t forget to include the semi-colon at the ends of each command. Continue reading mySQL (mariaDb) Useful User Management Via Command Line

Facebook Comments

Magento Cookies not Working in Chrome or Opera on Frontend

So, I was testing the “this site is using cookies” functionality in Magento. It worked fine on a local environment but failed to work on a test “live” IP address site. I say failed, but it worked fine in IE and Firefox whereas in Chrome hitting the “I agree to cookies” button didn’t set a cookie and redirected. I eventually solved it. Continue reading Magento Cookies not Working in Chrome or Opera on Frontend

Facebook Comments