Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide on running these versions with apache (mod php) #325

Open
aszenz opened this issue Feb 8, 2024 · 21 comments
Open

Guide on running these versions with apache (mod php) #325

aszenz opened this issue Feb 8, 2024 · 21 comments

Comments

@aszenz
Copy link

aszenz commented Feb 8, 2024

Any idea on how we could use these old php version (5.5) on apache

@drupol
Copy link
Collaborator

drupol commented Feb 8, 2024

Hi !

AFAIK, we don't maintain 5.5, we start at 5.6.

@aszenz
Copy link
Author

aszenz commented Feb 8, 2024

Hi !

AFAIK, we don't maintain 5.5, we start at 5.6.

Ok, 5.6 is also fine for us.

@drupol
Copy link
Collaborator

drupol commented Feb 8, 2024

First you need to add the overlay of this flake in your own configuration.

In the whole process, this is probably the most complex part. An overlay is just the default standard mechanism to extends pkgs in Nix by adding a layer on top of your configuration so that when you do pkgs.php56, it works.

Then, once it's done, a quick search on Google led me to https://nixos.wiki/wiki/PHP, where I can see a snippet related to Apache.

You would just need to replace pkgs.php with pkgs.php56 and it should be good to go.

@aszenz
Copy link
Author

aszenz commented Feb 8, 2024

First you need to add the overlay of this flake in your own configuration.

In the whole process, this is probably the most complex part. An overlay is just the default standard mechanism to extends pkgs in Nix by adding a layer on top of your configuration so that when you do pkgs.php56, it works.

Then, once it's done, a quick search on Google led me to https://nixos.wiki/wiki/PHP, where I can see a snippet related to Apache.

You would just need to replace pkgs.php with pkgs.php56 and it should be good to go.

Could I point an ubuntu installed apache server to use this nix php binary (maybe by just hardcoding the path in nix store)

@drupol
Copy link
Collaborator

drupol commented Feb 8, 2024

Technically it should work, but using raw /nix/store/... paths is a bad practice since it can be garbage collected.
I would simply recommend you to add it to your profile using nix profile so now your can be sure that it will never be GC'd.

❯ nix profile install github:fossar/nix-phps#php56
❯ php -v
PHP 5.6.40 (cli) (built: Jan  9 2019 10:25:59) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
   with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
❯ type php
php is /home/pol/.nix-profile/bin/php
❯          

@aszenz
Copy link
Author

aszenz commented Feb 8, 2024

Technically it should work, but using raw /nix/store/... paths is a bad practice since it can be garbage collected. I would simply recommend you to add it to your profile using nix profile so now your can be sure that it will never be GC'd.

❯ nix profile install github:fossar/nix-phps#php56
❯ php -v
PHP 5.6.40 (cli) (built: Jan  9 2019 10:25:59) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
   with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
❯ type php
php is /home/pol/.nix-profile/bin/php
❯          

Perfect, so apache would just call nix php automatically since it's on the path

@drupol
Copy link
Collaborator

drupol commented Feb 8, 2024

If there are no other php on your system and if the user running apache is the same user who run nix profile, yes.

@aszenz
Copy link
Author

aszenz commented Feb 8, 2024

If there are no other php on your system and if the user running apache is the same user who run nix profile, yes.

Seems like mod-php embeds php within apache, and doesn't call cli process at all, so this idea wouldn't work

@jtojnar
Copy link
Member

jtojnar commented Feb 8, 2024

In theory, it should be possible but unless Apache has stable ABI for modules, you would probably also need to ensure that the PHP is linked against the same version of Apache as the one you are running (and possibly other parameters).

I think at that point it would be easier to replace the Ubuntu’s Apache with a one from Nixpkgs.

@aszenz
Copy link
Author

aszenz commented Feb 8, 2024

In theory, it should be possible but unless Apache has stable ABI for modules, you would probably also need to ensure that the PHP is linked against the same version of Apache as the one you are running (and possibly other parameters).

I think at that point it would be easier to replace the Ubuntu’s Apache with a one from Nixpkgs.

Yes but does nixpkgs apache have older versions of mod-php?

@jtojnar
Copy link
Member

jtojnar commented Feb 8, 2024

No. But that is what this repo is for.

@aszenz
Copy link
Author

aszenz commented Feb 8, 2024

No. But that is what this repo is for.

Ok, so older modphp versions can be added to this flake?

@jtojnar
Copy link
Member

jtojnar commented Feb 9, 2024

If you want to to run Apache from Nix, you are best off looking at the relevant NixOS module. For example, this is how you get PHP with mod_php:

https://github.com/NixOS/nixpkgs/blob/8a3e1cf40a6eaeb122c8321b97a0518cfa6ed779/nixos/modules/services/web-servers/apache-httpd/default.nix#L21

@aszenz
Copy link
Author

aszenz commented Feb 12, 2024

If you want to to run Apache from Nix, you are best off looking at the relevant NixOS module. For example, this is how you get PHP with mod_php:

https://github.com/NixOS/nixpkgs/blob/8a3e1cf40a6eaeb122c8321b97a0518cfa6ed779/nixos/modules/services/web-servers/apache-httpd/default.nix#L21

Yes, but can i replace the php version in them to older ones like 5.6

@jtojnar
Copy link
Member

jtojnar commented Feb 12, 2024

Sure, just do as mentioned above #325 (comment)

@aszenz
Copy link
Author

aszenz commented Mar 8, 2024

Sure, just do as mentioned above #325 (comment)

I'm yet to try this overlays approach, it would be handier if it was prepackaged in this flake itself, basically I'm imagining this flake to be a simple way to maintain legacy versions of our software, we are also exploring lxd containers in this space.

@jtojnar
Copy link
Member

jtojnar commented Mar 8, 2024

You do not need the overlays approach but it the simplest way to use this flake. Or at least with fewest caveats – you could just use the packages.${system}.php output of the flake directly, but then you would need to make sure the Nixpkgs revision is the same as the one used to built PHP in this flake.

We are not going to include Apache in this flake, that just does not compose.

@aanderse
Copy link
Collaborator

aanderse commented Mar 8, 2024

i don't think what has been discussed in this issue is really the biggest challenge with what @aszenz is attempting to do - generating a configuration file for apache and running the software is going to be the biggest challenge when attempting to run a nix provided apache+php on ubuntu, in my opinion


so how can @aszenz proceed? personally i would suggest using system-manager as it would make running older php versions with apache on ubuntu relatively easy compared to other options

i was able to get the latest version of apache running php version 5.6 on ubuntu in just a few minutes from scratch with the following configuration:

{ nixosModulesPath, config, pkgs, lib, ... }:
{
  imports = [
    "${nixosModulesPath}/services/web-servers/apache-httpd"
    ./compat.nix
  ];

  nixpkgs.hostPlatform = "x86_64-linux";

  services.httpd = {
    enable = true;
    enablePHP = true;
    user = "www-data";
    group = "www-data";
    phpPackage = pkgs.php56;

    virtualHosts."localhost" = {
      documentRoot = "/srv/www";
    };
  };
}

@aszenz if you're interested in exploring this option further i would be happy to provide additional details for you

@aszenz
Copy link
Author

aszenz commented Mar 8, 2024

i don't think what has been discussed in this issue is really the biggest challenge with what @aszenz is attempting to do - generating a configuration file for apache and running the software is going to be the biggest challenge when attempting to run a nix provided apache+php on ubuntu, in my opinion

so how can @aszenz proceed? personally i would suggest using system-manager as it would make running older php versions with apache on ubuntu relatively easy compared to other options

i was able to get the latest version of apache running php version 5.6 on ubuntu in just a few minutes from scratch with the following configuration:

{ nixosModulesPath, config, pkgs, lib, ... }:
{
  imports = [
    "${nixosModulesPath}/services/web-servers/apache-httpd"
    ./compat.nix
  ];

  nixpkgs.hostPlatform = "x86_64-linux";

  services.httpd = {
    enable = true;
    enablePHP = true;
    user = "www-data";
    group = "www-data";
    phpPackage = pkgs.php56;

    virtualHosts."localhost" = {
      documentRoot = "/srv/www";
    };
  };
}

@aszenz if you're interested in exploring this option further i would be happy to provide additional details for you

Thanks, i tried this on my own nixos system (the server will be ubuntu though) and got this error:

getting status of '/nix/store/jp2kw74bigwv1npgi02n22hqm7dj7r6f-source/compat.nix': No such file or directory

i don't think what has been discussed in this issue is really the biggest challenge with what @aszenz is attempting to do - generating a configuration file for apache and running the software is going to be the biggest challenge when attempting to run a nix provided apache+php on ubuntu, in my opinion

so how can @aszenz proceed? personally i would suggest using system-manager as it would make running older php versions with apache on ubuntu relatively easy compared to other options

i was able to get the latest version of apache running php version 5.6 on ubuntu in just a few minutes from scratch with the following configuration:

{ nixosModulesPath, config, pkgs, lib, ... }:
{
  imports = [
    "${nixosModulesPath}/services/web-servers/apache-httpd"
    ./compat.nix
  ];

  nixpkgs.hostPlatform = "x86_64-linux";

  services.httpd = {
    enable = true;
    enablePHP = true;
    user = "www-data";
    group = "www-data";
    phpPackage = pkgs.php56;

    virtualHosts."localhost" = {
      documentRoot = "/srv/www";
    };
  };
}

@aszenz if you're interested in exploring this option further i would be happy to provide additional details for you

Thanks i created numtide/system-manager#72, initially tested it on NixOS before i can test it on Ubuntu server

@aanderse
Copy link
Collaborator

aanderse commented Mar 8, 2024

as mentioned - if you're interested in exploring this option further i would be happy to provide additional details for you

i did not include all details so please close that ticket against system-manager - there is no problem there, the problem is that you don't have all the source

i pushed the source here so you can take a look and have a fully running example

@aanderse
Copy link
Collaborator

@aszenz i missed the part where you said you were testing on NixOS instead of Ubuntu, sorry.

Did my example help at all? Did you get what you needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants