Materia is obtained by first spiritbonding a piece of gear through repeated use. Once it's at 100% (visible on the item's tooltip), it can be converted to materia by opening the menu on the item and pressing Convert. There are many cheap (~500gil) materia available on the Market Board if you want to do it quicker. The stat ones (dexterity 1, strength 1, etc) and elemental resistance ones (fire 1, ice 1, water 1, etc) are the best bet if you're after the trophy quickly and cheaply.
As well as the materia, you'll need a catalyst -- Namely, Carbonised Matter. Catalysts are gathered by miners or botanists (or purchaseable cheaply on the MB). You'll need the grade equivalent to the level of materia you're melding -- So if you're melding a grade I materia, you only need a Grade I Carbonised Matter; Grade II for Grade II, etc.
To meld the materia to a piece of gear, it first needs to have at least one materia slot (small empty circles under the stats). You can craft up to 5 materia to one item, but any melds past the amount of materia slots on the item has an increasing chance to fail, wasting the materia and catalyst.
Secondly, you need the required level in the specified craft. The level and craft required is also visible on the tooltip.
Thirdly, you need to have progressed far enough in the story, and have completed the short sidequest found in Central Thanalan at the bonfire northeast of the Aetheryte, available upon hitting Level 25 in a Disciple of the Hand class.