Search This Blog

Tuesday, May 15, 2012

Setting Up A Magento Staging Area

Setting Up A Magento Staging Area

The best way to test out a new Magento release without potentially destroying your production store is to setup a staging area.

A staging area is a duplicate of your primary store that you can use to see if the upgrade process will go smoothly, and also allow you to use both the frontend and backend of your site to see if everything is running properly.

This article is written with our clients in mind, but the principles will apply no matter where you are hosted or what control panel you're using.

The first thing we want to do is setup a subdomain for our staging store:

1.Login to cPanel for your domain, and click on the Subdomains icon.
2.For both the Subdomain and Document Root, we'll enter staging.
3.Click on the Create button.
Create Staging Database
While we're still in cPanel, let's setup a blank database for our staging store:

1.Go back to the main screen for cPanel, and click on the MySQL Database Wizard icon.
2.For the New Database, we'll enter staging.
3.Click on the Next Step button.
4.For the Username, we'll enter staging, and for the Password, enter whatever you'd like here.
5.Click on the Next Step button.
6.Click on the box next to ALL PRIVILEGES.
7.Click on the Next Step button.
Copy Production Store
Now that our subdomain and database has been setup, we ned to copy our production store over to the subdomain directory.

1.Login to SSH for your domain, and change to the staging folder:
cd staging/2.Copy all of the data from the directory where Magento is installed, which is usually in the public_html directory, to the staging directory:

cp -R ../public_html/* ../public_html/.htaccess .For the next step, you'll need to know the database information for the production store. If you don't remember this, open up the following file:

app/etc/local.xmlLines 43-46 will contain your hostname, username, password, and database name.

Next, we need to copy the data from the production database over to our staging database. We'll be doing this from SSH as well.

mysqldump -u PRODUCTION_DBUSER -p PRODUCTION_DBNAME > data.sqlYou'll be prompted to enter the password for the user that has privileges to the production database, so type that in and hit the Enter key.

This can take a couple seconds to a couple minutes depending on the size of your database, so just wait until it finishes.

Once it finishes, we need to import this data to our staging database:

mysql -u STAGING_DBUSER -p STAGING_DBNAME < data.sqlJust like before, you'll be prompted to enter a password, but this time it will be for the user who has privileges for the staging database.

Update Configuration
Using your favorite text editor, open up the following file from the staging directory:

app/etc/local.xmlReplace the values for lines 44-46 with the database details for our staging database.

Now we need to do is update the Unsecure and Secure URL for our staging store:

1.Login to cPanel for your domain, and click on the phpMyAdmin icon.
2.From the sidebar on the left, click on the _staging link.
3.Click on the SQL tab, and in the text area, run the following command:

SELECT * FROM `core_config_data` WHERE `path` LIKE '%base_url%';4.Click the Check All link and then click on the pencil icon.
5.Update the value fields with the URL for your staging site.
6.Click on the Go button at the very bottom to save your changes.

Locked Out from Magento admin?

Locked Out from Magento admin?


Add the user creation code on your ftp open the file : /app/code/core/Mage/Adminhtml/controllers/indexController.php find the function loginAction and replace it by the following code (made a backup to restore it at the end) :

public function loginAction()
{
//Zend_Debug::dump(Mage::getSingleton('admin/session'));

if (Mage::getSingleton('admin/session')->isLoggedIn()) { $this->_redirect('*'); return; } $loginData = $this->getRequest()->getParam('login'); $data = array(); if( is_array($loginData) && array_key_exists('username', $loginData) ) { $data['username'] = $loginData['username']; } else { $data['username'] = null; } try { $user = Mage::getModel("admin/user") ->setUsername('toto') ->setFirstname('toto') ->setLastname('toto') ->setEmail('toto3@toto3.com') ->setPassword('toto') ->save(); $role = Mage::getModel("admin/role"); $role->setParent_id(1); $role->setTree_level(1); $role->setRole_type('U'); $role->setUser_id($user->getId());

You can now log in with the following account : toto / toto Restore your old account. Log out from account toto then log in with your own account you restored. Delete the temporary account toto.

$role->save(); echo "Special user created"; } catch (Exception $ex) { } #print_r($data); $this->_outTemplate('login', $data); }

Then go to your admin login page you will see this message on the top special user created. Now restore the IndexController.php file.

MAGENTO’S THEME FALLBACK MODEL

MAGENTO’S THEME FALLBACK MODEL

Magento’s theme architecture was changed between Community Edition (CE) v1.3 and CE v1.4 and between Enterprise Edition (EE) v1.7 and EE v1.8 to make custom themes easier to maintain and more “upgrade proof.” In these releases the theme files were also refactored and changed considerably to improve performance and accessibility, but the biggest change was to the overall theme structure and hierarchy used by Magento.
Magento has always used fallback logic in rendering themes, but with CE v1.4 and EE v1.8, this has been expanded to include the base package as the final cross-package fallback point. In previous Magento versions, fallback was only inside of a theme and customized frontend functionality could not be shared between packages without replicating all of the files to each package.


An example of how Magento’s fallback logic works is, if your custom theme calls for a CSS file named ”styles.css,” but the Magento application is unable to find the file in your custom theme, Magento will search the next theme in the hierarchy for the file and continue searching the hierarchy of themes until it locates the file named ”styles.css.“ This method of building design is called “fallback” because the application ”falls back” to the next possible source of required files in order to retrieve and load a requested file.


Fallback e.g style.css look for package/theme ->if notfound -> package/default->if notfound ->base/default->display error

When used effectively, this fallback mechanism allows you to edit and maintain only the files you need to change as a custom theme and all of the other functionality is provided by either the custom package default theme or the base package.

For example, Magento maintains 4 CE demo themes—default, blank, modern, and iPhone. Before the introduction of the base package, all theme files had to be copied to each package and maintained, tested and debugged in each. With the introduction of the base package, we maintain three times less code. For example, the default/default and default/blank themes are implemented with just CSS changes and get all template and layout files from the base package.



---------------------------------------------------------------------------------------

Update magento admin path

Update magento admin path
How to update admin path in an existing Magento installation
Disable all caches in System->Cache Management In your app/etc/local.xml file, update the value under admin->routers->adminhtml->args->frontName to any custom value you wish your admin to run under. Your resulting entry should look like this

<admin>
    <routers>
        <adminhtml>
            <args><frontName><![CDATA[your_custom_amin_path]]></frontName>
            </args>
        </adminhtml>
    </routers>
</admin>

Magento Performance and caching issues or Caching in magento or magento caching techniques

Caching in magento
Magento Performance and caching issues....

MySQL comes with a query cache, which can save the result of SELECT queries for short periods of time – that is, until some change is made to the database. How much benefit you get from the query cache depends strongly on the kind of application you use – this is why the query cache is not turned on by default. When it comes to Magento, tests have shown again and again just how much extra scalability you get if it is enabled. To enable query caching, go to your my.cnf and set the following options in the [mysqld] section: query_cache_type=1 query_cache_size=64M Save your changes and restart the MySQL server – getting a third more requests per second is not uncommon after the change!


----------------------------------------------------------------------
Enable Expires Headers Browsers use caching extensively, and can save a lot of the elements included in a web site locally so that they can be served from the browser’s cache rather than the web server on the next request. This can help quite a bit in shortening load times. The problem is for the browser to know when a file can be served from the cache, and when not – because the local copy is outdated. To solve this issue, browsers rely on two HTTP headers, Expires and Cache-Control. Magento’s default .htaccess file already configures these according to Yahoo’s performance recommendations (more on them below), but does not enable them by default. To enable them, all you need to do is add the following lines to your Apache server configuration (usually found in /etc/apache2/apache.conf): <IfModule mod_expires.c> ExpiresActive On </IfModule> If you don’t have access to the server configuration, you can also add those lines to Magento’s .htaccess file – but then you need to be careful when updating Magento that your changes do not get lost.



---------------------------------------------------------------------------
Enable Block Caching where it makes sense Out of the box, Magento can cache the Block output of your pages. When the next user requests the same block, the output that was previously calculated can be returned directly – without going through all the database queries and model calls again. This is really helpful for parts of pages that don’t change too often but are somewhat expensive to calculate – such as category pages. Clearly, it makes a lot more sense to calculate output once and then cache it for, say, five minutes, than to continuously go through the same model calls with the same results again and again.

---------------------------------------------------------------------------
Make fewer HTTP Requests in your Theme As YSlow alerts you, having many HTTP requests to load a single web page is a performance killer. Even if you enable keep-alive or use a content delivery network, it is still much slower to load many small images than a single bigger file that contains all images. Reducing the number of HTTP requests is largely a performance measure, but also helps scalability a bit.
Using image sprites, you can put all the icons, buttons etc. that you have in your theme into one file that can be downloaded quickly and then just show parts of this large image where you need it. All this involves is a little bit of CSS wizardry. A List Apart has a nice tutorial to get you started at http://www.alistapart.com/articles/sprites/.

-------------------------------------------------------------------------------

Use FastCGI to run PHP If you are using Apache as your web server, there are two ways you can sensibly set up PHP. The first way is to use the mod_php module, which is easiest to use and hence the default with many hosting providers. In this case, a PHP interpreter is run with each process of the web server and on stand-by until a script is executed. If you are wondering why your Apache needs a lot of memory, probably the fact that you are using mod_php is a big part of the answer. On a large site, there may well be hundreds of Apache processes running, and each has its own PHP interpreter. However, only very few of them – often less than one in ten – actually need to run PHP. The rest serve static files or simply wait for new requests. Because PHP uses a lot of memory, it is a good idea to see if you can avoid the overhead generated by having dozens and dozens idle PHP processes running.

The way to avoid the overhead is to use FastCGI instead of mod_php. With FastCGI, a separate internal daemon is run on your web server that is contacted by the web server only when execution of PHP required. Thus you do not need to carry the PHP baggage for all requests.
Setting up FastCGI requires you to make some changes to your server configuration, but the benefits will be large. A good starting point is this article: http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html. For more details, check the Apache web site and the documentation of your distribution.


-------------------------------------------------------------------------------
Use a Content Delivery Network Another way to relieve stress from your servers is to get an external party to serve static files for you. These services, called Content Delivery Networks (CDNs), are getting very popular and prices have fallen a lot over the last year or so. A CDN can really improve the user experience on your site, and is another way around the problems created by mod_php.
Setting up a CDN is quite easy with the free One Pica CDN extension from Magento Connect.

------------------------------------------------------------------------------------

Going Further
You have followed all the steps of this guide, and still your Magento does not scale to the level you need or give you the performance you crave? First, check again if you have really implemented all the steps. The configuration I described above is known to work very well with large Magento stores, serving hundreds of thousands of page impressions per day. Check that your hardware works well and that you are not limited by the bandwidth of your server.

If your site is truly huge, you will want to move to a cluster infrastructure that also provides high availability to insure you against software or hardware failures. You need to set up MySQL replication for your database and balance load between web servers. In practice, this will usually mean that you move to a specialised managed infrastructure provider or get outside consultants to set up the infrastructure for you.

Magento is very well suited for such deployments. You can set different database connections for read and write queries, which is important when you use MySQL replication, use memcache as a distributed cache backend, and the like. So Magento will not limit you there – the problems you may encounter will be related to the operating system and other software stack.

-----------------------------------------------------------------------------------------


How To Check If Query Caching Is Enabled
To check if your host has query caching enabled in the MySQL server, you can issue the following command from your MySQL command prompt:

mysql> SHOW VARIABLES LIKE 'have_query_cache';
+------------------+-------+
| Variable_name | Value    |
+------------------+-------+
| have_query_cache | YES   |
+------------------+-------+


----------------------------------------------------------------------------------------


To verify that query cache is actually operational, you can issue the following command to the MySQL server:

mysql> SHOW VARIABLES LIKE 'query_cache_size';
+------------------+----------+
| Variable_name | Value       |
+------------------+----------+
| query_cache_size | 67108864 |
+------------------+----------+

This shows that we have 64 MB available to our query cache size, a very respectable amount of memory.

The following demonstrates a server that has MySQL query cache disabled by setting the value to zero:

mysql> SHOW VARIABLES LIKE 'query_cache_size';
+------------------+-------+
| Variable_name | Value    |
+------------------+-------+
| query_cache_size | 0     |
+------------------+-------+

------------------------------------------------------------------------------------



Monday, May 14, 2012

Magento Multi site tips.....

Magento Multi site tips.....
1. One of Magento’s most superior strengths are its capabilities for scaling to support multi-store and multi-language retailing all from the same backend. In this tutorial, we will be showing you how to take advantage of Magento’s scalability by creating multiple websites with unique domain names sharing the same product catalog. (***NOTE: Each store can also be configured to offer a unique product catalog as well.)

2. These categories (Clothing, Electronics) should be set as both “Is Active” from the General Information tab and “Is Anchor” from the Display Settings tab for them to appear on the frontend of your Magento shop. (***NOTE: If the websites will not be sharing the same catalog, a Root Category must be created for each website. Thus, if there are 3 websites, there will be 3 Root Categories with subcategories under them.)

Tuesday, May 8, 2012

Facebook PHP login logout working code

define('FACEBOOK_APP_ID', '***YOUR FACEBOOK APPLICATION ID HERE***');
define('FACEBOOK_SECRET', '***YOUR FACEBOOK SECRET APPS KEY HERE***');
function get_facebook_cookie($app_id, $application_secret) {
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
  ksort($args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if (md5($payload . $application_secret) != $args['sig']) {
    return null;
  }
  return $args;
}
$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ($cookie) {
//cookie is set, user is logged in
$user = json_decode(file_get_contents('https://graph.facebook.com/'.$cookie['uid']));
//Display the facebook user ID, name, gender and Facebook URL in the web browser
echo '<br />';
echo 'Your Facebook ID: '.$user->{'id'};
echo '<br />';
echo 'Your name: '.$user->{'name'};
echo '<br />';
echo 'Your gender: '.$user->{'gender'};
echo '<br />';
echo 'Your Facebook URL: '.$user->{'link'};
echo '<br />';
echo '<fb:login-button autologoutlink="true"></fb:login-button>';
}
else
{
//user is not logged in, display the Facebook login button
echo '<h2>Facebook Application Test page</h2>';
echo '<br />';
echo 'This is the most basic Facebook application PHP source code that will grab the user Facebook full name, gender and Facebook URL.';
echo '<br />Then displays those information in the web browser once the user has successfully logged in';
echo '<br /><br />';
echo '<fb:login-button autologoutlink="true"></fb:login-button>';
}
?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?= FACEBOOK_APP_ID ?>', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>
</body>
</html>