Listen to what your playing, enjoy what your playing, and finally structure and weed out the pieces you dont want in the song. Hope that helps.
Peace be thy journey
There's no set way to do these. Some people start with melody, others start with a riff, others start with a drum beat. But, generally, I get an idea of what I want guitar-wise in my head, and go from there and write it, editing and re-editing the song 'till I'm happy with it. Now, sometimes, I'll feel the urge to write, and have no ideas, so I'll write some catchy drum beat, and that inspires the rest.

In a nutshell, it all depends on you. You may come up with a melody first, and build around it; I build a melody into my music
Or even a phrase can turn into a whole song,
Write a ****ty song then make it better bit by bit until it's good
Lots and lots of trail and error, the best thing you can do when you're writing a song is to put the bits you have already down on tape. That way you can listen to it without playing it, so you can really focus on structure/flow of the song. Then if you feel that it just doesnt fit, just take it out This techinique has helped me alot.
I am almost always working in a DAW while I'm on my computer. If I come up with a good bassline or drum pattern, I start developing it, and then parts and riffs slowly follow, which I try to arrange into a song. Sometimes it works, sometimes I end up with too much material, but I find that writing and being able to put it together piece by piece as opposed to figuring the whole song out ahead of time really helps me.
When the inspiration comes, I usually start with some kinda of chord structure. Then, I'll add a melody with the chords, and then a percussive beat with that. (I play acoustic finger style slap type music)

Then, when I'm onto something, I set up my webcam so I don't forget it. Trial and error. Then BOOM, you got music babeh!
Quote by sashki
A lot of pros do that: if they play a wrong note, they'll hit it again to make it look as if it's intentional. It's called "jazz", aparently.
write down the lyrics.
figure out some chords that sound good together.
figure out a riff/pattern for those chords
figure out a way to put lyrics with chords
add extra crap.
bam. you have a song.
now refine it till it actually sounds good.

There are many books written on this subject and if you feel at a complete loss, then you may want to check them out and see what the "pros" have to say.