Unlike the connections on your physical network cards, that can be active/inactive, shared, and have to be properly set up, a localhost connection is just a shortcut that points to your own machine. It doesn't "stay active all the time" and you don't have to "connect to it" for longer than the period of time required for the commands to be executed.
When you use your browser to view a remote webpage (let's say Facebook), you don't have to setup a connection to the website on your OS control panel. You just inform the destination on the browser address bar. When you try to connect to localhost, the process is the same. To the client software, it doesn't matter if the server is local or not, if you try yo view a webpage on localhost, your browser will behave the same as if it was an external server, it's just the IP that's different.
The localhost address just points the destination to your own computer. You don't have to configure anything extra in terms of network cards or network sharing. The commands you try to execute will only be executed if you have a server present on your own machine. So, if you want to point your browser to localhost, you need a web server running on your machine. If you want to execute MySQL commands, you need a mysql serveron your machine. If you want to execute PHP code, you need a PHP interpreter installed on your machine. The protocol itself doesn't matter, it will be determined by the port the client tries to connect.
To simplify this process A LOT, I recommend you install a WAMP (or MAMP, or LAMP) package. They install Apache, MySQL and PHP in a single package. On windows, Wampserver is a good one.