Support #963

Install MediaWiki on FreeBSD

Added by Daniel Curtis over 2 years ago. Updated about 2 years ago.

Web Server
Target version:
Start date:
Due date:
% Done:


Estimated time:
1.00 h
Spent time:


This is a guide on setting up MediaWiki with Nginx on FreeBSD 12.

Prepare the Environment

  • Before installation of the components, make sure everything is up to date using the following command:
    pkg update -f && pkg upgrade
  • Create the mediawiki user:
    pw user add -n mediawiki -m -s /sbin/nologin -c "MediaWiki" 

Install Nginx

  • Install Nginx
    pkg install nginx
  • Start and enable nginx at boot:
    sysrc nginx_enable=YES
    service nginx start
  • Create a configuration directory to make managing individual server blocks easier
    mkdir /usr/local/etc/nginx/conf.d
  • Edit the main nginx config file:
    vi /usr/local/etc/nginx/nginx.conf
    • And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
      worker_processes  1;
      error_log  /var/log/nginx-error.log;
      events {
          worker_connections  1024;
      http {
          include       mime.types;
          default_type  application/octet-stream;
          sendfile        on;
          keepalive_timeout  65;
          # Load config files from the /etc/nginx/conf.d directory
          include /usr/local/etc/nginx/conf.d/*.conf;

Install PostgreSQL

  • Start by installing the postgresql packages:
    pkg install postgresql12-{server,client} php74-{pdo_pgsql,pgsql}
  • Enable, initialize and start PostgreSQL
    sysrc postgresql_enable=YES
    service postgresql initdb
    service postgresql start
  • Edit the pg_hba.conf file:
    vi /var/db/postgres/data12/pg_hba.conf
    • And add the following to the end of the file to enable password authentication:
      host    all        all        samehost        md5

Create PostgreSQL Databases and Users

  • Log in to postgresql user account
    su - postgres
  • Connect to postgresql database
    psql -d template1
    • Create a user and database for MediaWiki:
      CREATE USER mediawikiuser WITH PASSWORD 'SuperSecretPassword' CREATEDB;
      CREATE DATABASE mediawikidb OWNER mediawikiuser;
  • Quit postgresql and exit the user:

Install MediaWiki

  • Install mediawiki:
    pkg install mediawiki135-php74
  • Create an server block config file:
    vi /usr/local/etc/nginx/conf.d/
    • Add the following:
      server {
          root /usr/local/www/mediawiki;
          index  index.php;
          client_max_body_size 5m;
          client_body_timeout 60;
          location / {
              try_files $uri $uri/ @rewrite;
          location @rewrite {
              rewrite ^/(.*)$ /index.php?title=$1&$args;
          location ^~ /maintenance/ {
              return 403;
           location /rest.php {
              try_files $uri $uri/ /rest.php?$args;
          location ~ \.php$ {
              include fastcgi_params;
              fastcgi_pass unix:/var/run/mediawiki.sock;
              fastcgi_param SCRIPT_FILENAME $request_filename;
          location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
              try_files $uri /index.php;
              expires max;
              log_not_found off;
          location = /_.gif {
              expires max;
          location ^~ /cache/ {
              deny all;
          location /dumps {
              root /usr/local/www/mediawiki/local;
              autoindex on;
  • Create the mediawiki php-fpm pool config file:
    vi /usr/local/etc/php-fpm.d/mediawiki.conf
    • And add the following:
      user = mediawiki
      group = www
      listen = /var/run/mediawiki.sock
      listen.owner = mediawiki = www
      pm = dynamic
      pm.max_children = 5
      pm.start_servers = 2
      pm.min_spare_servers = 1
      pm.max_spare_servers = 3
      ;php_admin_value[session.save_path] = "/usr/local/www/mediawiki/tmp" 
  • Change the file ownership to the mediawiki user:
    chown -R mediawiki: /usr/local/www/mediawiki/
  • Restart nginx and start php-fpm:
    service nginx restart
    sysrc php_fpm_enable=YES
    service php-fpm start
  • Complete the installation by opening a web browser and go to then follow the basic account and database setup steps.



Updated by Daniel Curtis over 2 years ago

  • Estimated time set to 1.00 h
  • % Done changed from 0 to 100
  • Description updated (diff)
  • Subject changed from Install a MediaWiki on FreeBSD to Install MediaWiki on FreeBSD

Updated by Daniel Curtis over 2 years ago

  • Status changed from New to Resolved

Updated by Daniel Curtis about 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF