Pour 1 1/2 tbsp. of liquid castile soap, 1 qt. of water, and 3 drops of vegetable oil in a spray bottle. The liquid castile soap will kill the fungus gnats, and is natural so it won't affect the basil when you to eat the herb.
Shake the ingredients in the spray bottle each time you want to use it. Aim the homemade insecticidal soap at the gnats and begin spraying.
Spray the basil plants once you are done spraying the gnats surrounding the plants so that all future gnats stay away from the basil.
Reapply once per week to keep a new infestation from forming.