Disclaimer: I’m definitely not the biggest fan of PHP. For the same reason why I’m not the biggest fan of Perl. I’ve been using both extensively in the past decade to build websites, but when flexibility becomes sheer lack of structure it becomes easy to build unmaitainable and un-debuggable monsters.
The pervasiveness of web frameworks based on PHP justifies part of its success, but it’s not the only reason. PHP makes it easy to deploy server-side web logic — you drop your PHP script into your web server folder, and you’re good to go. No compilation, deployment or transpiling required. That is, in my opinion, still a big win for an ugly language like PHP, a big plus that is not yet matched by any other language used for server-side web development.
Java is structured and tidy, but it makes web development a cumbersome nightmare of compile-deploy-reload iterations, and it makes even relatively simple web application needlessly verbose. JSP came later to overcome this cumbersomeness, but it almost came in as an afterthought.
Python with Django or (even better) Flask has a lot of potential to replace PHP, but for some reason it hasn’t really won many server-side developers.
In the end, I overall dislike PHP, but I think that the reason why it is still so much around is that other server-side solutions have so far clearly FAILED in making web development an enjoyable experience. That’s why PHP is still the most used language on web servers, and the second spot still belongs to an even uglier and more unmaintainable language like ASP.NET. It’s not because of the merits of these languages, but because of the failures of other languages.