How to create a empty module? What is the most basic valid module one can create in Drupal?

It would be useful to have a simple blueprint available, for anyone just getting started with Drupal.
The below instructions allows one to create an empty module, and is helpful for anyone just getting started with module building. If you have troubles getting your first module working, or even showing up in Drupal, ensure you've read all the instructions below.

Drupal 8

A project must at least have


A machine name.
An yaml info file named after the machine name, in the form module-machine-name.info.yml with the following attributes:

name: A humanly readable name
type: A type, defining to be a module.
core: The major Drupal core version the module is compatible with, 8.x, in this case.

An empty module file, name in the form module-machine-name.module


Drupal looks for modules in these locations, as seen from the web root:


/modules/
sites/[example.com]/modules
sites/default/modules
profiles/[install-profile]/modules


Technically, Drupal also looks for modules in core/modules, but one should never, place modules there, hence it's not on the list above.

An example module structure, for a module with the machine name helloworld, would look like this:

/modules/helloworld/helloworld.info.yml

/modules/helloworld/helloworld.module

Notice that both the info and module file as named exactly the same as the machine name, which is important.

The module file may be empty, but the info file must contain a few minimum values for Drupal to recognize it as a module. For our helloworld module, that could look like:

name: 'Hello world module to demonstrate module building'
core: 8.x
type: module


If you follow the above instructions, you should be be able to get a new module listed in your Drupal site, although it won't do anything, at this stage.

Drupal 7

A module must at least have


A machine name.
A humanly readable name
An info file named after the machine name.
An empty module file.


To be loadable by Drupal, it must also define which core version it is compatible with.

Further Drupal looks for modules in these locations:


sites/all/modules/
sites/[example.com]/modules
sites/default/modules
profiles/[install-profile]/modules


Technically, Drupal also looks for modules in modules, but one should never, place modules there, hence it's not on the list.

An example module structure, for a module with the machine name helloworld, would look like this:

sites/all/modules/helloworld/helloworld.info

sites/all/modules/helloworld/helloworld.module

Notice that both the info and module file as named exactly the same as the machine name, which is important.

The module file may be empty, but the info file must contain the humanly readable name of the module, and the core version the module is compatible with.

For our helloworld module, that could look like:

name = Hello world module to demonstrate module building
core = 7.x


If you follow the above instructions, you should be be able to get a new module listed in your Drupal site, although it won't do anything, at this stage.