Building DevSecOps solutions using AWS, Terraform and Kubernetes

Magento Tips - List All Modules

  • 9th October 2021
Screenshot showing list of magento 2 modules

How do I list all the magento modules?

Simple! First, navigate to your project directory and run this bash script to make sure we have an XML parser installed:

# Install libxml2-utils dependency
if command -v apt-get >/dev/null; then
  sudo apt-get --yes install libxml2-utils
fi

Then run this bash snippet to export a full list of modules outside of the Magento namespace, along with the current version installed.

# List modules outside of Magento namespace
find . -name module.xml |
while read filename
do
    MODULE_NAME=$(xmllint --xpath 'string(//config/module/@name)' $filename)
    MODULE_VERSION=$(xmllint --xpath 'string(//config/module/@setup_version)' $filename)
    if [[ $MODULE_NAME != "Magento_"* ]]; then
        echo $MODULE_NAME,$MODULE_VERSION
    fi;
done

Why should I use this?

This is a key tool in performing a security audit on a magento website.

If you have freshly inherited a magento project then it is key that you understand what is currently installed on the site.

And then going forward, it is even more important to understand which modules are out of date. Running this bash script will give you an oversight of the current installed versions so you can quickly check when you need to install new versions.

Why a bash script?

Bash scripts can be run almost universally, and they won't suffer issues caused by PHP upgrades.

A small bash script to avoid an extra dependency is an excellent trade-off in any calculation.

But I already have magerun installed

Brilliant! Then just run:

./n98-magerun2.phar dev:module:list

Despite not being built for the cloud, magerun is still a great addition to the toolbox.

Rhuaridh

Please get in touch through my socials if you would like to ask any questions - I am always happy to speak tech!