Disclaimer: This is completely my imagination, and may be far from true.
First there were cgi programs. You had a web server, and you named one directory as 'cgi-bin'. Any programs in this directory were executed, and the results were sent back to the browser.
If a company wanted to have a website, they would speak to their sysadmins, who would just have to create a simple script and put it in the cgi-bin directory. Perl was already available, and it was easy to learn for someone who knew bash or awk. So, they chose Perl.
And that was how Perl first became popular.
If someone has learnt some HTML, and is able to make a website. But now wants to add some features which need a backend. Then, the easiest way to do it, especially if you are already using apache, is to use PHP.
Since there are a lot of such people, PHP became popular.
And since there are a lot more people who come from a HTML background, than from a programming background, PHP is more popular than Perl.
Perl was the king of open source web programming, but now PHP has taken its place.