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

php: build embedded, uwsgi: enable php plugin #19139

Merged
merged 2 commits into from Jan 19, 2017
Merged

Conversation

schneefux
Copy link
Contributor

Allows to run uwsgi with the PHP plugin.
The plugin needs embedded PHP, so I added php70-embed. (@globin)

Usage example:

location ~ (index)\.php$ {
  include ${pkgs.nginx}/conf/uwsgi_params;
  uwsgi_modifier1 14;
  uwsgi_pass unix:/run/uwsgi/php.sock;
}
services.uwsgi = {
  enable = true;
  user = "nginx";
  group = "nginx";
  instance = {
    type = "emperor";
    vassals = {
      php = {
        type = "normal";
        socket = "/run/uwsgi/php.sock";
        master = true;

        processes = 16;
        cheaper = 1;
        php-sapi-name = "apache";
        php-allowed-ext = [ ".php" ".inc" ];
        socket-modifier1 = 14;
        php-index = "index.php";

        php-set = "date.timezone=Europe/Berlin";
        env = "NEXTCLOUD_CONFIG_DIR=/var/www/nextcloud/config";

        plugins = [ "php" ];
      };
    };
  };
  plugins = [ "php" ];
Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • OS X
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@mention-bot
Copy link

@schneefux, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @abbradar and @dezgeg to be potential reviewers.

@@ -228,6 +232,7 @@ let
pdo_mysqlSupport = config.php.pdo_mysql or true;
libxml2Support = config.php.libxml2 or true;
apxs2Support = config.php.apxs2 or (!stdenv.isDarwin);
embedSupport = config.php.embed or false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be true as default so there would be no need for another top-level php attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Only one SAPI can be built at a time, either "apxs2" or "embed" in this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could assure with an assert, that either one or the other option is used? You could also add one option which is either set either to apxs2 or embed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that needed? When compiling with both flags, php shows this message:

checking for embedded SAPI library support... configure: error: 
+--------------------------------------------------------------------+
|                        *** ATTENTION ***                           |
|                                                                    |
| You've configured multiple SAPIs to be build. You can build only   |
| one SAPI module plus CGI, CLI and FPM binaries at the same time.   |
+--------------------------------------------------------------------+

I think that's sufficient - maybe it will be possible to build multiple SAPIs in future PHP versions.

--replace '@CONFIGURE_OPTIONS@' "" \
--replace '@PHP_LDFLAGS@' ""
done
fi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ${if (config.php.embed or false) == false then "true" else "false"}; then

can be all done in nix, eg:

${optionalString config.php.embed ''...''}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That gives me attribute php missing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use (config.php.embed or false).

@@ -74,7 +79,7 @@ stdenv.mkDerivation rec {
buildPhase = ''
mkdir -p $pluginDir
python3 uwsgiconfig.py --build nixos
${lib.concatMapStringsSep ";" (x: "${x.interpreter or "python3"} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed}
${lib.concatMapStringsSep ";" (x: "${x.preBuild or ""} ${x.interpreter or "python3"} uwsgiconfig.py --plugin ${x.path} nixos ${x.name}") needed}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a semicolon after preBuild here so that we wouldn't need to add it in every preBuild by hand. You can fallback to true so that if preBuild is not set it evaluates to true;.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, even better -- use a "\n", then you don't need tricks with true,

@schneefux schneefux force-pushed the uwsgi-php branch 7 times, most recently from 82fc009 to 85bf33a Compare October 2, 2016 10:26
@schneefux
Copy link
Contributor Author

@abbradar @ericsagnes I updated the PR with your changes.
Travis fails with configure: error: Cannot find ldap libraries in /usr/lib. I think LDAP_LIBDIR=${openldap.out}/lib needs to be passed in preBuild as seen in php/default.nix, but that doesn't work… php, php-embed and uwsgi build fine for me locally.

@abbradar
Copy link
Member

abbradar commented Oct 2, 2016

@schneefux Enable sandboxing -- this would most likely allow you to reproduce.

@schneefux
Copy link
Contributor Author

@abbradar: My changes are not responsible for the failure, the same error already occurred in #18860. uwsgi php70 php56 php70-embed build fine on Linux and NixOS with sandboxing.

@@ -4,7 +4,8 @@
, pam, withPAM ? false
, systemd, withSystemd ? false
, python2, python3, ncurses
, ruby
, ruby, php-embed
, openldap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openldap is not used.

@Mic92
Copy link
Member

Mic92 commented Oct 22, 2016

can you add your php example to nixos/modules/services/web-servers/uwsgi.nix as well?

@schneefux
Copy link
Contributor Author

can you add your php example

I got the example from the official documentation, I added a link.

@bachp
Copy link
Member

bachp commented Jan 19, 2017

Any chance this gets merged?

@globin globin self-assigned this Jan 19, 2017
@globin globin merged commit 3f3b6e6 into NixOS:master Jan 19, 2017
@Mic92
Copy link
Member

Mic92 commented Jan 20, 2017

@bachp can you provide me a configuration to test uwsgi + php. Just something which shows that plugin gets initialized.

@schneefux
Copy link
Contributor Author

@Mic92

services.nginx = {
  enable = true;
  virtualHosts = {
    "example.com" = {
      root = "/var/www";
      locations."/".extraConfig = ''
        include ${pkgs.nginx}/conf/uwsgi_params;
        uwsgi_modifier1 14;
        uwsgi_pass unix:${config.services.uwsgi.instance.vassals.php.socket};
      '';
    };
  };
};

services.uwsgi = {
  enable = true;
  user = "nginx";
  group = "nginx";
  instance = {
    type = "emperor";
    vassals = {
      php = {
        type = "normal";
        socket = "/run/uwsgi/php.sock";
        master = true;
        vacuum = true;
        processes = 4;
        cheaper = 1;
        php-sapi-name = "apache"; # performance tweak
        socket-modifier1 = 14;
        php-index = "index.php";
        php-set = [ "session.save_handler=files" "session.save_path=/var/www/sessions" ]; # fixes session issues with Nextcloud
        plugins = [ "php" ];
      };
    };
  };
  plugins = [ "php" ];
};

index.php:

<?php phpinfo(); ?>

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

Successfully merging this pull request may close these issues.

None yet

8 participants