Do a quick Google search for an iptables tutorial. On a Fedora system, your firewall rules are kept in /etc/system/iptables. You might want rules that look similar to:
-A INPUT -i eth0 -p 22 -j ACCEPT
-A INPUT -i eth0 -p 80 -j ACCEPT
-A INPUT -i eth0 -p 5432 -j ACCEPT
-A INPUT -i eth0 -p 27017 -s x.x.x.0/24 -j ACCEPT
Although, I would not recommend opening ports 22 and 5432 to the world. The SSH connections should be locked down to as few sources as possible, and even then you might want to consider additional restrictions. The database connections should be restricted to the web server and those machines that you use to manage the database.