Support #963
Updated by Daniel Curtis over 3 years ago
{{>toc}}
This is a guide on setting up MediaWiki with Nginx on FreeBSD 12.
h1. Prepare the Environment
* Before installation of the components, make sure everything is up to date using the following command:
<pre>
pkg update -f && pkg upgrade
</pre>
* Create the mediawiki user:
<pre>
pw user add -n mediawiki -m -s /sbin/nologin -c "MediaWiki"
</pre>
---
h1. Install Nginx
* Install Nginx
<pre>
pkg install nginx
</pre>
* Start and enable nginx at boot:
<pre>
sysrc nginx_enable=YES
service nginx start
</pre>
* Create a configuration directory to make managing individual server blocks easier
<pre>
mkdir /usr/local/etc/nginx/conf.d
</pre>
* Edit the main nginx config file:
<pre>
vi /usr/local/etc/nginx/nginx.conf
</pre>
#* And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
<pre>
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;
}
</pre>
---
h1. Install PostgreSQL
* Start by installing the postgresql packages:
<pre>
pkg install postgresql12-{server,client} php74-{pdo_pgsql,pgsql}
</pre>
* Enable, initialize and start PostgreSQL
<pre>
sysrc postgresql_enable=YES
service postgresql initdb
service postgresql start
</pre>
* Edit the pg_hba.conf file:
<pre>
vi /var/db/postgres/data12/pg_hba.conf
</pre>
#* And add the following to the end of the file to enable password authentication:
<pre>
host all all samehost md5
</pre>
h2. Create PostgreSQL Databases and Users
* Log in to postgresql user account
<pre>
su - postgres
</pre>
* Connect to postgresql database
<pre>
psql -d template1
</pre>
#* Create a user and database for MediaWiki:
<pre>
CREATE USER mediawikiuser WITH PASSWORD 'SuperSecretPassword' CREATEDB;
CREATE DATABASE mediawikidb OWNER mediawikiuser;
</pre>
* Quit postgresql and exit the user:
<pre>
\q
exit
</pre>
---
h1. Install MediaWiki
* Install mediawiki:
<pre>
pkg install mediawiki135-php74
</pre>
* Create an *wiki.example.com server block* config file:
<pre>
vi /usr/local/etc/nginx/conf.d/wiki.example.com.conf
</pre>
#* Add the following:
<pre>
server {
server_name cyto.wiki;
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;
empty_gif;
}
location ^~ /cache/ {
deny all;
}
location /dumps {
root /usr/local/www/mediawiki/local;
autoindex on;
}
}
</pre>
* Create the mediawiki php-fpm pool config file:
<pre>
vi /usr/local/etc/php-fpm.d/mediawiki.conf
</pre>
#* And add the following:
<pre>
[mediawiki.example.com]
user = mediawiki
group = www
listen = /var/run/mediawiki.sock
listen.owner = mediawiki
listen.group = 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"
</pre>
* Change the file ownership to the mediawiki user:
<pre>
chown -R mediawiki: /usr/local/www/mediawiki/
</pre>
* Restart nginx and start php-fpm:
<pre>
service nginx restart
sysrc php_fpm_enable=YES
service php-fpm start
</pre>
* Complete the installation by opening a web browser and go to http://wiki.example.com/ then follow the basic account and database setup steps.
---
h1. Resources
* https://www.mediawiki.org/wiki/Manual:Installation_guide
* https://www.mediawiki.org/wiki/Manual:Short_URL/Nginx
* https://www.nginx.com/resources/wiki/start/topics/recipes/mediawiki/