UPS bible written by Spence Harbar (for sharepoint 2010, but everything is the same in 2013):
http://www.harbar.net/articles/sp2010ups.aspx
In short:
Before starting:
Grant „Allow logon Locally“ to domain\spFarm account and add domain\spFarm to local admins on application Server.
Create new Web Application and site collection for mysites host: for example http://mysites using Content app pool running account domain\spContent
Create new User Profile Service Application
Service app pool is „Sharepoint Web Services Default“ running by domain\spService
Log on with domain\spFarm, then log of, then log on again (for user policies be applied correctly)
and start:
User Profile Service, then started:
User Profile Synchronization Service (wait about 2 min while starting),
then started:
IISRESET
Log off
Log on domain\spadmin
Remove domain\spFarm from local admins
Add domain\spFarm to „Allow log on locally“
Add domain\spFarm to „Log on as service“
Check the permissions on
HKLM\SYSTEM\CurrentControlSet\Services\FIMSynchronizationService\Parameters and see if your Farm Account is present. If not – add spfarm account with read permissions.
In windows services find Forefront Identity Manager Synchronization Service and set the startup type to Automatic (Delayed Start). Then grant the Network Service account basic "Read & Execute/List folder contents/Read" permissions to the C:\Program Files\Microsoft Office Servers\14.0 directory.
After starting services Configure Profile Synchronization connection using domain\spProfileSync
If stuck on starting:
Get-SPServiceInstance | Where-Object {$_.TypeName -eq "User Profile Synchronization Service"}
Stop-SPServiceInstance ups-service-guid-blablablabla