Tag: Magento

  • Magento 2 Your password has expired

    Magento 2 Your password has expired

    After resetting password on a Magento 2 installation, when trying to login to backend, I get following error message.

    Your password has expired; please contact your administrator.
    All other open sessions for this account were terminated.
    It's time to change your password.
    

    Magento 2 Password expired error

    To fix this error, on the command line, run the following commands

    php bin/magento config:set admin/security/password_is_forced 0
    php bin/magento config:set admin/security/password_lifetime 0
    php bin/magento cache:flush
    

    You can also update the database table admin_passwords and update the value of the “expires” column to a future date (UNIX timestamp)

    UPDATE admin_passwords SET expires=1999999998 WHERE user_id=USER_ID_HERE;
    

    In the above SQL command, replace USER_ID_HERE with the “user_id” of the admin user for which you get the password expired error message.

    Back to Magento

  • Magento 2 Your session has expired

    Magento 2 Your session has expired

    After migrating Magento 2 site to a new server with a different URL, adding an item to the cart produced the error message “Your session has expired”.

    First, I verified PHP session is working with a test script

    
    

    Renamed index.php to index.php.old and created a new index.php file with the above code. Every time I refreshed, I get a new number, which meant PHP session is working. If the number stay same on refresh, PHP session is not working, you need to look at your PHP configuration, and verify the session.save_path settings in php.ini is set properly and is writeable.

    Verify URLs are set properly.

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

    If you see wrong URL, update it with the command

    UPDATE core_config_data SET value = 'https://your-domain.tld/' WHERE path = 'web/unsecure/base_url';
    UPDATE core_config_data SET value = 'https://your-domain.tld/' WHERE path = 'web/secure/base_url';
    

    Also verify cookie settings, main domain is set properly.

    select * from core_config_data where path LIKE '%cookie%';
    

    Example

    mysql> select * from core_config_data where path LIKE '%cookie%';
    +-----------+---------+----------+-------------------------------------------------+----------------------+---------------------+
    | config_id | scope   | scope_id | path                                            | value                | updated_at          |
    +-----------+---------+----------+-------------------------------------------------+----------------------+---------------------+
    |        42 | default |        0 | web/default/cms_no_cookies                      | 404-not-found        | 2020-03-03 13:13:18 |
    |        49 | default |        0 | web/browser_capabilities/cookies                | 0                    | 2020-03-03 13:13:18 |
    |      1432 | default |        0 | newsletter/general/cookiename                   | es_newssubscribers   | 2020-03-03 13:13:18 |
    |      1433 | default |        0 | newsletter/general/cookielifetime               | 999                  | 2020-03-03 13:13:18 |
    |      2268 | default |        0 | system/external_page_cache/cookie_lifetime      | 3600                 | 2020-03-03 13:13:18 |
    |      2645 | default |        0 | magepsycho_easypathhints/general/save_in_cookie | 0                    | 2020-03-06 05:15:10 |
    |      3020 | default |        0 | web/cookie/cookie_path                          | /                    | 2020-08-31 13:36:11 |
    |      3021 | default |        0 | web/cookie/cookie_domain                        | 5351499f87.nxcli.net | 2021-09-30 12:24:53 |
    |      3022 | default |        0 | web/cookie/cookie_httponly                      | 1                    | 2020-08-26 12:29:36 |
    +-----------+---------+----------+-------------------------------------------------+----------------------+---------------------+
    9 rows in set (0.01 sec)
    
    mysql>
    

    Look for setting web/cookie/cookie_domain, if it is wrong domain, set it to the new domain or leave it empty. In this case, the domain was set to old URL - 5351499f87.nxcli.net

    UPDATE core_config_data SET value='' WHERE path = 'web/cookie/cookie_domain';
    

    Clear magento cache

    php bin/magento c:c
    php bin/magento c:f
    

    Back to Magento

  • Magento 2 Disable Two-Factor Authorization

    Magento 2 Disable Two-Factor Authorization

    On a Magento 2.4 fresh installation, when I log in to the backend, I got the following error message.

    You need to configure Two-Factor Authorization in order to proceed to your store's admin area
    An E-mail was sent to you with further instructions
    

    Magento Two-Factor Authorization

    To disable Magento Two-Factor Authorization, run the command

    bin/magento module:disable Magento_TwoFactorAuth
    bin/magento setup:di:compile
    

    Back to Magento

  • Validate class not found from basename Magento\Framework\Validator\EmailAddress

    Validate class not found from basename Magento\Framework\Validator\EmailAddress

    After Migrating a Magento site from shared hosting to a dedicated server running Plesk, when doing check out, I get an error message

    Unable to save address. Please check input data.
    

    When checking the error log var/log/exception.log, found following error message

    [2022-05-10 09:30:36] main.CRITICAL: Validate class not found from basename 'Magento\Framework\Validator\EmailAddress' {"exception":"[object] (Zend_Validate_Exception(code: 0): Validate class not found from basename 'Magento\\Framework\\Validator\\EmailAddress' at /var/www/vhosts/domain.tld/httpdocs/vendor/magento/zendframework1/library/Zend/Validate.php:244)"} []
    

    To fix this, in Plesk change PHP settings for the website

    Plesk PHP settings

    Change include_path from

    .:/opt/plesk/php/7.1/share/pear
    

    To

    .:/var/www/vhosts/DOMAIN.TLD/httpdocs/vendor/magento/zendframework1/library
    

    In the above, replace DOMAIN.TLD with your actual domain name.

    See Magento

  • Magento 2 static resources missing after server change

    Magento 2 static resources missing after server change

    After Migrating a Magento 2 site to a new server with a different folder structure (document root), static resources like CSS and JS files on the site stopped working. This error is because Magento uses symlinks, when you move the website to a new server with a different folder structure, these symlinks stop working.

    To fix this, we need to regenerate static files.

    First, make a copy of .htaccess file inside the static folder

    cp pub/static/.htaccess pub/.htaccess-sok-static
    

    Rename the static folder

    mv pub/static pub/static-`date +"%Y-%m-%d-%H-%M-%S"`
    

    Deploy the static resources

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

    If you have multiple languages, specify the languages separated by space

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

    Clear cache

    php bin/magento cache:flush
    

    Copy .htaccess file back to the “static” folder

    cp pub/.htaccess-sok-static pub/static/.htaccess
    

    Now static resources will work.

    Back to Magento

  • How to clean Magento 1.x database

    How to clean Magento 1.x database

    When I try to make a copy of the Magento 1 site, it takes forever to restore the MySQL database. The size of the database was 8.6 GB. On checking, I found some tables like report_event are very large.

    To clear the tables, Magento provides a script, you can run it with

    php -f shell/log.php clean --days 2
    

    This will delete all logs that are 2 days old from the MySQL database. If you need to keep logs for 60 days, you can use the following command

    php -f shell/log.php clean --days 60
    

    clean magento 1 mysql database

    After running the log cleaner script, the size of the database changed from 8.6 GB to 829 MB.

    magento database size before and after cleaning

    Cleaning Manually

    If you need to clean MySQL database manually using phpMyAdmin or MySQL command prompt, you can run the following SQL commands

    SET FOREIGN_KEY_CHECKS=0;
    TRUNCATE dataflow_batch_export;
    TRUNCATE dataflow_batch_import;
    TRUNCATE log_customer;
    TRUNCATE log_quote;
    TRUNCATE log_summary;
    TRUNCATE log_summary_type;
    TRUNCATE log_url;
    TRUNCATE log_url_info;
    TRUNCATE log_visitor;
    TRUNCATE log_visitor_info;
    TRUNCATE log_visitor_online;
    TRUNCATE report_viewed_product_index;
    TRUNCATE report_compared_product_index;
    TRUNCATE report_event;
    TRUNCATE index_event;
    SET FOREIGN_KEY_CHECKS=1;
    

    Using Magento Backend

    You can log in to the Magento Admin area, then go to

    System > Configuration > Advanced > System > Log Cleaning
    

    You have the option to auto clean the Magento store logs.

  • Can’t create table `catalog_product_relation` (errno: 140 “Wrong create options”)

    Can’t create table `catalog_product_relation` (errno: 140 “Wrong create options”)

    When I try to restore the MySQL database of a Magento 1.x site on MariaDB 10.3.32 (source MySQL 5.7.36), I get the following error

    boby@sok-01:/www/magento/amazingplans/backup$ mysql amazingplans < amazingp_demo.sql 
    ERROR 1005 (HY000) at line 4080: Can't create table `amazingplans`.`catalog_product_relation` (errno: 140 "Wrong create options")
    boby@sok-01:/www/magento/amazingplans/backup$
    

    On checking the line in the error message, I found the error is due to the following SQL statement.

    CREATE TABLE `catalog_product_relation` (
      `parent_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Parent ID',
      `child_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Child ID',
      PRIMARY KEY (`parent_id`,`child_id`),
      KEY `IDX_CATALOG_PRODUCT_RELATION_CHILD_ID` (`child_id`),
      CONSTRAINT `FK_CAT_PRD_RELATION_CHILD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`child_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
      CONSTRAINT `FK_CAT_PRD_RELATION_PARENT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`parent_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Catalog Product Relation Table';
    

    Fixed it by removing

    ROW_FORMAT=FIXED
    

    From the SQL.

  • Magento 2 Password reset

    Magento 2 Password reset

    Magento 2 is popular open-source eCommerce software. If you lost admin password for your Magento 2 website, you can follow the instructions below to reset your password.

    Find the crypt key from file

    app/etc/evn.php
    

    Once you have the key, you can run following SQL command using MySQL command line or phpMyAdmin.

    UPDATE admin_user SET password = CONCAT(SHA2('CRYPTO_KEYnewPassword', 256), ':CRYPTO_KEY:1') WHERE username = 'admin';
    

    In the SQL above, replace

    CRYPTO_KEY = cyrpt key from your app/etc/evn.php file.
    newPassword = replace with new password you need.

    See Magento

  • Magento 2 admin too many redirects error

    Magento 2 admin too many redirects error

    On a Magento 2 site, after migrating to a new domain, when accessing the admin area, I get too many redirect error.

    magento 2 admin redirect error

    To fix, using the following SQL command verify URLs are correct.

    SELECT * FROM  core_config_data WHERE path like '%_url';
    

    if any URL is not correct, fix it.

    Then run the following commands in the Magento directory.

    php bin/magento cache:clean
    php bin/magento cache:flush
    php bin/magento indexer:reindex
    php bin/magento setup:upgrade
    php bin/magento setup:static-content:deploy -f
    

    See Magento

  • Magento Disable CDN

    Magento Disable CDN

    To see URLs configured on a Magento 2 installation, run the following SQL command

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

    Example

    mysql> select * from core_config_data where path like '%_url';
    +-----------+---------+----------+------------------------------------+------------------------------------------------------------------------+---------------------+
    | config_id | scope   | scope_id | path                               | value                                                                  | updated_at          |
    +-----------+---------+----------+------------------------------------+------------------------------------------------------------------------+---------------------+
    |        10 | default |        0 | web/unsecure/base_url              | https://buildingplans.com/                                             | 2021-11-09 19:39:03 |
    |       200 | default |        0 | payment/braintree/descriptor_url   | NULL                                                                   | 2020-10-14 06:23:31 |
    |       587 | default |        0 | web/unsecure/base_static_url       | https://621984-2039577-raikfcquaxqncofqfm.stackpathdns.com/pub/static/ | 2021-08-05 10:18:30 |
    |       588 | default |        0 | web/unsecure/base_media_url        | https://621984-2039577-raikfcquaxqncofqfm.stackpathdns.com/pub/media/  | 2021-08-05 10:18:30 |
    |       589 | default |        0 | web/secure/base_url                | https://buildingplans.com/                                             | 2021-11-09 19:39:03 |
    |       591 | default |        0 | web/secure/base_static_url         | https://621984-2039577-raikfcquaxqncofqfm.stackpathdns.com/pub/static/ | 2021-08-05 10:18:30 |
    |       592 | default |        0 | web/secure/base_media_url          | https://621984-2039577-raikfcquaxqncofqfm.stackpathdns.com/pub/media/  | 2021-08-05 10:18:30 |
    +-----------+---------+----------+------------------------------------+------------------------------------------------------------------------+---------------------+
    8 rows in set (0.00 sec)
    
    mysql> 
    

    In this case, the site use stackpath CDN.

    To remove CDN, you can delete the entries related stackpathdns with SQL command

    delete from core_config_data where path = 'web/unsecure/base_static_url';
    delete from core_config_data where path = 'web/unsecure/base_media_url';
    delete from core_config_data where path = 'web/secure/base_static_url';
    delete from core_config_data where path = 'web/secure/base_media_url';
    

    Now you need to re-deploy the static assets with

    php bin/magento setup:static-content:deploy
    

    clear cache

    php bin/magento cache:flush
    
  • How to Enable Magento 2 Cronjob

    Magento uses cron jobs for numerous features to schedule activities. To enable the cron job in Magento 2, log in to the server using SSH. Switch to the appropriate user if you are logged in as root. Now run command

    php bin/magento cron:install
    

    If you need to remove the cronjob, run

    php bin/magento cron:remove
    

    set cronjob in magento 2

    See Magento

  • Magento catalog_product_relation MySQL Error

    On transferring a Magento website Database running on MySQL 5.7.34 to MariaDB 10.2.39, I get the following error

    [root@server52 etc]# mysql buildingplans_m1 < db.sql
    ERROR 1005 (HY000) at line 4080: Can't create table `buildingplans_m1`.`catalog_product_relation` (errno: 140 "Wrong create options")
    [root@server52 etc]# 
    

    SQL Strict mode was already off on this MySQL server.

    MariaDB [(none)]> select @@sql_mode;
    +------------+
    | @@sql_mode |
    +------------+
    |            |
    +------------+
    1 row in set (0.00 sec)
    
    MariaDB [(none)]>
    

    To fix the problem, edited the db.sql file, added

    set innodb_strict_mode = off;
    

    at the top of the file. After this change, the restore worked without any error.

    See Magento