Dumbass who learned to program in the last 10 years here and has managed to never touch PHP. Normally I think of a a hard distinction between a “programming language” (Python, JS etc) and a “markup language” (HTML) and this distinction is clear in most web stacks. But then one day I installed DokuWiki and it was a big bundle of PHP files. The way you install it is you just unpack it to the public www folder and run it with Apache. I guess you could use Nginx or another web server instead.
I’m confused because I don’t get who is running the PHP code here when someone visits the wiki. PHP is like, it’s own thing with a website where you can download it, but I never actually did this in the process of installing DokuWiki. Is Apache/Nginx just vendoring PHP? Or do they have their own implementation?
It looks to me (a dumbass) like the majority of the work of running a DokuWiki instance is just executing the PHP code… So what is really being added by Apache in this scenario? Why doesn’t PHP just vendor a little script that answers HTTP requests so we can cut out the middle map (Apache)?
Because PHP is just the programming language and its interpreter. It takes input data, does some processing and prints out the results. You still need a web server to talk to visitors and pass data back and forth: requests from the browser to PHP, generated web pages back to the browser. In fact you’ve probably noticed that a PHP script goes where a web page normally would, and is accessed the same way. It’s just that you can get different results every time.
But that’s not possible without the web server! Its part of the job is pretty important. It can talk to a lot of browsers very fast, and do it securely, for example by not letting bots access files they shouldn’t. Otherwise it would be simple enough. Indeed, PHP has a web server built in that can be used for development on your local machine (it’s what I use) but it’s not performant or secure enough to run on a production server.
In my setup the browser speaks https to nginx and nginx speaks fastcgi to php-fpm. It is also acting as a reverse proxy in front of some node.js and ruby applications running on the same system.
A different system might have mod_php running in Apache.
So does apache vendor php (like Inkscape vendors python) or is it installed as a dependency (like, idk, most other python programs) when you apt install it?
Apache can work with either mod_php or php-fpm. I don’t know what distro you have or how you installed Apache, but I can say php-fpm is the default in Fedora.
php-fpm is a separate package and runs as a separate service so in that configuration it isn’t vendored.
One fun thing is that you can do the same thing with server-side JavaScript these days! (Express.js, Node.js itself, etc) So no need to learn an extra language.
It has to be “apt installed”. If you don’t have a PHP handler installed on your server (or if it’s not configured properly), PHP doesn’t get served correctly. (I think the default behavior when this is the case is to attempt to download the PHP file, or at least that’s what I’ve seen.)