Installing MediaWiki on Debian: Difference between revisions

From Andreida
 
(5 intermediate revisions by the same user not shown)
Line 127: Line 127:


=== Allow upload of larger files ===
=== Allow upload of larger files ===
in php.ini (for example: /etc/php5/apache2/php.ini) change
in php.ini (for example: /etc/php/7.0/apache2/php.ini) change
post_max_size = 8M
post_max_size = 8M
and
and
upload_max_filesize = 8M
upload_max_filesize = 8M
to whatever you need. You have to restart Apache afterwards. You should be able to do these changes per host inside /etc/apache2/sites-enabled/wiki1 in <Virtual Host> like this:
to whatever you need. You have to restart Apache afterwards. You should be able to do these changes instead per host inside /etc/apache2/sites-enabled/wiki1 in <Virtual Host> like this:
php_value upload_max_filesize 100M
php_value upload_max_filesize 100M
php_value post_max_size 100M
php_value post_max_size 100M
Line 144: Line 144:
* backup
* backup
mysqldump -p myWikiDbName > myWikiName.sql
mysqldump -p myWikiDbName > myWikiName.sql

=== backup uploaded files ===
If users uploaded files, they are not in the database but in most cases in a folder "images" in your wiki.
tar zcvhf your-wiki-name-images.tgz /var/www/wiki.your-wiki.biz/images/


=== restore a database ===
=== restore a database ===
Line 161: Line 165:
* copy your logo from wiki-old to wiki-new
* copy your logo from wiki-old to wiki-new
* restart apache
* restart apache

= Upgrading Debian =
* [[Debian#upgrade_Debian_to_the_next_major_version|upgrade Debian]]
* when reaching version 10 (cat /etc/issue):
** directory entry for dir in conf-enabled/mediawiki.conf
<Directory /var/www/wiki.YourWiki.de>

SetEnv MW_INSTALL_PATH "/var/www/wiki.YourWiki.de"
AllowOverride None
Require all granted

</Directory>
** comment out CologneBlue and Modern in LocalSettings.php
** "require_once ... WikiEditor" -> wfLoadExtension('WikiEditor'); in LocalSettings.php
** call update.php from the maintenance directory
/var/www/wiki.YourWiki.de# php maintenance/update.php --conf LocalSettings.php

* if the main page is empty, try the previous version, edit, save


= old instructions =
= old instructions =

Latest revision as of 14:56, 7 June 2023

new instructions

Install wiki and prepare files

  • Install mediawiki (this will install apache, php, mysql as needed)
 apt-get install mediawiki php-apc php5-gd php5-intl
  • Create www directory
mkdir /var/www/copy1
cd /var/www/copy1
  • in the copy create some subdirs
mkdir images config upload cache
chmod a+w config 
chmod o+w images (do this only if you later want to allow uploads)
  • link to the original
ln -s /var/lib/mediawiki/* .
  • remove LocalSettings.php
rm LocalSettings.php
  • Add a virtual host (extension .conf is important from a certain version, first loaded match is the default, so use numbers)
 vi /etc/apache2/sites-available/005-copy1.conf
 <VirtualHost *:80>
     # the VirtualHost parameter MUST match your NameVirtualHost directive
     ServerName wiki.yourdomain.com
     ServerAdmin your@email
 
     RewriteEngine on
     RewriteRule (.*) /var/www/copy1/$1
 
     <Directory /var/www/copy1/>
         Options +FollowSymLinks -Indexes
         AllowOverride All
         order deny,allow
         allow from all
     </Directory>
 
     # some directories must be protected, enable this AFTER the setup!
     #<Directory /var/www/copy1/config>
     #    Options -FollowSymLinks
     #    AllowOverride None
     #</Directory>
     <Directory /var/www/copy1/upload>
         Options -FollowSymLinks
         AllowOverride None
     </Directory>
 </VirtualHost>
  • Activate it
 yourpc:/etc/apache2/sites-enabled# ln -s ../sites-available/005-copy1.conf
  • Enable the RewriteEngine
 yourpc:/etc/apache2/mods-enabled# ln -s ../mods-available/rewrite.load
  • Restart Apache (reload is not enough because of the mod)
 /etc/init.d/apache2 restart

prepare database

  • connect to the mysql database
mysql -p
  • create the database for the current wiki
create database copy1;
  • create the user for the new database (special characters may prevent the login of this user)
CREATE USER MyAdmin@localhost  IDENTIFIED BY 'MyPlainPassword';
  • Give all rights for the new database to the new user
GRANT ALL ON copy1.* to MyAdmin@localhost;
  • Let the database reload the data
flush privileges;

configure wiki

PHP Fatal error: require_once(): Failed opening required '/var/www/yourDir/skins/CologneBlue/CologneBlue.php'

open LocalSettings.php and change

require_once "$IP/skins/CologneBlue/CologneBlue.php";
require_once "$IP/skins/Modern/Modern.php";
require_once "$IP/skins/MonoBook/MonoBook.php";
require_once "$IP/skins/Vector/Vector.php";

to

require_once "$IP/skins/CologneBlue.php";
require_once "$IP/skins/Modern.php";
require_once "$IP/skins/MonoBook.php";
require_once "$IP/skins/Vector.php";

Can't contact the database server: Access denied for user 'wikiAdmin'@'localhost' (using password: YES) (localhost))

Search in LocalSettings.php for $wgDBpassword and fix it.

Misc problems

If you are migrating an old wiki, always update both wikis to the newest version first. Remember, that you will migrate the users too, so any user details you gave in the new wikis config dialog will be lost. If you have problems with passwords, you can set them via console. Remember, that this will go into the history. Clean your history perhaps with

history -c 

afterwards.

Setting the password for wiki logins (not the database login)

cd /var/www/copy1
php maintenance/changePassword.php --user=WikiUser1 --password=HisPasswordInPlaintext --conf /var/www/copy1/LocalSettings.php

reload apache

/etc/init.d/apache2 reload

External links should open a new window

Add

$wgExternalLinkTarget = '_blank';

at the very end of LocalSettings.php. Reload Apache AND your browser page before testing.

Allow upload of other file extensions

in /var/www/copy/includes/DefaultSettings.php search for something like

$wgFileExtensions = [ 'png', 'gif', 'jpg', 'jpeg', 'webp' ];

and add the wanted extensions.

Allow upload of larger files

in php.ini (for example: /etc/php/7.0/apache2/php.ini) change

post_max_size = 8M

and

upload_max_filesize = 8M

to whatever you need. You have to restart Apache afterwards. You should be able to do these changes instead per host inside /etc/apache2/sites-enabled/wiki1 in <Virtual Host> like this:

php_value upload_max_filesize 100M
php_value post_max_size 100M

Backup / Restore the database

backup a database

  • check the name of the database of your wiki
mysql -p
show databases;
exit
  • backup
mysqldump -p myWikiDbName > myWikiName.sql

backup uploaded files

If users uploaded files, they are not in the database but in most cases in a folder "images" in your wiki.

tar zcvhf your-wiki-name-images.tgz /var/www/wiki.your-wiki.biz/images/

restore a database

  • create a database
create database wiki_MyWikiName
exit
mysql -p wiki_MyWikiName < myWikiName.sql

Migrating

  • create a backup of wiki-old
  • create a new functional wiki-new
    • have LocalSettings.php/$wgDBprefix and "Database table prefix" (in the config dialog) match the old wiki
  • restore the backup from wiki-old into wiki-new
  • fix passwords if needed, make sure you can login etc.
  • copy the content of wiki-old/images to wiki-new/images, these are the uploaded files
  • copy the favicon.ico (restart the browser to see the effect)
  • copy your logo from wiki-old to wiki-new
  • restart apache

Upgrading Debian

  • upgrade Debian
  • when reaching version 10 (cat /etc/issue):
    • directory entry for dir in conf-enabled/mediawiki.conf
<Directory /var/www/wiki.YourWiki.de>
    SetEnv MW_INSTALL_PATH "/var/www/wiki.YourWiki.de"
    AllowOverride None
    Require all granted
</Directory>
    • comment out CologneBlue and Modern in LocalSettings.php
    • "require_once ... WikiEditor" -> wfLoadExtension('WikiEditor'); in LocalSettings.php
    • call update.php from the maintenance directory
/var/www/wiki.YourWiki.de# php maintenance/update.php --conf LocalSettings.php
  • if the main page is empty, try the previous version, edit, save

old instructions

Install mediawiki (this will install apache, php, mysql as needed)

 apt-get install mediawiki

Add a virtual host

 vi /etc/apache2/sites-available/mediawiki
 <VirtualHost *:80>
     # the VirtualHost parameter MUST match your NameVirtualHost directive
     ServerName wiki.yourdomain.com
     ServerAdmin your@email
 
     RewriteEngine on
     RewriteRule (.*) /var/lib/mediawiki/$1
 
     <Directory /var/lib/mediawiki/>
         Options +FollowSymLinks -Indexes
         AllowOverride All
         order deny,allow
         allow from all
     </Directory>
 
     # some directories must be protected, enable this AFTER the setup!
     #<Directory /var/lib/mediawiki/config>
     #    Options -FollowSymLinks
     #    AllowOverride None
     #</Directory>
     <Directory /var/lib/mediawiki/upload>
         Options -FollowSymLinks
         AllowOverride None
     </Directory>
 </VirtualHost>

Activate it

 yourpc:/etc/apache2/sites-enabled# ln -s ../sites-available/mediawiki

Enable the RewriteEngine

 yourpc:/etc/apache2/mods-enabled# ln -s ../mods-available/rewrite.load

Reload Apache

 /etc/init.d/apache2 reload

Configure the wiki

 http://wiki.<YourDomain>/config/index.php  

Move the LocalSettings.php to the correct place

  mv /var/lib/mediawiki/config/LocalSettings.php /etc/mediawiki

If you have the wiki more than once in use, move the LocalSettings.php to the copy of the wiki.

Prevent new user registrations except by sysops. Add in /etc/mediawiki/LocalSettings.php at the end:

 $wgGroupPermissions['*']['createaccount'] = false;

Restrict anonymous editing. Add in /etc/mediawiki/LocalSettings.php at the end:

 $wgGroupPermissions['*']['edit'] = false;


New users will still be able to be created by sysops, in the following manner:

  1. Go to Special:Userlogin, when logged in as a sysop.
  2. Click on "Create an account" link to get to the account creation form.
  3. Enter a username and an email address, and click the "by email" button. Note you need $wgEnableEmail=true or else the sysop must pick a password and send it to the user.
  4. The account will be created with a random password which is then emailed to the given address (as with the "forgot password" feature). The user will be requested to change password at first login; when he does this, his e-mail address will also be marked as confirmed.
    When you click the "create account" button instead, you have to manually send the user his password. If you've set $wgMinimalPasswordLength=0 (default configuration up to version 1.15) and you've left the password field blank, the user will be emailed an e-mail address confirmation request but will be unable to access Special:Confirmemail to perform the confirmation. Instead, he'll get an error (unless you've added it to $wgWhitelistRead); he'll be able to login with a blank password and then confirm email, but his password will not have been reset (he'll have to reset it manually).


Cache

The file cache is enabled by setting three variables in LocalSettings.php:

   $wgUseFileCache = true; /* default: false */
   $wgFileCacheDirectory = "$IP/cache";
   $wgShowIPinHeader = false;

This causes the rendered HTML webpage for each page of the wiki to be stored in an individual file on the hard disk. Any subsequent requests from anonymous users are met not by rendering the page again, but by simply sending the stored HTML version which is on the disk. This saves time.

You will have to check the error.log in /var/log/apache2 for error about the cache directory, if it need more write rights or does not exist or so.

Navigation

Change the links on the page: MediaWiki:Sidebar

Set in LocalSettings.php $wgLogo to the URL (!) of an image.


In case you have problems: The official way did never work for me with old versions. So instead I did

  • copy my image as wiki.png to /usr/share/mediawiki/skins/common/images
  • repeat after updates of the wiki or just use a link, so you only need to recreate the link

just copy your file to the directory, rename wiki.png and say

ln -s mypic.png wiki.png

Allow more file types (extension) for upload

  • edit /etc/mediawiki/LocalSettings.php and add or modify
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'zip', 'xxx' );
$wgVerifyMimeType = false;
$wgCheckFileExtensions = false;
$wgStrictFileExtensions = false;

maybe this is overkill, but it works for me


more than one wiki on the same server

http://www.steverumberg.com/wiki/index.php?title=WikiHelp_-_Method_Two

  • install mediawiki (either just mediaiwiki or perhaps more? mediawiki is enough!)
apt-get install mediawiki imagemagick php5-gd mediawiki-math memcached clamav  tinyca openssl-blacklist  php-pear libipc-sharedcache-perl
  • now we have the wiki in /var/lib/mediawiki
  • create a copy and cd there
mkdir /var/www/copy1
cd /var/www/copy1
  • in the copy create some subdirs
mkdir images config
chmod a+w config
  • link to the original
ln -s /var/lib/mediawiki/* .
  • remove settings
rm LocalSettings.php
  • Link in the configuration script file that will set up the wiki:
cd config && ln -s /var/lib/mediawiki/config/index.php .
  • now continue like above, when you just create a new wiki

backup a database

  • check the name of the database of your wiki
mysql -p
show databases;
exit
  • backup
mysqldump -p myWikiDbName > myWikiName.sql

restore a database

  • create a database
create database wiki_MyWikiName
exit
mysql -p wiki_MyWikiName < myWikiName.sql

create user and allow him access to the database

  • create the user
mysql> CREATE USER MyWikiAdmin IDENTIFIED BY 'myPassword';
mysql> GRANT ALL ON wiki_MyWikiName.* to MyWikiAdmin;


make sure $wgDBadminuser and $wgDBadminpassword are in your LocalSettings.php and call

php maintenance/update.php --conf /<path-to-your-wiki>/LocalSettings.php