Magento tips and tricks for developers and server admins

Through this post we have tried to gather some useful tricks and tips related to Magento that are frequently required during development and deployment.

How to update Magento site urls through command line?

You can update magento site urls through magento cli commands. Just go to your magento site root and run below commands:

php bin/magento setup:store-config:set --base-url="http://domain.com/"
php bin/magento setup:store-config:set --secure-base-url="https://domain.com/"

Replace domain.com with your actual domain name.

You can also update magento site urlsĀ  from database, connect to the database server and run below commands:

update core_config_data set value = 'http://domain.com/' where path = 'web/unsecure/base_url';
update core_config_data set value = 'https://domain.com/' where path = 'web/secure/base_url';

Replace domain.com with your actual domain name.

How to clean magento cache through CLI?

You can use below set of commands to clean magento cache:

php bin/magento cache:flush
php bin/magento cache:clean

How to clear magento compiled code and cache?

php bin/magento setup:upgrade

Prevent old generated files from being deleted:

php bin/magento setup:upgrade --keep-generated

How to do magento code generation?

php bin/magento setup:di:compile

How to do magento static view file generation?

php bin/magento setup:static-content:deploy

What to include in git ignore file for Magento 2?

You can use following contents in git ignore file for Magento 2 Site:

### Start Magento2 GitIgnore ###

/.buildpath
/.cache
/.metadata
/.project
/.settings
/.vscode
atlassian*
/nbproject
/robots.txt
/pub/robots.txt
/sitemap
/sitemap.xml
/pub/sitemap
/pub/sitemap.xml
/.idea
/.gitattributes
/app/config_sandbox
/app/etc/config.php
/app/etc/env.php
/app/code/Magento/TestModule*
/lib/internal/flex/uploader/.actionScriptProperties
/lib/internal/flex/uploader/.flexProperties
/lib/internal/flex/uploader/.project
/lib/internal/flex/uploader/.settings
/lib/internal/flex/varien/.actionScriptProperties
/lib/internal/flex/varien/.flexLibProperties
/lib/internal/flex/varien/.project
/lib/internal/flex/varien/.settings
/node_modules
/.grunt
/Gruntfile.js
/package.json
/.php_cs
/.php_cs.cache
/grunt-config.json
/pub/media/*.*
!/pub/media/.htaccess
/pub/media/attribute/*
!/pub/media/attribute/.htaccess
/pub/media/analytics/*
/pub/media/catalog/*
!/pub/media/catalog/.htaccess
/pub/media/customer/*
!/pub/media/customer/.htaccess
/pub/media/downloadable/*
!/pub/media/downloadable/.htaccess
/pub/media/favicon/*
/pub/media/import/*
!/pub/media/import/.htaccess
/pub/media/logo/*
/pub/media/custom_options/*
!/pub/media/custom_options/.htaccess
/pub/media/theme/*
/pub/media/theme_customization/*
!/pub/media/theme_customization/.htaccess
/pub/media/wysiwyg/*
!/pub/media/wysiwyg/.htaccess
/pub/media/tmp/*
!/pub/media/tmp/.htaccess
/pub/media/captcha/*
/pub/static/*
!/pub/static/.htaccess
/var/*
!/var/.htaccess
/vendor/*
!/vendor/.htaccess
/generated/*
!/generated/.htaccess
.DS_Store

### End Magento2 GitIgnore ###
Help us Grow

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code