If you can use HDMI (as mentioned above), then that is the best way.
If you can only use optical; then as Esat mentioned, using optical on a motherboard, you can only get 5.1 from media like DVDs or film/TV files that have Dolby Digital or DTS audio tracks.
If you are wanting 5.1 for gaming, then you'll need a sound card, because the majority of PC games do not support Dolby or DTS. 5.1 audio needs to be encoded on the fly with either Dolby Digital Live or the DTS equivalent, so it can be decoded as 5.1 by the amp/receiver.
The frustrating thing is that motherboards are capable of this on a hardware level. Dolby/DTS 5.1 encoding doesn't work from motherboard optical, because manufacturers disable it. Something to do with not having to pay royalties, or so they can include such features on more expensive boards, as an extra feature to make more expensive boards more appealing compared to budget ones. Hence why Esat says they'd rather waste money including pointless gimmicks instead.
Hi I tried this, I unplugged the optical and plugged in the hdmi into the GPU however I didn’t get any sound. I’m not sure why though.
On the amp I set it to the right hdmi port but I didn’t couldn’t hear anything
Could be HDMI audio driver, or maybe HDMI audio output was not automatically set to default audio output device.