I've used PHP, and Python, and quite a lot of other languages. They all have their pros and cons, but you can do most things in most languages if you put your mind to it.
The reason certain languages get popular in certain fields seems to be a combination of having the right sort of characteristics and being in the right place at the right time. Once they attain that position in a given niche, infrastructure develops around them. Specialist libraries, books and blog posts help you use that language for that purpose. Eventually employers decide they need developers who know X language for that field, and developers realise they need X language to get a job in that field.
PHP is a fairly unremarkable member of a bunch of C-like languages. It is lightweight, easy to pick up if you know C, interpreted, and had a few features to help with generating web pages. The real clincher is probably that most cheap shared hosting providers started supporting LAMP, so if you don't want to pay for a dedicated host you need to run PHP on the server. If Wordpress had required a Windows server running Java it would have gotten nowhere.
Python is good for quickly creating experimental code. Not so much because you don't need to type in curly brackets, more because it works at a higher level than most other languages (for example, has decent functional programming support) and has tonnes of libraries. It is also syntactically a little similar to the rather expensive Matlab, which all contributes to its popularity in data science and ML.