They both more or less accidentally became popular. None of them were very well designed. They both lacked type safety.
Unlike php though javascript became not only popular but it actually ended up being the only alternative.
Most languages had major design flaws. Rubyists will gladly complain about how OO is bolted on in Python, Python users will gladly talk about how slow Ruby's interpreter was and how god awfully complex the syntax is. Both of them have limitations in their runtimes and are actually catching up to JS in some areas (see Python's adoption of async).
We can talk about how baroque CL is or how much Java sucked in 1995, how massively complex C++ is, etc, etc. Those arguments have been made for decades, though. JS is no worse than most languages in various ways, but people are pissed off because their chosen language isn't as popular.
Maybe that's a cynical point of view, but these criticisms never get past the most superficial concerns, so it's not obvious why people really care so much.
I started with C in my early teens (first book I found, lucky me) and I've gone through the VB, PHP, Java, Python, Ruby, and Javascript phases. Honestly I've seen great engineering in all those languages (maybe not VB) and those projects have all been easy and pleasurable to work with (maybe not Java). I've also seen hideous stuff that's a total sanity destroyer. At least for me the main contributing factor to language dislike is dealing with shitty code. Except Classic ASP... That stuff is poison.
In Ruby code starts executing before everything is initialized making it unpredictable. Also JS is just so much smoother is composable. It's far superior to RUBY IMO
The features which make a language rise rapidly might just be different to the features that make a language "good".
PHP in particular is amazing for getting started at speed. I remember taking a HTML file and popping in a couple of lines of PHP in the middle. I still haven't found anything anywhere near that easy for making a server backed website.
If that's already your web server, anyway.
I agree, it sucks that js the only alternative in some cases. But hey, imagine if Java was the only alternative!