It’s a bit tricky for evaluation error. You can use lib.traceVal and friends from nixpkgs to try and trace the value but usually I revert to carefully reading the code (which is unfair to nix beginners that don’t know how to read nix yet).
Here the issue is that source-code-derivation.nix with return { source-code = «derivation ...rivation»; }. The documentRoot wants a path or null but is getting an attrset. One way to fix this:
Thank you very much! I’m now able to get the PHP files where I want them to be. I think that the next step is figuring out how to manage the database. I found this example project where they do this:
for addition…like in my case i dont use mySql…i use microsoft SQL server on my project so i need to install php with custom extention…here is my config…
let
myPhp = pkgs.php.withExtensions ({ all, ... }: with all; [ sqlsrv pdo_sqlsrv pdo_odbc curl dom filter intl json mbstring tokenizer xmlwriter openssl ctype exif fileinfo gd gettext iconv pdo posix session]);
in {
services.httpd = {
enable = true;
adminAddr = "webmaster@example.org";
enablePHP = true;
phpPackage = myPhp;
};
users.users.fadhli.extraGroups = [ "wwwrun" ];
environment.unixODBCDrivers = with pkgs.unixODBCDrivers; [msodbcsql17];
Build with nix-build server.nix. Note the output store path
Copy to server with nix-copy-closure --to my_server_ip --use-substitutes path_from_step_one
One the server:
a. nix-env --profile /nix/var/nix/profiles/system --set path_from_step_one
b. /nix/var/nix/profiles/system/bin/switch-to-configuration switch
I’m happy with this so far! Thanks for the help. Before I move on (to database migrations and lets encrypt), do you have any feedback to the above setup? Ex: The services.httpd.enablePHP = true; # oof... not a great idea in my opinion - what should I do instead?
One specific question: How can I make environment variables available to my PHP script? I’d like to set fex DBNAME=something and then use getenv('DBNAME') from PHP.
Do you have any suggestions to decrease space usage in the nix store? I’d like this run this old app on a small VPS, and currently the nix store is taking about 4gb of space.
[root@extravmstianlagstad:/]# du /nix/ -sh
4.1G /nix/
That’s after running nix-env -p /nix/var/nix/profiles/system --delete-generations +2 and nix-collect-garbage. Is it realistic/practical to decrease that 4gb?
I would suggest opening a new topic for your space question. I have never tried to reduce disk space usage with NixOS because I only work on boxes where high disk space usage is expected. Sorry I couldn’t be helpful on this topic.
Thanks @tomberek ! I did nix-build server.nix and then nix path-info -Sh ./result to see that the closure size is 1.6G. Not too bad, I think.
The next step for me is to setup Let’s Encrypt. I see that Nginx - NixOS Wiki has an example of the LEMP stack, so I’ll try using nginx instead of apache.
I think the letsencrypt part works, but I’m not able to load my site. When I go to the root domain, I get an nginx 403 error. When I explicitly go to /index.php, then I get a black page.
tail -f /var/log/nginx/access.log reports a 500
I don’t see anything in /var/log/nginx/error.log
I don’t see anything useful in journalctl -u phpfpm-mypool.service.
Any hints as to where I could look for the error log?
Not sure if it’s worth mentioning, but I’m seeing this in /var/log/nginx/error.log:
2021/08/01 12:25:41 [warn] 38659#38659: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
Is there a tutorial somewhere for setting up a PHP app with devenv? I’ve read a bit of devenv’s documentation and the PHP sample above but I’m afraid I need a lot more hand-holding. My main question is: where do I specify the file that is to be used as an entrypoint, e.g., index.php?