Bacteria's relationship to the sun depends on two aspects: one, that the sun is the source of all the heat on earth and secondly, that sun's rays are used to make all the food in any ecosystem. Bacteria require a certain temperature for their growth, survival and reproduction. Depending on temperature preference, bacteria can be classified as mesophiles, thermophiles, extremophiles, etc. The sun's rays result in different temperature in different regions of the world, which provides habitats for different types of bacteria. Bacterial growth and survival depends on food or substrate. Both plants and bacteria can produce substrate via photosynthesis, which requires sunlight as an input to produce food. Hence bacteria are dependent on sun for survival, maintenance, growth and other functions.
Hope this helps.