When shared hosting was the norm. mod_php was much faster than CGI and a lot safer to use because usually processes in one virtual host did not affect processes in another unlike with mod_perl and the like.
The strong selling point of PHP for a long time was cheap hosting. Combine that with a fast learning curve and you're set.
Nowadays, it's not so clear cut price wise, but PHP took a strong advance in term of user base - look at the number of libraries, projects, and jobs (!) available in PHP, vs python or ruby.