Non EU resident persons can apply for a Spanish residency permit, including long term one, when they have a house in Spain, but apart from that they also need several other requisites, such as proof of financial means (800 € or more per month per person), a Visa for residency application issued by the Spanish Consulate in your country, and some other medical and official certificates of good standing concerning health and good behaviour in your original country