How to write to Apache DocumentRoot?

I’m attempting to create a new CalDAV backend for SabreDAV (github) using Nix. You can see what I’ve go so far here. Here’s my configuration to create the site using Apache.

I believe the problem I’m encountering is generic and not necessarily related to my particular project but the problem is that the web app needs to write to the file system but cannot. It cannot write to the Nix store, of course, so I attempted to give the app a path to a sub-directory of my home directory but it seems that Apache cannot write outside of its DocumentRoot. What is the Nix solution to this problem? Thanks!

The httpd service is running as the wwwrun user and you’re telling it to write into a directory owned by another user (like tmciver). You could grant the httpd service access to a directory outside of your home that wwwrun uses, or if this is a dev box without outside (incoming) access you could run the httpd server as your own user by setting services.httpd.user = "tmciver"; and services.httpd.group = "tmciver";.

While the two solutions above hopefully answer your question rather directly I’ll point out that there are much better approaches out there for what you are looking to do. Actually just earlier today @domenkozar posted on another thread about an awesome development environment for php developers. I would strongly encourage you to abandon your current approach and take advantage of https://devenv.sh/. From this point on I will be suggesting all php developers I know to use this. I say this as someone who has done extensive devops work for a php shop.

Some big advantages to using https://devenv.sh/ in your position:

  • abandons httpd in favour of caddy, which is much better suited for a local environment
  • abandons mod_php in favour of php-fpm, which is much better suited in any non legacy environment
  • batteries included approach covers pretty much everything you will need when developing with php

Really - consider it :+1:

2 Likes

Thanks so much @aanderse! I saw your postings on other related questions and was hoping you’d answer! :slight_smile:

I most certainly will take the devenv.sh approach. I’m not far into this project so it shouldn’t be a big deal. It’s been a very long time since I’ve done PHP dev work so I don’t have a strong dev preference here.

Thanks again!

1 Like