WordPress
Wordpress is a self-hosted content management web application, especially designed for blogging but also a good start to create your own website. It can customized with themes and an in-build site editor and further extended with plugins.
Installation
A simple local setup of Wordpress can be enabled with the following setup
services.wordpress.sites."localhost" = {
enable = true;
virtualHost.adminAddr = "hello@example.org";
};
Visit http://localhost to setup your new Wordpress instance. By default, a Mysql server is configured automatically so you won't have to setup the database backend.
Configuration
Language
The default language of the Wordpress module will be English. It is possible to package additional languages and make them available for your specific instance. Using extraConfig
you can configure the default language. In this example, we're going to package and enable the German language.
{ pkgs, ... }: let
language-de = pkgs.stdenv.mkDerivation {
name = "language-de";
src = pkgs.fetchurl {
url = "https://de.wordpress.org/wordpress-6.0.1-de_DE.tar.gz";
sha256 = "sha256-dlas0rXTSV4JAl8f/UyMbig57yURRYRhTMtJwF9g8h0=";
};
installPhase = "mkdir -p $out; cp -r ./wp-content/languages/* $out/";
};
in {
services.wordpress.sites."localhost" = {
enable = true;
languages = [ language-de ];
virtualHost.adminAddr = "hello@example.org";
extraConfig = ''
define ('WPLANG', 'de_DE');
'';
};
}
Make sure that the source of your language package corresponds to the Wordpress package version you're using. Consult the translation portal of Wordpress for the specific country and language codes available. This example is using the code de_DE
(Germany/German) in the source URL and also the extraConfig
part.
Plugins and themes
In case you want to package and add custom plugins and themes, you can add these too
let
# For shits and giggles, let's package the responsive theme
responsive = pkgs.stdenv.mkDerivation {
name = "responsive";
# Download the theme from the wordpress site
src = pkgs.fetchurl {
url = http://wordpress.org/themes/download/responsive.1.9.7.6.zip;
sha256 = "06i26xlc5kdnx903b1gfvnysx49fb4kh4pixn89qii3a30fgd8r8";
};
# We need unzip to build this package
buildInputs = [ pkgs.unzip ];
# Installing simply means copying all files to the output directory
installPhase = "mkdir -p $out; cp -R * $out/";
};
# Wordpress plugin 'akismet' installation example
akismet = pkgs.stdenv.mkDerivation {
name = "akismet";
# Download the theme from the wordpress site
src = pkgs.fetchurl {
url = https://downloads.wordpress.org/plugin/akismet.3.1.zip;
sha256 = "1i4k7qyzna08822ncaz5l00wwxkwcdg4j9h3z2g0ay23q640pclg";
};
# We need unzip to build this package
buildInputs = [ pkgs.unzip ];
# Installing simply means copying all files to the output directory
installPhase = "mkdir -p $out; cp -R * $out/";
};
in {
services.wordpress.sites."localhost" = {
themes = [ responsive ];
plugins = [ akismet ];
virtualHost.adminAddr = "hello@example.org";
extraConfig = ''
// Activate and enable theme responsive as default
define ('WP_DEFAULT_THEME', 'responsive');
'';
};
}
Unfortunately you'll have to enable plugins and themes every time you update or install them manually. Hopefully Wordpress plugins and themes will also be packaged inside the Nixpkgs repository, see this draft pull request.
Tips and tricks
Enable SSL behind reverse proxy
In case you're running Wordpress behind a reverse proxy which offers a SSL/https connection to the outside, you can force Wordpress to use the https protocol
services.wordpress.sites."localhost".extraConfig = ''
// Needed to run behind reverse proxy
define('FORCE_SSL_ADMIN', true);
$_SERVER['HTTPS']='on';
'';