You need to apply for Residence Visa first, which will be provided for 1 year and may be renewed for additional 2 years of period. After it's expiration, you can apply for permanent residence visa. After getting the permanent visa, you will be able to apply Spanish Passport.
Spanish Passport
Spanish Passport