Pagoda Box has several optimization tools available to help you get the most out of your Magento application. After reading this doc, you should be familiar with:
- Installing a bytecode caching extension
- Configuring Magento to use Redis
- Other optimizations to improve Magento's performance
Use this Doc with the Magento Doc
This doc is intended to be used in conjunction with the Magento Configuration doc. If you don't have Magento up and running yet, start there first.
Bytecode caching stores the code generated by PHP so it doesn't have to parse and compile scripts on every request. APC, eAccelerator, OPCache, and XCache are bytecode caching extensions available on Pagoda Box. Which one you use depends on what version of PHP you're using and personal preference. Each is added as a php_extension or zend_extension in your Boxfile. What extensions are available to each version of PHP can be found in the PHP Extensions doc.
Simply add your preferred opcode cacher as a php_extension or zend_extension in your Boxfile and deploy. No additional configuration is required.
Enabling OpCode Cachers in the Boxfile YAML
Redis Sessions & Cache
Redis is an advanced key-value store that makes for an extremely powerful caching mechanism and/or session store. We highly recommend using Redis to store sessions and caches instead of storing them in network directories or in your database.
Add a Redis Service
Redis can be added via your Boxfile or the dashboard. In either case, you'll need to add the "redis" php extension to your web service. This is the Redis/PHP adapter that will allow your PHP process to communicate with Redis.
Adding a Redis service in the Boxfile YAML
To store Magento sessions in Redis, modify the session handler section of your
and set the session save path as follows:
Redis Session Save Path in local.xml XML
# These are not your Redis connection credentials. # Use the Redis connection credentials found in your dashboard.
If you using the technique outlined in the
Magento Configuration doc
of using two
note that only changes to
will be reflected in your app on Pagoda Box.
Next, add Redis support to Magento by overriding the core Magento file:
Simply copy the file and create your own local version at:
In the new file, around line 62, add the following:
Setting the Magento Session Save Handler PHP
Magento is now configured to use Redis as a session store.
To use Redis as a Magento cache, add the Credis library and Cm Module. The module consists of one file, which you can download
Although the Cm module author recommends installing via modman, modman doesn’t correctly register all submodules with Pagoda Box. Instead, save the file as:
Add the Credis Library to your Project
Edit Your Magento Cache Declaration
Edit the cache delcaration and its contents in your
Changing Magento's Cache Declaration XML
<port>, be sure to use the host and port for your Redis service provided in your dashboard.
Also notice that
<database> is set to 1 in the example. Redis allows up to 16 databases within a single Redis service. Setting the cache database as 1 (or any other number) will isolate cache records from your sessions. This isn't necessary, but does help to keep things organized.
Set Far-Future Expires
To drastically reduce the number of requests per visitor as they browse your site, set far future expires. This should be done after finishing front-end theme work. Adding the following
httpd_static_expire directive to the web1 section of your Boxfile will expire static asset caches after 1 year.
Setting Static Expire in the Boxfile YAML
Go ahead and deploy your changes. Once they're deployed, you'll need to flush your Magento cache. Log into your Magento admin and go to System > Cache Management, then click "Flush Magento Cache".
Verify Redis is Working
Now that Magento is configured for Redis, verify that everything is working. Browse and update your site to create sessions and cached data in your Redis service. Enable SSH access on your Redis service and either use the Pagoda Tunnel or setup SSH port forwarding from your local machine. Then use the Redis-CLI to connect. Once connected, run the following command to display a list of all stored keys.
Connecting To & Displaying Keys in Redis Terminal
# Use the Pagoda CLI to open a Tunnel to Redis $ pagoda tunnel cache1 # In a separate terminal session, connect using the redis-cli $ redis-cli -h 127.0.0.1 -p 6379 # List all keys $ keys *
You should see a list of assorted keys. If you see session keys only, cache keys only, or if you don’t see any keys at all, review your configuration settings and ensure you’ve cleared the Magento cache.
For a full list of useful commands when using Redis, see their official documentation.
Avoid Storing JS & CSS in Network Storage
To turn file merging off, log into your Magento admin panel, then navigate to: System > Configuration > Developer.
Disable Unnecessary Logs
Magento has a few logging utilities that can provide helpful information, but also dramatically increase the number of database reads and writes.
If you don't need the System & Exception logs, disable them by going to System > Configuration > Developer > Log Settings and change "Enabled" to "No".
If you don't need the user browsing activity logs, disable some or all of them by adding the following code to your app/etc/local.xml file.
Disabling User Activity Logging XML
Enable All Default Caching Options
This should go without saying, but ensure you've enabled all the default caching options available at System > Cache Management.
Disable Unused Modules
Disable any unused Modules at System > Configuration > Advanced > Advanced.
Expires Browser Caching
You can increase the number of files browsers cache by adding the following code to the
file in the root of your application.
Expires Browser Caching Apache
Scale Server Resources
After you've optimized your application and environment as much as possible, it's time to scale your server resources. Since Magento is extremely database intensive, DB RAM will most likely be the first place you'll want to start. Large catalog/high traffic stores will most likely require a dedicated database.
Table of Contents
- Add a Redis Service
- Adding a Redis service in the Boxfile
- Redis Sessions
- Redis Session Save Path in local.xml
- Setting the Magento Session Save Handler
- Redis Cache
- Add the Credis Library to your Project
- Edit Your Magento Cache Declaration
- Changing Magento's Cache Declaration
- Set Far-Future Expires
- Setting Static Expire in the Boxfile
- Verify Redis is Working
- Connecting To & Displaying Keys in Redis
- Avoid Storing JS & CSS in Network Storage
- Disable Unnecessary Logs
- Disabling User Activity Logging
- Enable All Default Caching Options
- Disable Unused Modules
If you have any questions, suggestions, or corrections, let us know.