Setting up LAMP environment

Hi all,

I’m working on a PHP project and need to setup a PHP+Mysql(Mariadb) environment (don’t care about web server)

I researched and looks like the best way is to use devenv.
I got this devenv.nix file

{ pkgs, config, ... }:

let
  phpPackage = pkgs.php.buildEnv {
    extraConfig = ''
      memory_limit = 256M
    '';
  };
in
{
  languages.php.enable = true;
  languages.php.package = phpPackage;
  languages.php.fpm.pools.web = {
    settings = {
      "pm" = "dynamic";
      "pm.max_children" = 5;
      "pm.start_servers" = 2;
      "pm.min_spare_servers" = 1;
      "pm.max_spare_servers" = 5;
    };
  };

  services.mysql.enable = true;
  services.mysql.package = pkgs.mariadb;
  services.mysql.initialDatabases = [{ name = "app"; }];
  services.mysql.ensureUsers = [
    {
      name = "app";
      password = "app";
      ensurePermissions = { "app.*" = "ALL PRIVILEGES"; };
    }
  ];
  # Project specific MySQL config like require always a primary key
#   services.mysql.settings.mysqld = {
#     "sql_require_primary_key" = "on";
#   };


  services.caddy.enable = true;
  services.caddy.virtualHosts."http://localhost:8000" = {
    extraConfig = ''
      root * public
      php_fastcgi unix/${config.languages.php.fpm.pools.web.socket}
      file_server
    '';
  };
}

But once I do devenv up I end with this message and mysql don’t starts.

Once I close this, I end with this output, that I searched in google without too much success:

giu@nixos:~/dev/lamp/ > devenv up
• Building processes ...
• Using Cachix: devenv
✔ Building processes in 4.5s.
• Starting processes ...
• Building shell ...
✔ Building shell in 2.8s.
✨ devenv 1.0.5 is out of date. Please update to 1.0.7: https://devenv.sh/getting-started/#installation
{"level":"warn","error":"open /home/giu/.config/process-compose/settings.yaml: no such file or directory","tim
e":"2024-06-16T20:26:33+02:00","message":"Error reading settings file /home/giu/.config/process-compose/settin
gs.yaml"}

Is one of the last things I need to fix to stop booting into windows. Some idea?¿

Fatal error: can't open and lock priviliges tables
That does suggest that some permission(s) are missing and / or mysql is not initialized.

Have you ensured that the current linux user has correct permission(s) / access to mysql?

Hi, thanks for answer

Yes, is what I though, but I guess I have to do it from devenv.nix file. I changed app user by my giu user, with same result. Searching out there, should be this way, nothing more to do

How about the initialization part? Which seems to give permissions to some directory for specific user(s)