Judy,
SHORT ANSWER: You may not begin the process to immigrate to Portugal while present in Portugal. Sorry.
LONGER ANSWER:
Immigrating to Portugal for non-EU citizens is a Two-Step Process, each with specific, though somewhat confusing, names
1st Step-
A) Apply for a Portuguese Residence VISA. The Portuguese Residence VISA is regulated by the Schengan Agreement and Portuguese law. You may see the Portuguese Residence VISA referred to as a "Schengan Area Visa".
B) Obtained from a Portuguese Consulate in the country of your residence. For example, Americans apply for the Portuguese Residence VISA from one of the several Portuguese Consulates in America, such as San Francisco or Washington DC. You may NOT apply for the Portuguese Residence VISA while physically present in Portugal. Sorry, again.
C) Required documents:
1. Completed Application form for a Portuguese Residence VISA (Schengen Area Visa). Available online.
2. Passport that is valid for at least 6 months after the expiry date of the visa for which you're applying (which will be valid for 4 months)
3. Two recent passport-size color photos
4. Personal statement declaring the reasons why you wish to obtain Portugal residency
5. Proof of financial means / proof of sufficient funds
6. FBI criminal record certificate (and, if you've lived outside the US in the last year, a police record report from that country)
7. Proof of private health insurance coverage, including repatriation cover
8. Proof of accommodation in Portugal (property title deed, rental agreement, letter of invitation or property loan agreement),
D) The Portuguese Residence VISA, when granted, is for a 120-day period during which you MUST travel to Portugal to advance to the 2nd Step.
2nd Step-
A) Once in Portugal on your 120-day Portuguese Residence VISA, you must apply for your Temporary Residence PERMIT. Note: 1st Step, in America for example, yields a VISA, the 2nd Step in Portugal yields a PERMIT.
B) The Application for Temporary Residence PERMIT is lodged at the offices of the Serviço de Estrangeiros e Fronteiras (SEF). See website . Offices are located throughout Portugal.
C) Once granted, the Temporary Residence PERMIT is valid for one year and you are permitted to remain in Portugal. You may also you move freely about the Schengan Area countries. NOTE: You must renew the Temporary Residence PERMIT before the one year expires. This is also at the SEF. You will be then granted a 2-year Temporary Residence PERMIT. In addition to being able to remain in Portugal, you are allowed to move freely about the Schengan Area countries.
I hope this helps.
Robbie