top | item 40520019

(no title)

jslaby | 1 year ago

Long time C# dev, now I primarily code in PHP8 which is a great language to quickly get things done. This is the kind of direction the language needs to go in, instead of the older LAMP which can require somewhat complex Apache configuration.

discuss

order

hparadiz|1 year ago

PHP dev of 18 years here.

Use nginx with php-fpm. It takes 5 minutes to configure.

Edit: I'm gonna give this thing a try too but I've never had any bottlenecks with either nginx or Apache. They both take a few minutes to get going at most.

anonzzzies|1 year ago

Few seconds with docker. There are fully loaded compose ones that include everything so you don’t need to add anything. It’s lovely. For prod it’s better to only leave the needed extensions etc of course but for dev it’s so easy to get going. And to be honest, for small personal, company internal and less than $1000/mo rev saas, we just use the fully loaded in prod as well.

lordofgibbons|1 year ago

>It takes 5 minutes to configure

Is that because you have 18 years of experience, or would it be as easy for a new developer?

codegeek|1 year ago

It takes 5 minutes to configure with the defaults. But once you need to optimize PHP-FPM to handle more requests, you now find yourself fiddling with pm.max_children etc settings and need to know what you are doing. I love working with PHP and Go both btw. But PHP configurations can be a pain if you do anything other than defaults.

ofrzeta|1 year ago

Apache with mod_php actually takes just "apt install libapache2-mod-php8.2" to work.

francislavoie|1 year ago

Just as a reminder, you can use Caddy + php-fpm as well (with vanilla Caddy, no plugins).

What this does is give you a way to run your webserver + PHP as a single process, or single Docker container (instead of the traditional 2-container approach), and it also unlocks the ability to run PHP in a worker mode, where you have long-running PHP processes that have your framework loaded in memory ready to serve requests, instead of booting the framework on every request (so, much lower request latency).

n3storm|1 year ago

I agree. Having separated php processing and http processing brings good practices and helps further scalation.

El_RIDO|1 year ago

And to add one more option to the comments (beyond [frontend] + php-fpm):

Nginx Unit https://unit.nginx.org/ - like Apache + mod_php runs as a single service, handles the multiprocessing of php (and other languages), static files, reverse proxy and even lets you configure both itself and php via a single configuration (either as a file or dynamically at runtime, via a socket): https://unit.nginx.org/configuration/#php

Here is an IRL config example: https://github.com/PrivateBin/docker-unit-alpine/blob/master...

The resulting container image can be pretty small: https://hub.docker.com/r/privatebin/unit-alpine

lelanthran|1 year ago

>This is the kind of direction the language needs to go in, instead of the older LAMP which can require somewhat complex Apache configuration.

I hardly every set up PHP (once each time I reinstall my desktop, which was last in ... 2018?) but I recall it being very quick and smooth using apt-get.

I don't recall doing anything else other than restarting apache.

KronisLV|1 year ago

> ...instead of the older LAMP which can require somewhat complex Apache configuration.

Is it really that bad? The Apache configuration seems decent with something like PHP-FPM: https://news.ycombinator.com/item?id=40256843

  LoadModule proxy_fcgi_module "/usr/lib/apache2/modules/mod_proxy_fcgi.so"
  <FilesMatch \.(php|phar)$>
    SetHandler "proxy:fcgi://127.0.0.1:9000"
  </FilesMatch>
Here's a more full example of Nginx that's quite conceptually similar to how one would configure Apache, with installing the prerequisite packages: https://news.ycombinator.com/item?id=37443911

There are also prebuilt container images that you can use to achieve similar results, this is just in case you want to do it yourself and have a look at what's under the hood a bit more.

In my eyes, that's certainly easier than configuring the Java app servers of old, like doing manual Tomcat or GlassFish configuration or whatever people spent time on back then. A single run command will usually be better regardless of the environment, but LAMP isn't all that bad either, when compared to the other stacks out there.

augustohp|1 year ago

I agree. If we can start a culture of relying on SQLite instead of PostgreSQL/MySQL, a whole server-side application can be a simple standalone binary.

Also, having a binary makes it easy to bundle in an Electron app.

francislavoie|1 year ago

Laravel is defaulting to SQLite now (mainly for ease of development). Also FrankenPHP has SQLite included by default. Going that route is less scalable though, obviously, unless you use one of those third party SQLite cluster solutions.

pathartl|1 year ago

I cut my teeth as a WordPress dev and left the scene for .NET when it was still popular to use Vagrant to setup your dev environment. While I'm glad things have progressed since then, I have a trauma response to those days. The amount of hours spent getting a proper config with XDebug setup (oh god, what an absolute backwards-ass nightmare) was substantial.