I can relate to this, but for the most part this is in the past for me (but even still I struggle sometimes in this area--meaning I don't think it ever really goes away totally).
Now, as someone who has been EXTREMELY shy and has managed to come back from that and be semi-outgoing (I'm still not extremely extroverted, but at least I finally have the confidence to hold a conversation with people and not get nervous--which I consider to be a major victory in my life), let me give you some tips and pointers that helped me.
First of all, RELAXATION. That's the crux of your problem. You have conditioned yourself into thinking the person you are talking to is better than you in some way. THEY ARE NOT. I know this sounds semi-gross, but that beautiful, cute, and/or popular girl you are talking to uses the bathroom like you, she gets sick and throws up like you do, she gets boogers (yeah that's crude I know

) like you do, and there's even a time of the month where she is EXTREMELY gross for 3-5 days. Yeah, I know that's kind of sick to think about, but these things make you realize that they are more human and not something to be put up on a pedastool. If you can convince yourself that this person is in most aspects the same or very similar to yourself, you can begin to relax.
Secondly, you got to have a REALIZATION about this girl. The realization is that this girl (and all girls/people) has the exact same fears and insecurities you do. Just because she's pretty doesn't mean that she doesn't think she is ugly or is insecure about the way she looks. 99.9% of ALL the girls you meet have this insecurity. I mean, you can be talking to complete BABE and she probably STILL thinks she is ugly. Girls can be extremely insecure...it's natural. How this helps you is to realize that you not only have the same "grossities" as she does, but you share the same insecurities. The same feelings and worries you have about her, she is doubt feeling them about you (at least a little bit), the difference is that she has probably learned to hide it better and APPEAR confident. And in this game, appearances are half the battle.
The last big thing is REVELATION. Revealing yourself to her (and other people) in such a way as to not convey your insecurities. It's all a mind game. If you get inside your own head and begin to talk yourself up to yourself and use things to motivate yourself, you can reveal yourself as a confident and secure person. If you give off the insecurities you are feeling by clamming up and getting nervous, she'll sense that and it'll make her uncomfortable and awkward, which in turn you will see that awkwardness in her. When that happens, because of your insecurities, you will assume that she is awkward because of YOU personally...because you think you are a loser or something. When in reality, she's only being awkward with you because she can sense your insecurity.
I said all that to say this: YOU CONTROL HOW YOU REACT TO OTHER PEOPLE. It IS in your power, believe it or not. And the major cure for this is psyching yourself up (trust me it's difficult to do at first) until after a while you begin to get comfortable with yourself and you don't have to psych yourself up anymore.
What are some ways to psych yourself up?
Here's some things I did:
1. From now on, ANYTIME you walk past a person, MAKE EYE CONTACT WITH THEM. This is a key battle in the confidence game. Making eye contact is your first step into a brave new world because this is the point that makes you insecure. EVERYBODY you meet or run into, look them square in the eye and hold their gaze, at least for a few seconds until you begin to get more comfortable with it (which DOES take time).
2. When you've gotten yourself trained to make eye contact with the people you meet, it's time to take the next step: GREETING them. You don't have to be all intense about it or say much. Just get used to making eye contact with people and THEN saying "Hi" or "How you doing?". YOu don't have to strike up a conversation with them just yet, just take baby steps at initiating eye contact and then greeting them. I promise you that this is a MAJOR chunk of the battle.
3. After this, then, you're ready for the next big hurdle: INITIATING A CONVERSATION. Contrary to popular opinion, initiating a conversation isn't extremely hard to do. When your mind goes blank, stop yourself right there, take a DEEP BREATH, and calm yourself down. Yeah, it may seem sort of weird to the other person at first, but at this point you are just using that other person to build confidence in yourself.
Conversation is a game as well. In fact, it's very much like a game of tennis. Imagine if you will, that you are playing tennis with your friend. Now imagine that your friend has a case of three tennis balls and you guys are out on the court. Casually, he lobs up the ball and serves it to you. Now, imagine if you just stood there and watched it go by and then just sort of giggled nervously. Ok, so your friend would get out another ball and lob it across the net. Imagine again that you just let it go by, until finally after 3 balls, your friend no long has any balls. They are all on your side of the court.
Conversation is just like that. EXACTLY like that. Imagine is someone comes up to you and says something to you and you just grunt out the bare minimum of "um hmmm" or "fine". You are essentially letting that ball fly past you and eventually, after so many tries your friend will be out of "balls" or intros to conversation. The key is to see the ball coming and be prepared to return it and volley it back and forth. I mean, EVENTUALLY the ball will get by one of you, but then you have a couple of other balls (or topics) in reserve that can fill out a nice conversation before you guys run dry.
Essentially, then it's like playing tennis. Here, let me give you an example of "holding the ball" and letting a conversation die:
Do you see how "You" held the ball there? Now, let me give you an example of how to "return her serve":
Do you see how much smoother and easier that played out? You led the conversation and captivated her interest. And you didn't have to say anything monumental. You just had to say the first thing that popped into your head (that is appropriate for the level of friendship of course).
It's all one giant mind game. You've got to get inside your head and "preach" to yourself and psych yourself up. Learn little key things like making eye contact and greeting people and when the time is right you can begin to initiate a conversation and begin to climb out of that shell.
In any case, I wish you luck dude. I know what it's like and I am here today to tell you that I am a living example that you CAN regain your self-esteem and confidence and you CAN beat this. Good luck man.