Facebook's backend is, to my knowledge, largely C++, connected via Thrift. The frontend started out as PHP, eventually got compiled to C++ via HipHop, replaced HipHop with HHVM, and then added support for Hack. My understanding is that they're gradually adding more React to it as well. FB also includes a number of specialized services, eg. Chat & Whatsapp are written in Erlang.
Google as written by Larry Page was done in Java. It was rewritten in Python by Scott Hassan before the company was incorporated. As of 1999, the webserver and crawler were still in Python. It was almost completely rewritten (multiple times) in C++ shortly thereafter for efficiency. Most of the Google Apps (GMail, Docs, Plus, etc.) are written in Java. The webserver for Search shifted over to a combination of Java and two different DSLs in 2010; I worked on the implementation of this. My comment is lightly paraphrased from a remark Larry Page gave when asked why Google doesn't adopt more modern programming frameworks like Rails or Node (it was in 2011, when both of these were still state-of-the-art).