Support #963
Install MediaWiki on FreeBSD
Description
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; }
- And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
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
- And add the following to the end of the file to enable password authentication:
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;
- Create a user and database for MediaWiki:
- Quit postgresql and exit the user:
\q exit
Install MediaWiki¶
- Install mediawiki:
pkg install mediawiki135-php74
- Create an wiki.example.com server block config file:
vi /usr/local/etc/nginx/conf.d/wiki.example.com.conf
- Add the following:
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; } }
- Add the following:
- Create the mediawiki php-fpm pool config file:
vi /usr/local/etc/php-fpm.d/mediawiki.conf
- And add the following:
[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"
- And add the following:
- 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 http://wiki.example.com/ then follow the basic account and database setup steps.