Both Ruby and PHP are open source and therefore it comes as no surprise that both these languages are being taken up far more quickly than established languages like Java.
There are other factors too; One of the main ones is that many new web applications need to reach their market as quickly as possible. Applications developed in compiled languages like Java cannot be rolled out iteratively as compared to those developed using interpreted scripting languages like Ruby or PHP making them far less desirable.
There are also quite a few web development frameworks built on these two languages around now, Rails based on Ruby and Symfony based on PHP are two that I know of. This makes it even faster, and easier, to develop and deploy a new web application.
Find out more about: