Magento
Magento Performance Enhancement
by morf on Dec.08, 2009, under Blog, Magento
Omlouvám se, ale článek ještě není dostupný v české mutaci.
Magento Commerce is very robust system which make me happy with its complexness, but on the other hand this robustness implied bad performance. There are few but reliable tips for Magento Performance Enhancements before you should upgrade your server. You can tune Apache web server, PHP engine configuration and modules, MySQL server configuration, and at last you have to setup Magneto to use this tunes.
- Apache tuning
- PHP tuning
- MySQL tuning
- Magento configuration
1. Apache tuning
There is few tips how to speed up Apache quickly. You need edit your apache.conf or httpd.conf file, or your virtual named host configuration file. First of all you should read official Apache Performance Tuning, or Configuring Apache for Maximum Performance at Linux Gazette. Before you start experimenting with this you want backup your apache.conf or httpd.conf especialy if you dont know what you are doing
Few simple advices noted in articles above – setup apache to worker if you can, disable unused apache modules, use mod_deflate and mod_expires. Documentations: Apache 2.0 mod_deflate, Apache 2.0 mod_expires. After making changes to Apache you 100% sure wanna test the server performance in load. Last tip – if you disabled AllowerOverride Magento .htaccess file will not work, so you have to copy the content to your Apache Virtual named Host configuration.
2. PHP tuning
As above the basic tip is – you should disable all unused PHP modules wasting useful resource. Then you could enable few good modules to enhance performance.
2.1.1. eAccelerator
eAccelerator is must have extension of PHP which can help your Magento performance a lot, because it can do few tricks to speed up Magento Scripts and what is even better – “eAccelerator typically reduces server load and increases the speed of your PHP code by 1-10 times.” You can find informations at official site. Example configuration for eAccelerator is:
eaccelerator.shm_size = "128"
eaccelerator.cache_dir = "/var/cache/eaccelerator"
eaccelerator.enable = "1"
eaccelerator.optimizer = "1"
eaccelerator.check_mtime = "1"
eaccelerator.debug = "0"
eaccelerator.filter = ""
eaccelerator.shm_max = "0"
eaccelerator.shm_ttl = "0"
eaccelerator.shm_prune_period = "0"
eaccelerator.shm_only = "0"
eaccelerator.compress = "1"
eaccelerator.compress_level = "9"
eaccelerator.allowed_admin_path = "/var/www/eaccelerator"
More informations on eAccelerator configuration you can find at official site eAccelerator settings.
2.1.2. APC (Alternative PHP Cache)
APC have some code accelerating features like eAccelerator above, but my personal experience said when you have APC and enable eAccelerator above, you can got anoteher 30% speed enhancements. But combination of eAccelerator and APC cache isnt recommended. But APC is supported as cache engine by Magento Commerce. So its very simle to configure Magneto to use APC Cache. Example configuration of local.xml with enabled APC cache:
<global>
<cache>
<prefix>apc</prefix>
<backend>apc</backend>
</cache>
<install>
<date><![CDATA[Thu, 16 Oct 2008 10:14:54 +0000]]></date>
</install>
… rest of your local.xml file
But remember to setup different prefixes per Magento installation, otherwise you can get funky results.
2.1.3. Memcache
Its almost the same like APC cache. It cache data into RAM and create very fast cache backend. You can enable it in local.xml like APC above, just change backend to “memcache” (without quotes).
2.2. Configuration enhancements
There is few significant PHP configuration attributes to setup with Magento. If your installation have thousands of products, few store views, and per view product attributes Magento require to setup bigger memory_limit. Another case is when you write your own long running / memory consuming script which need setup longer running time. In some cases i needed more than 384 MB RAM handling data in Magento with custom script. Ideal way of changing this values is in .htaccess file of your Magento installation (backup before change anything). Another way to enhance speed of your scripts is to enable zlib output compression for your scripts. This is definitively wrong idea, when you using mod_deflate in Apache or another alike zlib.
php_value memory_limit 128M
php_flag zlib.output_compression on
</IfModule>
memory_limit = 128M
; max script running time
max_execution_time = 60
; enable zlib output compression
zlib.output_compression = on
If you cant setup this values in php.ini, then you can try set them in .htaccess (look in .htacces of Magento php4 or php5 section), you can hopefully set them in index.php like that:
3. MySQL tuning
You can enhance Magento script very well with proper MySQL tunning. This pay double, when you are using Dataflow import / export features for thousands of products etc. Anyway Magento accelerate pretty when you enhance MySQL buffers and caches. Magento use Innodb engine, so you have to enhance innodb settings as well. Before using this tunes be sure backup your my.ini or my.cnf files.
This section is inspired by Performance is Key! – Notes on Magento’s Performance article at Magento Blog.
# innodb tuning
innodb_buffer_pool_size = 64M
innodb_additional_mem_pool_size = 8M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 2
# key buffer
key_buffer = 96M
# query cache size and limit
query_cache_size = 128M
query_cache_type = 1
query_cache_limit = 16M
# max opened tables
table_cache = 1024
# sort buffers
myisam_sort_buffer_size = 64M
# temporary table size
tmp_table_size = 128M
thread_cache = 16
max_allowed_packet = 64M
sort_buffer_size = 4M
read_buffer_size = 4M
read_rnd_buffer_size = 4M
thread_cache_size = 8
max_connections = 128
wait_timeout = 200
4. Magento configuration
Some another tips cover Magento configuration, and they are short:
1. let Magento put session data in database instead of files. Part of configuration to do that in local.xml
<session_save><![CDATA[db]]></session_save>
</global>
2. use global attributes for products if you dont need per view attribute values (admin -> attributes)
3. enable APC or Memcache cache backend and of course enable caching in admin -> cache management
4. enable Mage_Compiler module and disable unneeded modules in admin -> system -> configuration -> advanced
5. Other useful tips
If you dont have fast connection enough or you want speed up user connections to your Magento you should do few optimalization. You can batch resize product images, or merge and compress CSS files.
5.1. Image size optimalization
You can simply follow tips for resizing images from this How to Article – Resizing images that are too big or too small for the product pages, en-masse. (Tips from this article need linux compatible OS with some basic programms installed.)
5.2. CSS files compression
Open your Magento layout definition XML in your view. And copy all CSS files contents to one css file, and include it instead of multiple files. Then use CSS Compressor to compress CSS files by removing unnecessary space and definitions. There is possibility all files in one will not work together, then you will have to experiment with right combination (eg. reset + menu + clears , boxes , your own … ).
5.3. Javascript files compression
Is used by Magento by default i think, otherwise you should enable it in your Magento administration.
5.4. Gzip / Deflate compression
As written above, you can use PHP gzip output filter, or Apache module mod_deflate. Be noticed, than you can use just one of them
I hope you liked this post, and find it useful.
Magento Commerce database diagram
by morf on Nov.19, 2009, under Blog, Magento
Prior 1.3.x … native MySQL Workbench reverse engineering exported to png.
Verze 1.3.x … nativní reverse engineering MySQL Workbench vyexportovaný do png.
How to purge Magento Commerce Orders and Customers
by morf on Nov.19, 2009, under Blog, Magento
In near past i need this feature, because i just put some fresh development version of Magento Commerce installation to live server. Before that, i should purge all Magento Commerce testing orders and customers. I found this how to, and i want to share it. Originaly from How do I purge dummy sales orders – Here is your solution to it!. PS: Don’t forget set your database prefix.
Nedávno jsem potřeboval tuto vlastnost, protože jsem zrovna instaloval čerstvou vývojovou verzi Magento Commerce na živý server. Před tím jsem ale musel smazat všechny testovací Magento Commerce objednávky a zákazníky. Našel jsem toto how to, a chtěl bych se o něj s Vámi podělit. Orignál pochází z testing How do I purge dummy sales orders – Here is your solution to it!. PS: Nezapomeňte použít Váš databázový prefix.
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
– reset customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
– Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;
How to install Magento Commerce
by morf on Oct.27, 2009, under Blog, Magento
This Post is step by step generic tutorial how to install Magento Commerce.
First of all you should setup your Environment, but if you are installing Magento first time you should check if you fit Magento Commerce System Requirements. In short you need: any os running Apache, PHP, and MySQL. Required PHP modules are: PDO_MySQL, Simplexml, mcrypt, hash, GD, DOM, iconv, SOAP (optional).
Now you need to get Magento Commerce Full Release stable package, and optionaly you could download one of Magento Translations. I suppose you have knowledge to prepare hosting for you, this problematic is not part of tutorial at all. You need one apache virtual host, eg. server, or hosted domain, and one MySQL database (optionaly due to table prefix Magento can share one database with other projects without any harm).
Next step is extracting full package to temporary directory or right to the server root directory. If you download custom translation, extract localization package to app/locale. Example path for cs_CZ localization (eg. Czech language) is app/locale/cs_CZ. Then if you using Linux or Unix OS (almost all hosting providers), you need for some basic Magento functions (images, logging, sessions, temporary files etc.) set up few directories writable for Web Server – app/etc media/ (media/catalog/product) var/ (var/session var/tmp var/log). You dont have to do this in 99% on your Windows OS.
Now the fun begins – you can install Magento. Start up your browser and direct it to your magento url, you should see installation screen now. Confirm agreement, next select localization, time zone and currency, next fill up db connection details, setup session (for high traffic site use db as storage), and as last step setup administrator’s account and pass. Optional you could generate your own Shop Key – use for data encryption. Store it well and secure, on last installation step.
If you did well, you could go now to your Magento Frontend or Backend. Good Luck, and have fun.
Sreenshot images of installation with example values filled:
1. Licence Agreement
2. Localization
3. Configuration
4. Create Admin Account
5. You’re All Set!
Tento článek je obecný návod jak nainstalovat Magento Commerce krok za krokem.
Nejdříve by jste měli nastavit prostředí, jestli ale Magento instalujete poprvé měli by jste zkontrolovat, zda odpovídáte Magento Commerce Systémové požadavky. V krátkosti budete potřebovat: jakýkoliv operační systém na kterém běží Apache, PHP, MySQL Vyžadované PHP moduly jsou: PDO_MySQL, Simplexml, mcrypt, hash, GD, DOM, iconv, SOAP (volitelné).
Nyní budete potřebovat stáhnout Magento Commerce Full Release stable package, a volitelně můžete stáhnout jeden z lokalizačních balíčků Magento Translations. Předpokládám, že máte dostatek znalostí k přípravě vašeho hostingu, tato problematika není vůbec součástí tohoto návodu. Budete potřebovat jeden apache virtual host, nebo server, nebo hostovanou doménu, a jednu MySQL databázi (volitelně díky databázovým přefixům Magento může sdílet jednu databázi s jinými projekty aniž by došlo k nějakému poškození).
Dalším krokem je rozbalení archivu do dočasného adresáře nebo rovnou do adresáře server root. Pokud jste stáhli překlad, rozbalte lokalizační balíček do app/locale. Např. pro lokalizaci cs_CZ (čeština) je správná cesta app/locale/cs_CZ. Potom pokud používáte Linux nebo Unix (většina hostingů), tak je potřeba pro některé základní funkce Magento (obrázky, logování, session, dočasné soubory atd.) nastavit několik adresářů s právy pro zápis pro web server. Jsou to: app/etc media/ (media/catalog/product) var/ (var/session var/tmp var/log). Na 99% windows tento krok není potřeba.
Nyní začíná sranda – můžete nainstalovat Magento. Spusťte prohlížeč a nasměrujte ho na url Magento, nyní by jste měli vidět instalační obrazovku. Potvrďte licenci, dále vyberte lokalizaci, časové pásmo a výchozí měnu, v dalším kroku vyplňte připojení k databázi, nastavte session (pro stránky s velkou návštěvností použijte databázi jako úložiště), a v posledním kroku nastavte uživatelský účet a heslo. Volitelně můžete vygenerovat vlastní klíč obchodu – používá se k šifrování dat. Uložte si tento klíč na bezpečné místo v posledním kroku instalace.
Jestli jste si vedli dobře, tak by jste nyní měli možnost jít do Magento Frontend nebo Backend rozhraní. Hodně štěstí, a bavte se.
Screenshoty instalace s předvyplněnými příkladnými hodnotami:
1. Licence
2. Lokalizace
3. Nastavení
4. Vytvořit účet správce
5. Hotovo
How to import images into Magento Commerce
by morf on Sep.27, 2009, under Blog, Magento
If somebody told you, you can’t import images to Magento, he was definitively liar. Magento Dataflow can import images, but the trick is you have to upload or copy images you want to import into [installation_directory]/media/import/* . Then export (System -> Profiles -> Export All Products -> Start profile) your products if you have any, download (copy) and edit the file. Now you can fill columns small_image, image, thumbnail with absolute path from media/import directory – for example /my_image.jpg (note the / on the start). And sure you can use same image for all three columns.
Jestli Vám někdo říkal, že nemůžete nahrávat obrázky do Magenta, tak byl definitivně lhář. Magento Dataflow umožňuje importování obrázků, ale trik je v tom, že nejříve musíte uploadnout nebo zkopírovat obrázky, které chcete importovat do [installation_directory]/media/import/* . Potom vyexportujte (Systém -> Profily -> Export All Products -> Spustit Profil.) Vaše produkty, jestli nějaké máte, stáhněte (zkopírujte) a editujte tento soubor. Nyní můžete vyplnit sloupečky small_image, image, thumbnail absolutní cestou z adresáře media/import – např. /muj_obrazek.jpg (všimněte si / na začátku). A samozřejmě – můžete použít stejný obrázek pro všechny tři obrázky.
How to migrate Magento database
by morf on Sep.27, 2009, under Blog, Magento
If you have to migrate Magento database from one server to another, or from your local working station to server (etc.), you sure noticed that Magento store informations about base urls in database, so you have to change this data. To fix this you need migrate the database to new server, and then through PHPMyAdmin, or mysql console submit this commands to change new base url and base secure url.
Dont forget the closing /.
Pokud jste museli přesouvat databázi Magento z jednoho serveru na druhý, nebo ze své lokalní pracovní stanice na server (atd.), určitě jste si všimli, že Magento ukládá informace o base url (základních, výchozích url) do databáze, takže budete muset změnit tato data. Aby jste to mohli zpravit, nejdříve přesuňte databázi na nový server, a potom přes PHPMyAdmin nebo mysql konzoli pošlete tento příkaz ke změně základních url (base url, base secure url).
Nezapomeňte na uzavírací /.
How to add Products on Magento Homepage
by morf on Sep.07, 2009, under Blog, Magento
Its pretty simple – you have to do edit your Home page. Go to your Magento admin, login, then go CMS – Manage Pages. Edit your Home page, and in the place you wanna have product list displayed put this row:
{{block type=”catalog/product_list” category_id=”1″ template=”catalog/product/list.phtml”}}
Where you have to change the category_id attribute to category id you want to display. You can find this id in heading, if you editing any category.
Je to pěkně jednoduché – jediné co musíte udělat je upravit vaší Domací stránku. Jděte do Magento Adminu, přihlašte se, a potom jděte do CMS – Správa stránek. Upravte svojí Domácí stránku, a v místě kde chcete mít zobrazení výpis produktů vložte tuto řádku:
{{block type=”catalog/product_list” category_id=”1″ template=”catalog/product/list.phtml”}}
Kde musíte změnit atribut category_id na id kategorie, kterou chcete zobrazit. Toto id najdete v nadpisu při editaci kterékoliv kategorie.
How to enable APC cache in Magento Commerce
by morf on Aug.27, 2009, under Blog, Magento
Its quite simple. You just have to edit your local configuration file app/etc/local.xml too look like this:
<config>
<global>
<cache>
<prefix>apc</prefix>
<!– this prefix should be unique for each Magento using this server tento prefix musí být unikát pro každé Magento používající tento server –>
<backend>apc</backend>
</cache>
<!– … another content of your local.xml další obsah vašeho local.xml … –>
</global>
</config>
How to clean Magento log database
by morf on Aug.12, 2009, under Blog, Magento
Just send this SQL commands to your database console:
DELETE FROM log_quote;
DELETE FROM log_summary;
DELETE FROM log_summary_type;
DELETE FROM log_url;
DELETE FROM log_url_info;
DELETE FROM log_visitor;
DELETE FROM log_visitor_info;
If you used recently dataflow import or export, you can clean dataflow tables with these commands:
DELETE FROM dataflow_batch_export;
DELETE FROM dataflow_batch_import;
DELETE FROM dataflow_import_data;
DELETE FROM dataflow_profile_history;
DELETE FROM dataflow_session;
Magento Dataflow Speed
by morf on Jun.22, 2009, under Blog, Magento
Many people have suffered a lot by Magento Commerce Dataflow speed. I had serious problem by myself, when i tried to import 10,000 items into Magento database. I wrote my own import script, one of possible solutions to Magento Dataflow speed problem. But my achieved results were about 30-60 seconds per item. That’s terrible.
So i did little bit of research on Varien_Profiler, and the major problem was called database queries. So little googling took me to Magento Blog Article about Performance – this is really good starting page if you do experience Magento Dataflow speed issues. Setup your MySQL configuration by example in the article, which will help a lot – i’ve got 10 times faster queries on my averange Windows Vista laptop.
But still 3 - 6 seconds * 10,000 items isn’t in fact a good result. So i dug deeper in Magento Forums about speed, and tried to run benchmarks of Magento Dataflow import / export profiles. Export was already fast enough, but Import was a real pain in the ass. Even original script from Magento (= Dataflow API) didn’t run faster than my own script.
I’ve found lot of people with the same issue on forums, so i didn’t give up. Another solution for improving performance of Magento, is installation of Memcache, or APC cache, but i haven’t got better results using them. Something was wrong, because script didn’t use 100% CPU or memory.
So after at least 100 times i red profile xmls created by Magento Admin, and finally i’ve found holy grail in getting speed Magento Dataflow import. 10,000 items in 20 minutes. The solution is very easy: setup Number of records in your import profile to 10, or 100, maybe even 1,000 items – this causes Magento doesn’t run one query per imported item, but cache 10, 100 or 1,000 rows and then run’em all at once (well not really, but that’s the point).
I hope you found this article useful. Don’t forget to setup enough memory_limit for your php script when using this method.
Edit:
I’m pretty sure you can enhance speed of import rapidly, when you setup your custom product attributes scope to GLOBAL instead of store view, because if you are using attributes per store, then all this data are duplicated per store, and then amount of data handled by Dataflow import/export will grow rapidly.









