Hacker News new | ask | show | jobs
by hannob 16 days ago
Apache has a feature that no other http server has replicated: .htaccess files.

They provide limited configurability of server functionality within a webroot. That's extremely convenient for PHP webapps. For many PHP apps, deploying them on anything that is not apache means touching the server config itself.

7 comments

I would say that's actually a misfeature as it requires too many additional filesystem lookups to fulfil requests.

Modifying the web server config is a nonissue outside of shared hosting, which should have died out with the advent of VMs/containers.

> I would say that's actually a misfeature as it requires too many additional filesystem lookups to fulfil requests.

Its use is optional: set "AllowOverride None" (the default) and it's disabled.

* https://httpd.apache.org/docs/2.4/mod/core.html#allowoverrid...

But then that removes the "feature Apache has that no other webserver does" and brings back GGP's point about "what does Apache offer over other webservers like nginx"
> But then that removes the "feature Apache has that no other webserver does" […]

Disabling the feature does not remove it.

If I do not turn on my car's windshield wipers, do they get "removed"?

But, if we concede that it's a misfeature (and that it's not valid to criticize the project for having it, as it can be disabled), then what advantage is there in having it?

You can't have it both ways. Either it's a misfeature but it 'doesn't matter' because it can be disabled, or its a legitimate feature in which case you must therefore defend the existence and purpose of the feature.

When you need (or want) it, you turn it on and accept a few more filesystem look ups, in exchange for convenience and not having to edit the main config.

When you don't need it, great, you've got slightly better performance.

> But, if we concede that it's a misfeature […]

Why would this be conceded?

> Either it's a misfeature but it 'doesn't matter' because it can be disabled, or its a legitimate feature in which case you must therefore defend the existence and purpose of the feature.

Just because I don't (currently) use it doesn't preclude someone else from doing so, and if that someone else wants to explain their use-case that's their prerogative.

But you can selectively use the option: allowing the feature where it is useful (user web dirs perhaps, or individual dirs even more selectively) and disabling it elsewhere.
> … too many additional filesystem lookups …

Caching is a thing. Only dump the cache when a changed is noticed.

And now you have 2 problems..
I believe the OS actually caches it, and since you only modify it by interacting with the OS, the cache gets invalidated when needed.
Network filesystems, consequences of mount shadowing, crazy access control extensions, etc.. Trying to recursively monitor directories with a htaccess file in them to know if a URL requested will reach one.. It is a typical layered system problem.
Webserver/filesystem management, cache invalidation, and off-by-one errors.
Your forgot naming things :)
ok, five problems
what about ~/public_html dirs on shared servers? Having the ability to have .htaccess there means users can impose access control without being able to modify the server config (which they shouldn't be able to do!).
Why shared hosting should die? It's still the cheapest way to publish a dynamic website.
Shared hosting was and still is a great idea, IMHO it just should be limited to static files, not running server-side webapps.
Does not Microsoft's IIS also have that with web.config files?
Does IIS run on Linux?
Yes, but then you're dealing with IIS and why would you want that?
When your Wordpress site gets hacked the hackers are going to assume that you are running apache or nginx and put a .htaccess in the site root that messes the site up. When you are running on IIS the hackers can put in as many .htaccess files they feel like, it will not make any difference.

Perfect security.

> Perfect security.

sigh

Indeed, but it's interesting how web serving in general has shifted away from files. In the original era of web servers, the path component of the URL was the filesystem path on the web server; these days, we expect to match it against a table of routes. Even most PHP apps use routing takes. If you want to bring things back to the filesystem you don't just need to bring back .htaccess - you need a whole new framework.
> Apache has a feature that no other http server has replicated: .htaccess files.

That can expose your files for such a trivial reason as different end of line sequence than what it expects. Instead of shutting down the access, it just happily ignores .htaccess and enables DirectoryIndex.

This is the software that's responsible for majority of data leaks in the world.

Stop using it.

Ah yes, htaccess. Another lovely source of security bugs for the past 30 years and may it continue to bear skiddie fruit for another 300.

Its model is fundamentally flawed precisely because it was based on the fundamentally flawed PHP model (website assets and code are stored and hosted from the same webroot). This allowed for shared hosting to exist but containers and reverse proxies are a far better way of organising such sites today.

The fact that in other webservers the server's configuration is configured through its configuration file and not the content of its webroot is a feature.

Yes apache has a config file too amazingly enough, .htaccess is optional
The point I was making is that having alternative sources of configuration (coming from the contents being served no less) is a misfeature.

Really not sure how one could possibly read my comment as me saying htaccess is the only way of configuring Apache?

PHP can go to hell. My hair is gray because of it. Nginx is superior, and I can get anything imaginable done with config files. And not to mention, it's much faster.
The http servers drag race finished 15 years ago on a tie, it's really much a matter of taste and familiarity more than performance at this point.
The lazy bastard in me prefers Caddy.
I don't understand this. NGINX can run PHP. PHP is not exclusive to Apache.
In general, the Apache php mod has had less drama than php-fpm over the years. Also, casting each domain under specific isolated itk server user(s) account(s) adds a layer of containment, where Nginx processes must run under a single user context.

Nginx uses way less memory in most use-cases (1/4 to 1/10), but with dynamic content like php it is only slightly better (maybe 15% if lucky). Also, setting up websocket proxy in Nginx is still a bit of a bodge.

Each server type has its own trade offs, and a list of known mitigations the uninitiated must learn. If you have a single domain high-traffic site with static media files, than Nginx is probably going to matter more. =3

There is a way nginx/fpm to host multiple domain where each domain has its own user and group and they maintain 0750 permissions so they can't see eachother but nginx and php can both access them:

- php-fpm is easy, you can make the pool run as the domain's user/group directly

- nginx: you must add nginx's user (www-data) to the domain personal's group

The downside to this approach is that it's harder to reason about for someone unfamiliar with it and it's easy to misconfigure file permissions. There is also a limited number of extra groups a user can be part of before it becomes an issue (plus one fpm pool per user takes memory).

That being said the best massively-shared hosting system I've ever used was apache mpm_prefork with mod_php and mod_ruid2. It used as much(little) memory as a single user setup, it scaled to 10k users if you wanted, and file permissions were all naturally handled.

The way mod_ruid2 worked was to use linux capabilities to change the effective user/group of the apache process before serving the request, so it would run as the tenant's group and user, then switch back to nobody/nobody. It had very little overhead compared to things like mod_suphp and, more importantly, it also worked on static files and .htaccess!

The module has been abandoned and was never that popular so I always wondered if it was found to be exploitable or something... Thanks to Linux Capabilities an exploiter couldn't gain root, but as seen from the recent exploit apache's mod_php doesn't do a full cleanup so maybe there was leakage when the process was reused (but then that is solvable by limiting the requested to 1)

Eh. You can use .htaccess in nginx too. I use that everyday.