The standard 8051's digital I/O ports are "quasi-bidirectional" and are not explicitly configured for either input or output. There is no data direction register or tri-state control register as there is on most other microcontrollers.
Each port has an output register and an input register. When you set a bit in the output register to 1, the corresponding pin goes high but is only pulled high weakly (this is called a "weak pullup"). External circuitry (such as a pushbutton connected from the pin to GND/VSS) can then pull that pin low, and the pin state can be read on the input register.
When you set a bit in the output register to 0, the corresponding pin goes low with a strong pull-down, and cannot be used for input. For this reason, pins that are used for output functions are normally arranged to be active low, and loads (e.g. LEDs) are normally connected from VCC to the pin.
Edit: Port 0 (if present) does not have weak pullups.
Edit2: The read-only input register and the write-only output register are actually accessed through the same location in the SFR (special function register) address space. The port registers are directly bit-addressable using the 8051's bit-processing instructions (CLR bit to drive the pin low, SETB bit to set it high so it can be used for input, and MOV C,bit to read the state of the pin).