My name is raquel and I am from Portugal and live near the border with Spain. So I think I can help you. I also go often on holidays to spain.
So starting with the first question, alcohol and cigarettes. In Portugal you can buy it if you are 16 years old or older. I am also almost sure that the same happens in Spain.
As for the prices, honestly I dont thik you will get by with only 5 euros. But I will try tro help you.
First of all, cigarettes here cost about 2,5 €, which is just half the money you want to spend. And alcohol can be even expensive. For example, a box of 6 beers would cost about 2,30€, and a single beer 0.5 €. Please remember that these prices are in supermarkets.
As for food, in the end I will write you a letter with some prices in supermarkets.
Weather, trust me, weather you go to Spain or Portugal in august, you will find excellent weather, quite hot. Not only in the south, in whole countries. For more weather questions, go to weather.yahoo.com/ you will find there some weather forecasts.
In Portugal, sleeping in a tent in the beach is illegal. Just sleeping, I guess it also might be but you wont probably any problem with that. But I still dont recommend you any of these choices, because I have some doubts about the safeness of it. It might be a bit dangerous depending on the beach. As for sleeping in train station, I guess its perfectly safe and you wont have problems with that. here in Portugal, we have some kind of hotels for students, in wich you would find very acceptable prices. Check here the website rail.shop/hostelworld
And I guess that is it. But I want to tell you one more time, I dont think it is possible to get by with only 5€ in Portugal or Spain.
Some prices in spain or portugal (these refer to portugal but in spain it wont be very different, perhaps just a bit more expensive):
A bread: 0.1€
A botle of 1.5l of water: 0,4€
A botle of 1,5 coke: 1€
A can of coke: 0.5€
A small botle or can of berr: 0.5
Cigarrettes: 2,50 (in spain might be more expensive)
A big mac in (menu) MCDonalds: about 4€
A box of cookies (depends): more or less 1€
A chocolate: the cheapest one about 0.6€
A fish in a acn (atum in portugal, I dont know in portuguese): 1,3€
A box of cereals: 3.2€
A 1l milk: 0.7€
4 yougurths: 1.1€
Notice that these prices are for supermarkes, buying a bear in a bar will be more expensive.
I hope I helped you! And come to Portugal and Spain! You will find very nice cities, places, beaches and people!
Best wishes for your trip,