It is certainly possible to start a business as a foreigner in Spain. You just need a business plan, enough capital, and the right documentation. Some of these things will differ depending on whether you want to be self-employed or start a limited company.
For those wishing to start a business on a self-employed basis (Autónomo), you will first need two things before beginning the startup process. You will need a work permit and a national identification number (NIE). To obtain a work permit for setting up an Autónomo, you will need to submit a business plan, a copy of the documentation proving sufficient training and experience, and proof of sufficient finances to support yourself and do business. This will accompany other documentation and forms required by Spanish authorities. Citizens from EU countries do not need to apply for a work visa, but do need to apply for a NIE.
Like a work visa, a NIE can be obtained at a Spanish Consular office, but can also be obtained at a police station in Spain. This number will serve as your tax identification number and allow you to register, open a bank account, and proceed with the rest of the required steps for starting a business. You will also need to register with the Spanish census authorities (el padrón). Once these requirements for living and doing business in Spain are met, you simply need to go through the rest of the steps for setting up a business. One is obtaining an electronic signature or digital certificate as this is often a requirement in Spain. Others include registering with the tax authorities, social security authorities, and getting whatever licenses and permissions may be necessary.
If you wish to start a limited company (Sociedad Limitada), there will be additional requirements. You will not need to get a work permit, but you will need a NIE. Additionally, you will need to open a Spanish bank account with a minimum deposit of 3000€. Because there will be Notarial requirements, it may also be a good idea to seek a Power of Attorney as well as an electronic signature so that someone, such as a lawyer, can submit registrations and sign documents on your behalf. Non-residents will also need to submit a Form 030 and receive a national tax ID (NIF). Once these fulfillments have been met, you may proceed with all of the other required steps such and company registry and obtaining a company tax ID (CIF). With that your business will be established.