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

wordpress: Patch loader for $WORDPRESS_CONFIG #86377

Closed
wants to merge 1 commit into from

Conversation

@schneefux
Copy link
Contributor

schneefux commented Apr 30, 2020

Motivation for this change

Patch Wordpress' wp-loader.php to load wp-config.php from $WORDPRESS_CONFIG if the environment variable is set and the file exists.

This makes it possible to run the web application directly from the nix store, without copying all of the files like the wordpress module does.

This is the NixOS configuration I'm using to run it:

  services.nginx = {
    enable = true;
    virtualHosts = {
      "wordpress.${config.networking.domain}" = {
        root = "${pkgs.wordpress}/share/wordpress";
        locations = {
          "/" = {
            index = "index.php";
            tryFiles = "$uri $uri/ /index.php?$args";
          };
          "^~ /wp-content/".alias = "/var/www/wordpress/wp-content/";
          "~ \\.php$".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";
          stats = "/run/uwsgi/php-stats.sock";
          master = true;
          vacuum = true;

          php-sapi-name = "apache"; # opcode caching tweak

          php-allowed-ext = [ ".php" ".inc" ];
          socket-modifier1 = 14;
          php-index = "index.php";

          php-set = [
            "date.timezone=${config.time.timeZone}"
            "session.save_handler=files"
            "session.save_path=/tmp/sessions"
            "display_errors=off"
          ];
          env = [
            "WORDPRESS_CONFIG=/var/www/wordpress/wp-config.php"
          ];

          plugins = [ "php" ];
        };
      };
    };
    plugins = [ "php" ];
  };

In my wp-config.php, I have set $WP_CONTENT_DIR to a state directory:

define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/wp-content' );
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
@flokli
Copy link
Contributor

flokli commented Apr 30, 2020

Has this been suggested upstream too? I think it's a very good idea for NixOS, but it's probably not limited to us…

@@ -9,6 +9,9 @@ stdenv.mkDerivation rec {
sha256 = "10zjgbr96ri87r5v7860vg5ndbnjfhjhily4m9nyl60f1lbjdhrr";
};

# exposes $WORDPRESS_CONFIG variable to configure wp-config.php path
patches = [ ./wordpress-wp-config.patch ];

This comment has been minimized.

Copy link
@Mic92

Mic92 Apr 30, 2020

Contributor

Could open a ticket here: https://core.trac.wordpress.org and add reference here? To make a stronger case: Docker people might be happy to have feature as well.

This comment has been minimized.

Copy link
@flokli
@schneefux schneefux force-pushed the schneefux:pkg.wordpress-env-config branch from b58cc44 to 1329878 May 1, 2020
@schneefux
Copy link
Contributor Author

schneefux commented May 1, 2020

This would be great to have upstream, but I'm not involved in the Wordpress dev community. I added a link to the second ticket.

@flokli
Copy link
Contributor

flokli commented May 5, 2020

While I understand this is appealing, if nobody intends to upstream this, there's also no reason to carry this downstream.

@flokli flokli closed this May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.