i have seen this one on trending php projects on github quite often.
as a side note, the php community is quite good at coming up with cms projects. i wonder what makes the language so nice for writing content management systems in? might be interesting to learn about.
> i wonder what makes the language so nice for writing content management systems in? might be interesting to learn about.
The fact that you just need to drop a file on an Apache server to have a functional web app. It's not so much the language itself but the execution model of the code. No need to stop/start a server when the code changes, no need to actual write a server since Apache fronts everything.
so it has nothing to do with the language, it's about the CGI style model and its simplicity.
PHP as a language was, to a certain extent, made for the web. The language included things like MySQL access. That meant that projects didn't need a lot of dependencies. PEAR existed for libraries, but it's not like Java or Python where things like cookie handling or MySQL access isn't baked into the language. This also meant that a lot of the things you'd do on the web were basically written in C and fast.
This made mod_php very useful. You could write a login.php file that would do a mysql_query and return a redirect and maybe a couple hundred lines of code would need to be interpreted. Everything dealing with the web or database was built-in to the language. If you're using Python, you're loading libraries. Because different users might want to use a different library (or a different version), you couldn't easily build something that would offer the same capability there (where the web server had already loaded most of the things you want to do and shared that with everyone on your box). PHP basically had a web framework built-in and that meant that it could be loaded and shared. Rather than having to interpret your logic plus the web framework, it would just need to interpret your logic.
Now, there are benefits to a library-based ecosystem. You can update your DB library without updating the language. If most programs in the world aren't going to talk to MySQL, why include MySQL access in the language? But that's what PHP was about.
I do think part of what made the execution model possible was the language itself. It's certainly not impossible in other languages, but PHP was really made for the web and it made the mod_php-style system work well.
With no long-running processes, it was easy to offer cheap shared hosting. The PHP language would be in-memory and then the scripts could be small pieces calling into the language functions. If I'm running a Java app or Python/Gunicorn or whatnot, I'm holding onto memory even when I'm not serving requests. Even today, memory isn't free. If you have a lot of customers getting minimal traffic, you'd like to use your hardware efficiently. If you have a 32GB RAM box, you could slice that up into 1,000 customers holding on to 32MB of RAM. However, if they're each getting a hit per minute, you have a lot of wasted RAM. Imagine personal blogs and home pages and such. Plus, when customers need a burst of resources, they aren't available - everyone has their 32MB of resources whether they're using it or not. With mod_php, customers could be using basically zero resources for the 99% of the time that they're idle. They could burst when needed. Some shared hosts way oversold their capacity, but it enabled cheap hosting.
A lack of long-running processes also meant that a lot of potentially sloppy things never bit you.
PHP had some language features that enabled good performance on a shared system compared to other ecosystems and that made it a great target if you were looking to create such an app. Today, VMs are cheap, but they still require a level of knowledge/work above just sticking files on managed, shared server.
The execution model really drove PHP's adoption, but I think the language design made that possible. If PHP apps needed to load lots of libraries on each run, that execution model wouldn't have worked as well.
That's the reason why PHP became popular and still is but does it make PHP special for CMSes? I believe that the reason is that people started creating CMSes in the mid 90s when the only viable choices were Java, Perl and PHP. There was a wave of big and expensive CMS focused on companies and there were the open source ones we're using still now. Open source went PHP and my guess is that people thinking about CMSes now is heavily influenced by that culture, which is mostly based on PHP.
Well because people who don't know anything about programming just need a cheap hosting with an Apache/PHP/Mysql plan and upload the script via FTP.
That's it. Again it has everything to do with how easy and cheap it is for an hosting company to provide PHP/hosting and how simple it is to deploy a PHP application for someone without a programming background.
it makes hosting cheaper and deployment easier. you don't need to run a separate server program per app. you share your hosting with others. Sure, things like docker have enabled sharing for other languages, but i think there is still more overhead involved, both in terms of system resources and in terms of setup, so other languages can't compete on price. CMS users also (at least in non-enterprise market) don't care about the language things are written in, because they don't use it. but the price of hosting is important to them.
PHP is web-first, built for the web, and it does it's job well for that purpose. In the years before this boom of SaaS web apps and platforms, the only thing you needed on the web, in almost all cases, was some sort of CMS.
PHP was traditionally used for CMS', because that's what was needed (and still is) on the web. It's not a glamorous job, but those CRM, ERP, and other data systems are what power the modern business world. And a large number is written in PHP.
Case in point: Serbia's largest government-owned telco "Telekom Srbija" used to use a CRM system written in ASP.NET with WPF client software. In January 2019. they started to migrate off of that solution onto a web based platform written in PHP. It's still kind-of in progress, but I think it will bring them more success.
SBB, Serbia's largest alternative telco, has been using that same PHP-based solution for years, and has a smooth customer acquisition process, because it can be done from anywhere due to the web UI.
Of course, you can have a Web UI with any other language, but PHP is web native and isn't any worse than other languages, but may provide some advantages.
Also, before nodejs was invented, the only truly accessible (as in - simple to develop in, with a tolerant dev environment) language was PHP, if you wanted to do web and web only. There was (and is) Python, Ruby, Java, etc., but they were never easy to use, manage and deploy. Most of the new tools we take for granted weren't available in, i.e. 2005., when the standard dev procedure was to upload files via FTP for a large amount of the world.
And lastly, nowdays, I don't think PHP is any worse than other scripting languages for web usage, especially for CRUD information system UIs. And if you need more than it offers, you will find luck only in .NET [Core] or Java, not in Node or Python.
Ironically, the company I work for is strictly a no-PHP shop, and does no PHP projects for clients, except half of the Intranet that spans many countries (Serbia, Slovenia, Bosnia, USA, Netherlands, Germany, Phillipines, UAE, etc.) and management systems are written in PHP. It's just useful for the task, and there's no need to change it, or waste money on something that works. The company is old-ish (from 1998.) but hasn't outgrown the systems (yet). I said ironically because I really like PHP, but do .NET with Oracle at work.
There are many languages that are as simple or even simpler than PHP in syntax, and if you're comparing it to JavaScript, nodejs is literally JavaScript.
PHP's biggest strength is ease of deployment and popularity. Deploying a nodejs app is a nightmare, because of the fact that nodejs isn't a web-first language in the traditional sense. It's a general purpose language that can do many things, but that causes problems for, i.e. hosting multiple apps on a single server (without having to coordinate ports between them, firewall them off, and have a single nginx instance proxying to them based on domain names).
PHP is simple to deploy. If you have a shared hosting, just upload files to the FTP server, and open the page in the browser. It works. If you have a root server, just `sudo apt install -y apache2 libapache2-mod-php7.3` and put the files in /var/www/html/
It's a perfect fit for web because that's the only place where it actually works. It does one thing (platform) and it does it well (from the deployment perspective).
It has (had) it's warts in the years, but I don't find many things that it doesn't have compared to other scripting languages.
Think you're underestimating the array functions. They might be ugly (programmers tend to prefer expressive array syntax), but their learning curve is the best of any language. So much of programming for the web is "do something to an array of stuff", and PHP makes that super-easy.
Agreed. Laravel is also fixing many of the complaints people have with PHP [developers], because it tries super hard to make you do things properly, and wherever it is possible, it actively prevents doing things the wrong way.
It's really a breath of fresh air in the way it's laid out (IMO) and the documentation is mostly very good, with some areas (weird edge cases) that are lacking a bit, but it's quite usable.
I'd recommend someone starting PHP to go with Laravel, and learn it's way of doing things. You can't go wrong and you will learn how to do things the right way. That's what I teach people.
> it tries super hard to make you do things properly
I don't have much experience with Laravel, but my sense is that Laravel tries to make hard stuff (CRUD operations, MVC) easy, but it doesn't try so hard to make you do things "properly".
as a side note, the php community is quite good at coming up with cms projects. i wonder what makes the language so nice for writing content management systems in? might be interesting to learn about.