Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My web server uses PHP as do 76.9% of web servers according to W3Techs:

The reason I use PHP is an inertia born out of seeing everyone else using it on web servers. What is it about PHP that would make it so ubiquitous on web servers?

(Note that this question is similar to the following question but takes it in a different direction: Why isn't Java used for modern web application development?)

share|improve this question

closed as primarily opinion-based by Scant Roger, GlenH7, Snowman, MichaelT, Ixrec Dec 13 '15 at 16:28

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

I always assumed because it is easy to install on Apache and nearly all web servers are Apache. – maple_shaft Sep 26 '11 at 18:03
PHP is the language that proves that while nearly everybody can program, nearly all of them shouldn't. It's the Visual Basic of the web generation. – Paul Tomblin Sep 27 '11 at 13:56
I want to argue another point - PHP has good abstractions for websites - it's cache friendly, it has an immutable request/response cycle, it doesn't make you deal with resource management, it doesn't make you deal with data structures, its dynamic nature works well with databases and it has a ton of built in functions so packages are more rare and deployment is easy. I don't like PHP, but it's very easy to make a case for it - I'm not convinced but it's easy to make. – Benjamin Gruenbaum Dec 10 '15 at 11:53
up vote 42 down vote accepted

PHP is a language that is specifically designed for web programming with built-in integration with the most popular open source database MySQL.

  • Easy to start with: As a beginner it is easy to start with PHP. The user just have to add a few PHP-tags with e.g. a for-loop in it's existing HTML-files and then upload it to the server and see the result or an error message. Dynamic typing and associative arrays makes it also easier to start using PHP.

  • Easy to use: Compared to most solutions like e.g. Java, PHP doesn't need to be compiled, so it's just to write the script and then upload it to the server and then update the browser.

  • Integrated database support: PHP has (mostly) built-in support for the most popular databases like e.g. MySQL, that means it is easy to start using databases, no additional drivers needs to be installed, just to use the mysql-functions. The easy to use web based admin tool PHPMyAdmin (released 1998) is also important to the PHP's success in combination with MySQL.

  • Old language (since 1995) with a big user base: PHP became popular early (1995) since it was designed for web programming. Since then the user base has grown and now there is many web-oriented frameworks and libraries available. Some examples are blogg-systems and e-shopping-platforms.

  • Cheap hosting: Since PHP has existed for long time and works good on both Linux and Windows, and many webservers have support for it. There is no problem to find hosting with PHP pre-installed.

share|improve this answer
mark this as answer, you don't need to go further :P . Nice answer @Jonas – Pankaj Upadhyay Sep 26 '11 at 18:34
Most points here are also true for classic ASP. Oh, and also plain JSP. – Adrian Sep 26 '11 at 20:00
@Adrian: 1) PHP was released before both JSP and ASP. 2) It's easier to use MySQL with PHP since you don't have to handle ODBC or JDBC and drivers 3) ASP wasn't easy and widespread on Linux (cheap hosting) at the time. 4) Java with it's static typing is a bit harder to start with for a beginner. – Jonas Sep 26 '11 at 20:15
@Jonas, you are mostly reinforcing my point: 1) it was the only decent web language, so right place, right time. 3) LAMP, that's what my post is about. Also, take it easy, I'm not saying PHP is bad I'm just saying why it got popular: it filled a void, that's it. – Adrian Sep 26 '11 at 20:20
"Easy to start with" is, I think, what launched it. Perl existed, and could do everything PHP could do. But PHP was just that much easier for a complete novice to get started with. And I suspect the community was friendlier to novices as well. PHP filled the void that VB did for Windows programming - easy enough that people could get started on their own and actually create something. – GrandmasterB Sep 26 '11 at 20:48

For the same reason MySQL is so popular: it was at the right place in the right time.

With the Linux server boom in the 90's, the LAMP platform (Linux-Apache-MySQL-PHP) came to scene as a reliable and, most importantly, free option.

As a side note, take MySQL at the time. These were two missing features from MySQL (from the top of my mind, there might be more) not so long ago:

  • No triggers
  • Not fully ACID compliant

How did a DB that wasn't even ACID (atomicity-consistency-isolation-durability) compliant get to be so popular? Same answer as PHP: it was at the right place in the right time.

Further reading about the "right place right time" on LAMP components:

share|improve this answer
If "it was at the right place in the right time" is the answer, then Perl and CGI with C should have seen the same popularity. – Jonas Sep 26 '11 at 20:12
"How did a DB that wasn't even ACID compliant get to be so popular?" - thats easy... its just wasnt that important to most people. MySQL was reliable enough for most web uses. Reliable enough early on for a bank? Probably not. For a web forum? Yes. – GrandmasterB Sep 26 '11 at 20:45
I had a colleague the would scream "but MySQL is hardly a RDBMS!". I find that amusing. Popularity is a funny thing. We - software developers - must not be slaves of trend, we have to keep on learning to keep on working. Anyone who defends a tech too much is less likely to let go. And that's always professionally dangerous. This topic is over for me. :) – Adrian Sep 26 '11 at 20:48

If you look around, most folks running PHP these days are running Wordpress, Drupal, Joomla and the like. Or one of 10,000 free, popular apps that pretty much work out of the box with a cheap PHP host and a little configuration. Many times it gets installed not because anyone is making something that runs on PHP so much as the easiest option is to use something built on PHP.

share|improve this answer

I'm teaching myself PHP right now, so maybe I can answer.

A PHP source code file can contain a mix of HTML, JavaScript and PHP, so it seems really easy to get simple web applications up and running. More complex interactions, that would require lots of Java in a JSP situation, or some weird contortions in a CGI-BIN situation, get catered to by the PHP builtins: you don't even have to know if an HTTP GET or POST called your code, everything your code wants to know lives in _REQUEST or _SERVER or _COOKIE global variables.

PHP-the-langauage gets parsed and executed pretty rapidly so you won't notice a huge performance drop when generating HTML, rather than just having a bunch of static HTML files.

PHP-the-interpreter has library calls for just about every open source DBMS, and a lot of the proprietary ones, too, so making a 3-tier-style web app looks easy. PHP-the-interpreter includes library calls for a lot of other commons situations (a.k.a. "use cases"), so you don't have to write a lot of code yourself, just call the library. So, just like J2EE "enterprise apps", the problem moves from knowing how to code to knowing how to look library stuff up. This is aided by the very decent PHP manual.

As a programming language, PHP doesn't have a lot of exotic constructs, or differ too much from, say C, FORTRAN 4 or Pascal, so programmers that already know one language can easily pick up PHP-the-programming language.

share|improve this answer

There are two key points for PHP's success: The timing and the focus on shared hosting.

In the beginning the Web was static. Web-Servers could only distribute pre-generated HTML this obviously wasn't enough after some time so in 1993 the NCSA team extended their web server (the predecessor of Apache httpd) with a technology called CGI which allowed calling specific programs from the web server which could generated HTML (or other content) on the fly. This was great as people could do all the things. A commonly used language at that time for that purpose was Perl. Perl is a language strong in text processing which is a key property for handling HTTP request data and producing HTML. So people used it.

But there was a problem: For each and every request the web server had to run an external program, Perl had to initialize and run the script. This caused quite some headache. A solution was mod_perl coming ca. 1997. mod_perl is a module for the Apache webserver embedding the Perl interpreter directly into the web server process so no extra startup was need.

But again this approach had a problem: mod_perl was extremely powerful and had access to the complete server configuration. You couldn't use one server to host multiple independent clients as they could easily harm the other people - be it on purpose or by accident. And that's where PHP came.

PHP was built in a way that it could run as Apache module (thus not having the startup hit for each request) but provides a shared-nothing environment between requests. Once a request was done all information was lost and a subsequent request to another virtual host would be served independently. PHP also offered features to restrict access (safe_mode, open_base_dir). With that architectural choice companies could install PHP on their server and provide customers FTP (or similar) access to upload their files and by that host many many customers on a single machine without much work. This caused a competition leading to cheap prices for PHP-based hosting making PHP an ubiquitous platform.

Additionally PHP had a few benefits over Perl, like allowing to mix HTML and PHP code or direct access to request variables (see also register_globals) which in Perl was harder (custom parsing or dependency on which developers liked.

Another aspect which made PHP successful in those days was good support on Windows. Getting Perl or other languages working on Windows was hard, but back at that time many developers where using Windows at home and virtualization or containers weren't a thing, yet. PHP did run easily on Windows so people could use it for development and then pack up the files and deploy on Linux. With Perl for instance you would have to get the correct perl distribution and then check which modules are available at all etc.

What about other languages? Compiled languages like C or C++ never got traction since scripting serves the rapid developing market better. Java existed, but Java Virtual machines required way more resources and shared hosting in the way PHP supports it was hardly doable. Investment in harddware was way higher. ASP (as predecessor of ASP.Net) was bound to the Windows platform, limiting it to organizations which already run Windows and who don't fear the licensing costs, and again no shared hosting support.

Different other technologies where produced but either were commercial (Cold Fusion or Netscape Server with server-side JavaScript) limiting their reach or didn't et out of their reach till Ruby-on-rails came, which probably was the first environment receiving lots of attention, but by that time PHP was already very popular with a large community and well-established software (like Wordpress or Drupal) making it hard to compete - especially as development of PHP never stopped and is still going on.

share|improve this answer

Lets face it, PHP is cheap, easy to learn, has a large community, you can host it anywhere, and it's been around a lot. So, if you think as someone using the internet as a way to make money fast in a small/medium industry and having to create a development area to do so with a practically nonexistent infrastructure, PHP sounds pretty great (to start with).

So I think PHP is a great way to make some money fast with a bunch of programmers and a small computer as a server.

share|improve this answer

protected by MichaelT Dec 10 '15 at 15:01

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.