My question is: which port(s) on the firewall must be opened, to get it work.
Ports which are used for debugging purposes are set in Tools > Preferences > Debugger. Here you can also set your own port range or set it more narrow.
But this is not enough to open. You also have to set port forwarding to your client PC, where you are debugging your application, if you are behind some firewall.
So when I set minimum port = maximum port = 4000 it only needs port 4000?
Do you know this also matters for application?
You can try. I use for example range of 100. I suggest you to use for beginning some wider range and after you will see that debugging work ok with this settings, then you can set maybe just one if is really necessary.