Pros:
-----
Simpler API: PHP's API is much more intuitive than java. Takes less time to get productive with PHP than with Java
PHP was not a resource hog: This is more relevant to the situation 9-10 years ago, than it is today. But the damage was already done. PHP did not need as much memory or as much processor power as a java web app running in a JVM. So PHP was more suitable to commodity hardware in those days. 9 to 10 years ago, I was told about
JSP developer experiences, where people would write JSP and then go have a cup of tea for half an hour while the compiler compiled and server deployed it. Then even the simplest JSP requests would take another 30 seconds to couple of minutes. JVMs became much more performant only later on. Performance is much better nowadays of course, but even now, a request to a java web app requires more memory than one to a PHP app.
Less typing. Faster to write code: PHP was a procedural language that later got OOP extensions. So global functions are still common in PHP. Makes for less typing.
The untyped nature of language too makes for less typing.
PHP is not strongly typed while java is. This is both a boon and a bane. It's a boon because you have to do less typing.
But it's a bane - specially in large projects - because one developer will have no idea what data is being passed by another component unless it's documented well.
This is not so much of a problem when single developer is developing and uses some common sense coding conventions.
Had open source server support much earlier than java (I believe this was one of the main reasons for its popularity): Apache - 1995 I think. Apache
Tomcat - 1999.
Arrived much earlier on the scene than JSP (I believe this was one of the main reasons for its popularity): PHP - 1995; JSP - 1999
Easier for web designers to pick up: PHP is easier for web designers to pick up, I believe this is another main reason it got traction
No installation complications: PHP interpreter usually comes bundled with Apache in most installation packages. Java on the other hand requires JRE to be installed.
Development cycles take less time: Changes can be made to a PHP file and these changes can be seen immediately on a refresh. This is due to PHP's shared-nothing architecture. PHP has no concept of shared memory, unlike java's static data and session data which remain in memory between requests. Once a PHP request is finished, all data created on the heap is deallocated. PHP session data is saved on file by default, but can be saved to DB.
In java web development, on the other hand, the only way to make a JSP change or java
servlet change active is to rebuild the war and redeploy the web application, thus making it much less nimble than PHP. Of course, some commercial tools like JRebel make this easier, but it's still not as nimble as PHP.
More hosting options: I agree with Stephen's point. It's much easier and cheaper to host PHP websites than it is to host Java websites.
Cons:
------
Not good support for DB transactions: DB transactions are by nature complex. Java has extremely good standardised APIs for transactions (
JDBC) and for distributed transactions(JTA).
PHP on the other hand had no such support. Even now, some DB agnostic APIs are available - like PDO - but I don't think transaction support is any better.
No multithreading: PHP has no native threading API. The runtime is also said to be not threadsafe (there's lots of heated debate about this depending on whether the poster is a PHP fanboy or not). I have not done any detailed analysis, so my knowledge is borrowed. But what I understand is some PHP extensions (these are the adapter plugins that add functionality to the PHP interpreter) are
thread unsafe, and since nobody seems to know exactly which ones aren't, it's risky to use threading.
No asynchronous processing support: Because there's no multithreading support in PHP. This is a strong point of java, making java a good candidate to deploy in the services (business logic) layer when some heavy backend processing is involved. It's possible to deploy webdesigner friendly PHP in the web tier and deploy scalable java (or other JVM language) in the business logic tier - and then integrate them through web services.
Linkedin uses java extensively. Twitter uses Scala (a JVM language) for its backend. Any
site based on Liferay CMS or Alfresco CMS (they're called "portal"s in java world but are comparable to the CMSes of PHP world, like wordpress and joomla) is running on a java stack.