The lunar phase depends on the Moon's position
in orbit around the Earth,
and the Earth's position in orbit around the sun.

This diagram looks down on Earth from a position over the north pole.
Earth's rotation and the moon's orbit are both counter-clockwise here.
From this diagram, we can see, for example, that the full moon will always rise at sunset,
and that the waning crescent moon is high overhead around 9:00 AM local time.

For more information see Wikipedia's entry about lunar phases.