With the discovery of hundreds of exoplanets and a potentially huge number of Earth-like planets waiting to be discovered, the conditions for their habitability have become a focal point in exoplanetary research. The classical picture of habitable zones primarily relies on the stellar flux allowing liquid water to exist on the surface of an Earth-like planet with a suitable atmosphere. However, numerous further stellar and planetary properties constrain habitability. Apart from geophysical processes depending on the internal structure and composition of a planet, a complex array of astrophysical factors additionally determine habitability. Among these, variable stellar UV, EUV, and X-ray radiation, stellar and interplanetary magnetic fields, ionized winds, and energetic particles control the constitution of upper planetary atmospheres and their physical and chemical evolution. Short- and long-term stellar variability necessitates full time-dependent studies to understand planetary habitability at any point in time. Furthermore, dynamical effects in planetary systems and transport of water to Earth-like planets set fundamentally important constraints. We will review these astrophysical conditions for habitability under the crucial aspects of the long-term evolution of stellar properties, the consequent extreme conditions in the early evolutionary phase of planetary systems, and the important interplay between properties of the host star and its planets.