Tag: Magento

  • Magento 1 Invalid Form Key

    Magento 1 Invalid Form Key

    When login to Magento 1 Admin area, i get an error

    Invalid Form Key. Please refresh the page.

    magento 1 login error

    This is because the value of web/cookie/cookie_domain set wrong. This should be the current domain name.

    MariaDB [goipshop]> select * from core_config_data where path like 'web/cookie/cookie_domain';
    +-----------+---------+----------+--------------------------+--------------+
    | config_id | scope   | scope_id | path                     | value        |
    +-----------+---------+----------+--------------------------+--------------+
    |       413 | default |        0 | web/cookie/cookie_domain | goipshop.com |
    +-----------+---------+----------+--------------------------+--------------+
    1 row in set (0.002 sec)
    
    MariaDB [goipshop]> 

    In this case, the domain name was different.

    To see the value, you can run

    select * from core_config_data where path like 'web/cookie/cookie_path';
    select * from core_config_data where path like 'web/cookie/cookie_domain';
    

    You can leave cookie domain value empty with command

    update core_config_data set value="" where path="web/cookie/cookie_domain";
    

    Or just delete the entry from MySQL table core_config_data with SQL commands

    DELETE FROM core_config_data WHERE path='web/cookie/cookie_domain';
    DELETE FROM core_config_data WHERE path='web/cookie/cookie_path';
    

    Once this is done, you need to clear the cache with the command

    rm -rf var/cache/ var/session/
    

    Also clear browser cache or test in a private (incognito) browser

    See Magento

  • Magento 2 Unable to proceed: the maintenance mode is enabled

    Magento 2 Unable to proceed: the maintenance mode is enabled

    When i visit a Magento 2 site, i get error

    1 exception(s):
    Exception #0 (Exception): Unable to proceed: the maintenance mode is enabled. 
    
    Exception #0 (Exception): Unable to proceed: the maintenance mode is enabled. 
    
    #1 Magento\Framework\App\Bootstrap->run(&Magento\Framework\App\Http\Interceptor#000000003459ecdd0000000028ca744b#) called at [index.php:39]
    

    magento 2 maintanance mode

    To fix this, login to the server using SSH, run following command.

    php bin/magento maintenance:disable
    

    This will disable Magento 2 maintenance mode.

    If you need maintenance mode enabled, you can run

    php bin/magento maintenance:enable 
    

    See Magento

  • Install Elasticsearch 7 on Ubuntu for Magento 2.3

    To install Elasticsearch, add the key

    wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

    Install apt-transport-https

    sudo apt-get install apt-transport-https

    Add apt repository

    echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list

    install elasticsearch with apt

    apt-get update
    apt-get install elasticsearch

    Set elasticsearch to start on boot

    systemctl daemon-reload
    systemctl enable elasticsearch

    Elasticsearch can be started and stopped as follows:

    systemctl start elasticsearch
    systemctl stop elasticsearch

    Verify Elasticsearch is running with

    systemctl status elasticsearch

    or with

    curl localhost:9200

    if it fails to start, you can debug it with

    journalctl --unit elasticsearch

    Official install instructions at

    https://www.elastic.co/guide/en/elasticsearch/reference/8.3/deb.html

    See elasticsearch

  • Enable  memcached on Magento 2 in Plesk Server

    Enable memcached on Magento 2 in Plesk Server

    To install memcached, run

    apt install php-memcached
    apt install build-essential
    apt install autoconf automake gcc libmemcached-dev libhashkit-dev pkg-config plesk-php*-dev zlib1g-dev
    

    Enable memcached php module

    /opt/plesk/php/7.3/bin/pecl install memcached
    

    This is for PHP 7.3, change the path to pecl for your version of PHP.

    Activate memcached

    echo "extension=memcached.so" > /opt/plesk/php/7.3/etc/php.d/memcached.ini
    

    Update php handler

    plesk bin php_handler --reread
    

    Restart php-fpm

    systemctl stop plesk-php73-fpm.service
    systemctl start  plesk-php73-fpm.service
    

    Install memcached deamon

    apt install memcached
    

    Restart memcached

    systemctl enable memcached
    systemctl restart memcached
    

    Verify it is working with netstat

    malta2032:~# netstat -lntp | grep mem
    tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      30204/memcached     
    malta2032:~# 
    

    Activate memcached in Magento 2

    Edit file

    vi app/etc/env.php
    

    Find

        'session' => [
            'save' => 'files'
        ],
    

    Replace with

        'session' => [
            'save' => 'memcached',
            'save_path' => '127.0.0.1:11211'
        ],
    

    If you get error like

    Warning: SessionHandler::read(): open(127.0.0.1:6379/sess_0s39482mnk2hhoflf4d6odjuv2, O_RDWR) failed: No such file or directory (2) in /vendor/magento/framework/Session/SaveHandler/Native.php on line 22
    

    edit your php.ini and set “session.save_handler” from “files” to “memcached”.

    php session memcached

    See if memcached working

    To see if memcached is caching, you can use

    telnet 127.0.0.1  11211
    stats items
    

    memcached telnet
    To exit, type

    quit
    

    See Magento, Memcached

  • Magento 2 list enabled modules

    To list Modules in Magento 2, run

    php bin/magento module:status
    

    Example

    [markt-24@server public_html]$ php bin/magento module:status
    List of enabled modules:
    Magento_AdminAnalytics
    Magento_Store
    Magento_AdobeIms
    Magento_AdobeImsApi
    Magento_AdobeStockAdminUi
    Magento_MediaGallery
    Magento_AdobeStockAssetApi
    Magento_AdobeStockClient
    Magento_AdobeStockClientApi
    Magento_AdobeStockImage
    Magento_Directory
    Magento_AdobeStockImageApi
    Magento_AdvancedPricingImportExport
    Magento_Theme
    Magento_Amqp
    Magento_AmqpStore
    Magento_Config
    Magento_Backend
    Magento_Authorization
    Magento_Search
    Magento_Backup
    Magento_Eav
    Magento_Variable
    Magento_BundleImportExport
    Magento_CacheInvalidate
    Magento_Customer
    Magento_AdminNotification
    Magento_Indexer
    Magento_Security
    Magento_GraphQl
    Magento_EavGraphQl
    Magento_Cms
    Magento_CatalogImportExport
    Magento_Catalog
    Magento_CatalogInventory
    Magento_Rule
    Magento_Payment
    Magento_CatalogRuleGraphQl
    Magento_CatalogRule
    Magento_CatalogUrlRewrite
    Magento_StoreGraphQl
    Magento_Widget
    Magento_Quote
    Magento_SalesSequence
    Magento_CheckoutAgreementsGraphQl
    Magento_MediaGalleryUi
    Magento_CmsGraphQl
    Magento_CmsUrlRewrite
    Magento_CmsUrlRewriteGraphQl
    Magento_ComposerRootUpdatePlugin
    Magento_User
    Magento_Msrp
    Magento_Sales
    Magento_CatalogGraphQl
    Magento_Checkout
    Magento_Contact
    Magento_Cookie
    Magento_Cron
    Magento_Csp
    Magento_CurrencySymbol
    Magento_CatalogCustomerGraphQl
    Magento_Integration
    Magento_Downloadable
    Magento_CustomerGraphQl
    Magento_CustomerImportExport
    Magento_Deploy
    Magento_Developer
    Magento_Dhl
    Magento_Captcha
    Magento_DirectoryGraphQl
    Magento_QuoteGraphQl
    Magento_DownloadableGraphQl
    Magento_ImportExport
    Magento_ConfigurableProduct
    Magento_BundleGraphQl
    Magento_CatalogSearch
    Magento_AdvancedSearch
    Magento_Elasticsearch
    Magento_Email
    Magento_EncryptionKey
    Magento_Fedex
    Magento_GiftMessage
    Magento_GoogleAdwords
    Magento_GoogleAnalytics
    Magento_Ui
    Magento_GoogleShoppingAds
    Magento_CatalogCmsGraphQl
    Magento_PageCache
    Magento_GroupedProduct
    Magento_GroupedImportExport
    Magento_GroupedCatalogInventory
    Magento_GroupedProductGraphQl
    Magento_DownloadableImportExport
    Magento_Bundle
    Magento_InstantPurchase
    Magento_Analytics
    Magento_Inventory
    Magento_InventoryAdminUi
    Magento_InventoryAdvancedCheckout
    Magento_InventoryApi
    Magento_InventoryBundleImportExport
    Magento_InventoryBundleProduct
    Magento_InventoryBundleProductAdminUi
    Magento_InventoryBundleProductIndexer
    Magento_InventoryCatalog
    Magento_InventorySales
    Magento_InventoryCatalogAdminUi
    Magento_InventoryCatalogApi
    Magento_InventoryCatalogSearch
    Magento_InventoryConfigurableProduct
    Magento_InventoryConfigurableProductAdminUi
    Magento_InventoryConfigurableProductIndexer
    Magento_InventoryConfiguration
    Magento_InventoryConfigurationApi
    Magento_InventoryDistanceBasedSourceSelection
    Magento_InventoryDistanceBasedSourceSelectionAdminUi
    Magento_InventoryDistanceBasedSourceSelectionApi
    Magento_InventoryElasticsearch
    Magento_InventoryExportStockApi
    Magento_InventoryIndexer
    Magento_InventorySalesApi
    Magento_InventoryGroupedProduct
    Magento_InventoryGroupedProductAdminUi
    Magento_InventoryGroupedProductIndexer
    Magento_InventoryImportExport
    Magento_InventoryInStorePickupApi
    Magento_InventoryInStorePickupAdminUi
    Magento_InventorySourceSelectionApi
    Magento_InventoryInStorePickup
    Magento_InventoryInStorePickupGraphQl
    Magento_Shipping
    Magento_InventoryInStorePickupShippingApi
    Magento_InventoryInStorePickupQuoteGraphQl
    Magento_InventoryInStorePickupSales
    Magento_InventoryInStorePickupSalesApi
    Magento_InventoryInStorePickupQuote
    Magento_InventoryInStorePickupShipping
    Magento_InventoryInStorePickupShippingAdminUi
    Magento_Multishipping
    Magento_Webapi
    Magento_InventoryCache
    Magento_InventoryLowQuantityNotification
    Magento_Reports
    Magento_InventoryLowQuantityNotificationApi
    Magento_InventoryMultiDimensionalIndexerApi
    Magento_InventoryProductAlert
    Magento_InventoryRequisitionList
    Magento_InventoryReservations
    Magento_InventoryReservationCli
    Magento_InventoryReservationsApi
    Magento_InventoryExportStock
    Magento_InventorySalesAdminUi
    Magento_CatalogInventoryGraphQl
    Magento_InventorySalesFrontendUi
    Magento_InventorySetupFixtureGenerator
    Magento_InventoryShipping
    Magento_InventoryShippingAdminUi
    Magento_InventorySourceDeductionApi
    Magento_InventorySourceSelection
    Magento_InventoryInStorePickupFrontend
    Magento_LayeredNavigation
    Magento_LoginAsCustomer
    Magento_LoginAsCustomerAdminUi
    Magento_LoginAsCustomerApi
    Magento_LoginAsCustomerFrontendUi
    Magento_LoginAsCustomerLog
    Magento_LoginAsCustomerPageCache
    Magento_LoginAsCustomerQuote
    Magento_LoginAsCustomerSales
    Magento_Marketplace
    Magento_MediaContent
    Magento_MediaContentApi
    Magento_MediaContentCatalog
    Magento_MediaContentCms
    Magento_MediaContentSynchronization
    Magento_MediaContentSynchronizationApi
    Magento_MediaContentSynchronizationCatalog
    Magento_MediaContentSynchronizationCms
    Magento_AdobeStockAsset
    Magento_MediaGalleryApi
    Magento_MediaGalleryCatalog
    Magento_MediaGalleryIntegration
    Magento_MediaGallerySynchronization
    Magento_MediaGallerySynchronizationApi
    Magento_AdobeStockImageAdminUi
    Magento_MediaGalleryUiApi
    Magento_MediaStorage
    Magento_MessageQueue
    Magento_CatalogRuleConfigurable
    Magento_MsrpConfigurableProduct
    Magento_MsrpGroupedProduct
    Magento_InventoryInStorePickupMultishipping
    Magento_MysqlMq
    Magento_NewRelicReporting
    Magento_Newsletter
    Magento_OfflinePayments
    Magento_SalesRule
    Magento_GraphQlCache
    Magento_CardinalCommerce
    Magento_Vault
    Magento_Paypal
    Magento_PaypalGraphQl
    Magento_Persistent
    Magento_ProductAlert
    Magento_ProductVideo
    Magento_CheckoutAgreements
    Magento_QuoteAnalytics
    Magento_ConfigurableProductGraphQl
    Magento_ReCaptchaAdminUi
    Magento_ReCaptchaCheckout
    Magento_ReCaptchaContact
    Magento_ReCaptchaCustomer
    Magento_ReCaptchaFrontendUi
    Magento_ReCaptchaMigration
    Magento_ReCaptchaNewsletter
    Magento_ReCaptchaPaypal
    Magento_ReCaptchaReview
    Magento_ReCaptchaSendFriend
    Magento_ReCaptchaUi
    Magento_ReCaptchaUser
    Magento_ReCaptchaValidation
    Magento_ReCaptchaValidationApi
    Magento_ReCaptchaVersion2Checkbox
    Magento_ReCaptchaVersion2Invisible
    Magento_ReCaptchaVersion3Invisible
    Magento_RelatedProductGraphQl
    Magento_ReleaseNotification
    Magento_InventoryLowQuantityNotificationAdminUi
    Magento_RequireJs
    Magento_Review
    Magento_ReviewAnalytics
    Magento_Robots
    Magento_Rss
    Magento_Elasticsearch6
    Magento_ConfigurableProductSales
    Magento_SalesAnalytics
    Magento_SalesGraphQl
    Magento_SalesInventory
    Magento_OfflineShipping
    Magento_ConfigurableImportExport
    Magento_UrlRewrite
    Magento_Elasticsearch7
    Magento_CustomerAnalytics
    Magento_Securitytxt
    Magento_SendFriend
    Magento_SendFriendGraphQl
    Magento_InventoryInStorePickupSalesAdminUi
    Magento_Sitemap
    Magento_UrlRewriteGraphQl
    Magento_CustomerDownloadableGraphQl
    Magento_Swagger
    Magento_SwaggerWebapi
    Magento_SwaggerWebapiAsync
    Magento_Swatches
    Magento_SwatchesGraphQl
    Magento_SwatchesLayeredNavigation
    Magento_Tax
    Magento_TaxGraphQl
    Magento_TaxImportExport
    Magento_AsynchronousOperations
    Magento_ThemeGraphQl
    Magento_Tinymce3
    Magento_Translation
    Magento_GoogleOptimizer
    Magento_Ups
    Magento_SampleData
    Magento_CatalogUrlRewriteGraphQl
    Magento_CatalogAnalytics
    Magento_Usps
    Magento_InventoryGraphQl
    Magento_PaypalCaptcha
    Magento_VaultGraphQl
    Magento_Version
    Magento_InventoryInStorePickupWebapiExtension
    Magento_WebapiAsync
    Magento_WebapiSecurity
    Magento_Weee
    Magento_WeeeGraphQl
    Magento_CatalogWidget
    Magento_Wishlist
    Magento_WishlistAnalytics
    Magento_WishlistGraphQl
    Amazon_Core
    Amazon_Login
    Amazon_Payment
    Dotdigitalgroup_Email
    Dotdigitalgroup_Chat
    Klarna_Core
    Klarna_Ordermanagement
    Klarna_Onsitemessaging
    Klarna_Kp
    Magefan_Community
    Magefan_Blog
    Magefan_WysiwygAdvanced
    PayPal_Braintree
    PayPal_BraintreeGraphQl
    Sm_BackEnd
    Sm_CartQuickPro
    Sm_Categories
    Sm_CategoriesMenu
    Sm_FilterProducts
    Sm_ListingTabs
    Sm_Market
    Sm_MegaMenu
    Sm_SearchBox
    Sm_ShopBy
    Temando_ShippingRemover
    Vertex_Tax
    Vertex_AddressValidation
    Yotpo_Yotpo
    
    List of disabled modules:
    Magento_TwoFactorAuth
    
    [markt-24@server public_html]$
    

    See Magento 2

  • Magento Change URL

    Magento Change URL

    Magento store website URL in table core_config_data. This is the same for Magento 1 and Magento 2. To see the current URL, in phpMyAdmin or MySQL command line, run

    select * from core_config_data where path like '%_url';

    Normally this shows 2 entries. If it shows more than 2 entries, it is because you have more store configured in your Magento installation. In such a case, you should be careful to change the correct URL.

    To change the URL, run

    UPDATE core_config_data SET value = 'https://NEW_URL_HERE/' WHERE path = 'web/unsecure/base_url';
    UPDATE core_config_data SET value = 'https://NEW_URL_HERE/' WHERE path = 'web/secure/base_url';

    Replace https://NEW_URL_HERE/ with your new website URL.

    Magento 2

    If you move a site from one site to another with a different folder structure, some static resources may not work as they use symlink and the path does not exist. To fix this, you need to redeploy the static assets.

    Clear the pub/static directory (excluding the .htaccess file):

    rm -rf var/www/html/pub/static/* 

    Clear generated directory:

    rm -rf var/www/html/generated/*

    Generate static files.

    php -d memory_limit=-1 bin/magento setup:static-content:deploy -f

    If you have multiple languages, you can use

    php -d memory_limit=-1 bin/magento setup:static-content:deploy -f en_US en_GB

    Clear cache with the command

    php bin/magento cache:flush

    Magento 1

    If you use Magento 1, use the following command to flush the cache.

    php -r 'require "app/Mage.php"; Mage::app()->getCacheInstance()->flush();'

    See Magento

  • Install Elasticsearch 6 on Debian for Magento

    To install Elasticsearch for Magento on Debian, install Java 1.8 and apt-transport-https

    apt install -y openjdk-8-jdk-headless
    apt install -y apt-transport-https
    

    Add key

    wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
    

    Add repository

    echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-6.x.list
    

    Install Elasticsearch

    apt update
    apt install -y elasticsearch
    

    Enable and start Elasticsearch

    systemctl enable elasticsearch
    systemctl restart elasticsearch
    
  • Magento 1 Command Line Tool

    Magento 1 Command Line Tool

    Magento 2 comes with command line tool to manage magento installation. This help you to do many tasks like clearning cache, install extension easier.

    Magento 1 CLI is available from

    https://github.com/netz98/n98-magerun

    To install Magento 1 command line tool, go to Magento install folder and run

    wget https://files.magerun.net/n98-magerun.phar
    chmod +x ./n98-magerun.phar
    

    Now you will be able to use the command line with

    ./n98-magerun.phar
    

    Here is an example how to Upgrade an Extension using CLI

    # ./n98-magerun.phar extension:upgrade Auctane_ShipStation
    Checking dependencies of packages
    Starting to download Auctane_ShipStation-1.3.47.tgz ...
    ...done: 46,264 bytes
    Installing package community/Auctane_ShipStation 1.3.47
    Package community/Auctane_ShipStation 1.3.47 installed successfully
    Package upgraded: community/Auctane_ShipStation 1.3.47
    
    # 
    
  • Enable SSL in Magento 1.9

    To enable SSL in Magento, go to System > Configuration

    Magento 1.9 SSL

    Click on “Web” link on left menu.

    Magento Configuration

    On this page, set Auto-redirect to Base URL to No.

    Magento Auto-redirect to Base URL

    Under “Unsecure” option, change the URL to use HTTPS.

    Magento HTTPS

    Under “Secure” option, set “https” for Base URL. Set “Yes” for both “Use Secure URLs in Frontend” and “Use Secure URLs in Admin”.

    Magento enable SSL

    If your Home page is linking to non HTTPS link, this is because Default page is set to CMS page, you need to edit and replace content of CMS page to use HTTPS links under Magento Admin > CMS > Pages.

  • Change Magento 1.9  admin URL

    Change Magento 1.9 admin URL

    To change Magento admin URL, login to Magento Admin area.

    Go to System > Configuration

    On next page, from side menu, click on Admin menu.

    On next page

    Use Custom Admin Path = Yes
    Custom Admin Path = okadmin
    

    Replace “okadmin” with whatever folder name you need for your magento admin area.

    Click “Save Config”

    Edit file

    vi app/etc/local.xml
    

    Find

    < ![CDATA[admin]]>
    

    Replace admin with your new folder name for admin area.

    Now you need to Clean magento cache. This can be done with command

    cd /path/to/magento/install/dir
    rm -rf var/cache
    

    Now you admin area will work on new URL.

    Doing it with MySQL

    Here is the changes made on database when i changed a sites admin folder path to “localsense”.

    Some useful SQL

    select * from core_config_data where path like "%url";
    select * from core_config_data where path like "%custom_path%";
    

    You can just set the value for “admin/url/use_custom_path” to 1 and “admin/url/custom_path” to the new admin folder name you need.

  • Magento 1.9 store login not working in Chrome

    Magento 1.9 store login not working in Chrome

    On a site running Magento 1.9, user login is not working on Google Chrome.

    The problem is due to cookie setting in Magento. Login to Magento Admin, go to

    Admin > System > configuration > web > Session and Cookie Management

    Put your domain name in “Cookie Domain” text box and click Save Config.

    Magento

  • Clean Magento session folder

    On a VPS hosting Magento 1.9 disk was getting full. On checking, found var/session folder taking too much disk space.

    Disk usage was 34 GB.

    This folder is used to store PHP session files. You can delete them.

    I created a cronjob to delete the session files that are older.

    mkdir /usr/serverok/
    vi /usr/serverok/clean-session
    

    Add following content

    #!/bin/bash
    
    /bin/find /path/to/var/session -type f -mtime +10 -name "sess_*" -delete
    

    Make it executable

    chmod 755 /usr/serverok/clean-session
    

    Set a cronjob to run everyday

    @daily /usr/serverok/clean-session > /dev/null 2>&1
    

    Method 2 – Strong session in database

    Edit file

    vi app/etc/local.xml
    

    Find

    
    

    Replace with

    
    

    Magento