SELinux

S

To MediaWiki on a system running SELinux the following additional steps must be performed:

chcon -R -t httpd_user_content_t /path/to/mediawiki_install

After building the PHP fileinfo extension:

chcon -t httpd_sys_script_exec_t /usr/lib/php/modules/fileinfo.so

Any additional files which will be execed by apache must be httpd_user_script_exec_t (not including PHP files).

Files which are httpd_*_script_exec_t may not be written to by the apache process.

Ideally the MediaWiki executable (PHP) files should all be set httpd_user_script_exec_t but this is not required by the current SELinux policy.

Upload directories
If uploads are enabled in your configuration, you might encounter a context problem because of the tmp directory used during the file upload process.

Creating a tmp directory in /var/www/ instead of using /tmp or the 'default setting' for upload_tmp_dir in <tvar|path3>/etc/php.ini</> can get around this problem.

Be sure to correctly chmod chgrp and chcon this new <tvar|dir>tmp</> directory.

Uploading images
If the MediaWiki directories were copied or moved to migrate from an old system to another system that has SELinux enabled (enforcing) then the copied/moved files and directories may not have the correct SELinux context types.

If this is the case, image uploads and thumbnail creation could be prevented by SELinux enforcement even if the owner and permissions are already set correctly.

The <tvar|scr1>includes/GlobalFunctions.php</> script file (and possibly other .php files in the MediaWiki install directory) must have the SELinux context type <tvar|type1>httpd_sys_script_exec_t</> to permits use of the PHP <tvar|cmd>function.mkdir</> command.

Without the correct context on the script, file uploads or thumbnail creation may fail on the attempt to create a hashed directory on the server.

From the wiki base install directory, check for the correct SELinux context by entering the command:

ls -Z includes/GlobalFunctions.php

If the listed SELinux security context type is not <tvar|type>httpd_sys_script_exec_t</>, change it with the command:

chcon -t httpd_sys_script_exec_t includes/GlobalFunctions.php

Assuming the permissions (755) and owner (usually 'apache') on the images directory are correct, the entire images directory tree must have the <tvar|type>httpd_sys_script_rw_t</> SELinux context type so that scripts (.php files) running in the web server process are allowed read/write access.

Check this with the command:

ls -dZ images

If the listed SELinux security context type is not <tvar|type>httpd_user_rw_content_t</>, change it with the command:

chcon -R -t httpd_user_rw_content_t images

Thumbnail generation may fail with error messages like <tvar|errmsg>ulimit: cpu time/virtual memory/file size: cannot modify limit: Permission denied</>.

To allow this you should enable <tvar|1>httpd_setrlimit</>:

setsebool -P httpd_setrlimit 1

Debug logging file
If you want to store your MediaWiki <tvar|dbg>wfDebug</> logs into a file, and have followed the <tvar|1></> page thoroughly but nothing gets written to your logging file, you might need to set the SELinux context of the logging file to <tvar|scrrw>httpd_sys_script_rw_t</> using the following command:

chcon -t httpd_sys_script_rw_t /path/to/your/debug/file

Enabling InstantCommons
If you want to enable the feature on your wiki, and your OS implements SElinux, you should first tell Selinux to allow HTTPD scripts and modules to connect to the network. To do so, enter the following command: Sejd

getsebool -a

See what is the value of the boolean: <tvar|1>httpd_can_network_connect</>. If it is set to on already, nothing needs to be done, Selinux will not prevent HTTPD scripts and modules from connecting to the network.

However, if it is set to off, enter the following command line to activate it permanently:

setsebool -P httpd_can_network_connect on

The -P option means permanently.

If you do not use it, the value of the boolean will be reinitialized on your next system reboot.

That is it. Make sure the modification was implemented successfully by issuing <tvar|cmd>getsebool -a</> one more time, and verifying the value was updated correctly. If that is the case, you can now enable InstantCommons successfully.

Sending emails
s from MediaWiki may not work at all, or you may get Unknown error on actions that trigger an email.

You need to enable sending emails from the webserver.

The following command may enable this:

setsebool -P httpd_can_sendmail on

Pygments for SyntaxHighlight
<tvar|ext></> use a library called pygments that provides the syntax highlight.

If Syntax highlight doesn't work you may need to enable execution on the pygments folder:

semanage fcontext -a -t httpd_sys_script_exec_t '/&lt;path_to_mediawiki>/extensions/SyntaxHighlight_GeSHi/pygments(/.*)?' restorecon -R -v /&lt;path_to_mediawiki>/extensions/SyntaxHighlight_GeSHi/pygments/

Other handy SELinux tricks
To find out if SELinux is enabled on your system:

getenforce

audit2allow is a perl script that interprets the selinux errors and constructs the right rules to overcome various problems.

/usr/bin/audit2allow -i /var/log/messages

It outputs the lines you need to add to your policies to permit things that are reported as failing.

In <tvar|dir>/var/log/messages</> you should find an id corresponding to the selinux error that occurred.

sealert -l &lt;id>

will give more information.

One possible source of error is that you copied the uncompressed installation files from a home directory to a system area thereby invalidating their security context.

This can be addressed by a command such as....

restorecon -R -v /var/www/html/mediawiki

When all else fails, try this

man setenforce

Updating Local Policy Contexts
Changes made by using chcon are only temporary, in that they will be overwritten by any subsequent action which relabels the files (e.g. restorecon, make relabel, etc).

To avoid this, you can add custom context entries to your local policy using the semanage utility.

These entries are stored in a separate file, <tvar|file>file_contexts.local</>, which is not part of the base SELinux policy.

The entries in this file always override the entries in the base policy.

For example, the following commands will label your main wiki files as <tvar|as1>httpd_user_content_t</>, your PHP scripts as <tvar|as2>http_user_script_exec_t</>, and your images directory for uploading as <tvar|as3>httpd_user_script_rw_t</>:

semanage fcontext -a -t httpd_user_content_t ' /path/to/mediawiki/install(/.*)?' semanage fcontext -a -t httpd_user_script_exec_t ' /path/to/mediawiki/install/.*\/php5?' semanage fcontext -a -t httpd_user_script_exec_t ' /path/to/mediawiki/install/includes/.*\.php5?' semanage fcontext -a -t httpd_user_rw_content_t ' /path/to/mediawiki/install/images(/.*)?' semanage fcontext -a -t httpd_user_rw_content_t ' /path/to/mediawiki/install/cache(/.*)?'

After running these commands, you can verify your changes by running

restorecon -R -v /path/to/mediawiki/install