Migration regulation
Migration to Sweden is primarily regulated through the Aliens Act. This law regulates visas, residence permits, work and study permits etc, and how state agencies should handle immigration and immigration cases.
You can find the official text of the law here and an unofficial English translation here.
Migration to Sweden is handled through the Migration Agency (Migrationsverket), a public authority. The agency maintains a detailed and up to date website that covers and describes the procedure in many migration related situations, in Swedish, English, and other languages. According to the Migration Agency, a residence permit (uppehållstillstånd) is a document that allows a foreign national to live and reside in Sweden, either for a limited period of time or permanently, while a visa (visum) is a conditional authorization to enter the country and stay for less than 90 days.
As a doctoral student intending to move to Sweden, you may need to apply for a residence permit and/or a visa. To determine whether you need to apply, you can consult the Migration’s Agency website, or contact the agency.
The type of permit most often relevant for doctoral students is the permit for higher education, which gives you the right to study and work in Sweden. You can apply for a new permit before the old one has expired.
In addition to the residence permit, you may need to apply for a visa in order to travel to Sweden. The Agency maintains a list of countries whose citizens need a visa to enter Sweden, here. Visa applications are handled by the Swedish embassies and consulates, sometimes through an external service provider.
Once you have lived in Sweden for four years, you may be able to apply for permanent right of residence (if you fulfill the other requirements).
If you do not qualify for permanent residency at the end of your doctoral studies you may still qualify to stay in Sweden on a permit for looking for work after studies.