The same can be said for Visual Basic and lots of other unsexy languages. Heck, someone out there is still doing COBOL and that's the unsexiest of beasts (that I can think of, ATM).
The trick is this: get familiar with a language now and just hang on tooth and nail. Someone, somewhere will still be using that language when you're close to retirement. And you can either charge them a bundle converting off of it, or an even bigger bundle supporting it.
And if it's the government, well, as long as you don't get too careless with the yachts, vacation homes and shady neighbors in banana republics, you can probably get away with it until you die. Especially if you own a politician or two.
In addition to the oft-cited deployment story, I think another reason for PHP's success is that it's the only major language specifically created as a DSL for rendering web pages. Once you're accustomed to having its baked-in toolset for web-related tasks, having to constantly hunt for the right third-party library in a general-purpose language like Ruby or Python becomes a major drag coefficient, even if those languages are objectively better in all other respects.
What features are built in to PHP that aren't built in to Ruby and Python?
This is actual curiosity, I just can't think of anything that PHP has that Ruby and Python don't. Even more so when it comes to Go. But you didn't mention Go.
It isn't the sexiest language, but a lot of people are making a decent living working with it.