Wash all the ingredients going into your oil and let them dry as much as possible - preferably overnight. Bacteria can't grow in the olive oil itself, but it can grow in the water left on the ingredients going into the oil.
Also, find a bottle that has a good seal. Canning jars work well, but if you want something more elegant, look for a container like the Ikea Slom bottle that has a rubber stopper. Wash and dry your bottle thoroughly.
Bruise your herbs gently to start to expose their oils and put them in your olive oil jar. Spices can be lightly toasted and crushed in a mortar and pestle. Fruits like chili peppers or lemons can be sliced thinly.
Cover the ingredients with olive oil, seal the bottle, and let it sit in a cool, dark place for 1-2 weeks before using it. The oil will slowly infuse over this time. Do a taste test every so often so see how it's coming along. Strain out the solids and re-bottle the oil once the flavor is to your liking.
You can also heat the oil and ingredients in a saucepan on medium-low heat (cook to 180°), let the oil cool, and then strain out the ingredients before bottling the infused oil. This makes the oil infuse more quickly and reduces some of the risk of bacteria growth, but it can also affect the flavor and quality of the olive oil.
Botulism is definitely a concern when making any kind of infused olive oil, especially with garlic-infused olive oil. Infused olive oil will generally keep for up to one month, especially if kept refrigerated. If the ingredients in the olive oil start to show any signs of spoilage, discard the rest of the oil immediately.
Here are a few infused oil recipes to help inspire!
Have you ever made infused olive oil? What are your favorite kinds?
Related: Cooking Basics: Very Easy Pickling