Most of the gateway operators will let you do this using a keyword at the beginning of a text which you pre-register. So texts come into the gateway operators number with your keyword as the first word and they'll call your server (usually over HTTP) with the rest of the message.
If you want to DIY you have two options:-
1. Bolt a GSM modem (some handsets can act as one) onto a server. That can either just trigger something in software or you can bridge it to look like a real SMSc using appropriate software (Kannal is an open-source SMSc project). That gives you your own number for the inbound messages.
2. The expensive and complex route is to get a SIGTRAN link into a MNO's SMSc (what most of the gateway vendors do). Not to even be looked at unless you're doing a ton of traffic.