{"id":1451,"date":"2017-03-23T16:45:05","date_gmt":"2017-03-23T23:45:05","guid":{"rendered":"https:\/\/www.coastalvectors.com\/blog\/?p=1451"},"modified":"2017-09-07T14:08:44","modified_gmt":"2017-09-07T21:08:44","slug":"mediawiki-on-centos-7","status":"publish","type":"post","link":"https:\/\/www.coastalvectors.com\/blog\/2017\/03\/mediawiki-on-centos-7\/","title":{"rendered":"MediaWiki on CentOS 7"},"content":{"rendered":"<p><a href=\"https:\/\/www.coastalvectors.com\/blog\/2017\/03\/mediawiki-on-centos-7\/600px-mediawiki_logo_1-svg\/\" rel=\"attachment wp-att-1452\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1452\" src=\"https:\/\/www.coastalvectors.com\/blog\/wp-content\/uploads\/2017\/03\/600px-MediaWiki_logo_1.svg_-450x450.png\" alt=\"\" width=\"450\" height=\"450\" srcset=\"https:\/\/www.coastalvectors.com\/blog\/wp-content\/uploads\/2017\/03\/600px-MediaWiki_logo_1.svg_-450x450.png 450w, https:\/\/www.coastalvectors.com\/blog\/wp-content\/uploads\/2017\/03\/600px-MediaWiki_logo_1.svg_-150x150.png 150w, https:\/\/www.coastalvectors.com\/blog\/wp-content\/uploads\/2017\/03\/600px-MediaWiki_logo_1.svg_.png 600w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<p>I&#8217;ve set up a few installations of MediaWiki in the past on different operating systems. It&#8217;s not the type of thing I do a lot, but when I do, It&#8217;s usually not too much trouble.<\/p>\n<p>I was migrating an old MediaWiki installation from a Windows 2007 server to CentOS 7. I figured it would be pretty routine. It turns out there were a couple little hiccups along the way that I figure I should document to help me out in the future.<\/p>\n<p>The first problem I ran into is that CentOS 7 doesn&#8217;t ship with a new enough version of of PHP for the current release of Media Wiki.<\/p>\n<p>Uninstall built in version of PHP<\/p>\n<pre>yum erase php\r\nyum erase php-common<\/pre>\n<p>Install yum repo for newer PHP release<\/p>\n<pre>rpm -Uvh https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\r\nrpm -Uvh https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm<\/pre>\n<p>Install PHP packages<\/p>\n<pre>yum install php55w* --skip-broken<\/pre>\n<p>This allowed MediaWiki to run finally, and I was able to create a new LocalSettings.php. From there I restored the SQL database without any issue. Don&#8217;t forget to install MariaDB.<\/p>\n<pre>yum install mariadb-server mariadb<\/pre>\n<p>To import the old SQL data to the new DB, first creat a DB with the same name, and then pupolate it with the sql file.<\/p>\n<pre># Get into mysql shell\r\nmysql --password=********\r\n# Create DB with same name as old DB\r\nmysql&gt; CREATE DATABASE my_wiki;\r\n# Exit shell\r\n\r\n# Import old SQL data to new DB\r\nmysql --password=******** my_wiki &lt; \/wiki.sql<\/pre>\n<p>I also copied over the images directory from the old installation.<\/p>\n<p>The next issue I had is permissions. SELinux wasn&#8217;t even on my mind, and provided all sort of permission problems. I ran the following commands on my html directory where MediaWiki is installed in an attempt to fix everything.<\/p>\n<pre>sudo chown apache:apache -R \/var\/www\/html\/\r\n\r\nfind . -type f -exec chmod 0644 {} \\;\r\nfind . -type d -exec chmod 0755 {} \\;\r\n\r\nsudo chcon -t httpd_sys_content_t \/var\/www\/html -R\r\nsudo chcon -t httpd_sys_rw_content_t \/var\/www\/html\/images\/ -R<\/pre>\n<p>At this point, MediaWiki is running, but I couldn&#8217;t see any images, or upload any files. I tweak settings in LocalSettings.php but to no avail. I enabled logs and better error messages by adding these lines to LocalSettings.php<\/p>\n<pre>$wgShowExceptionDetails = true;\r\n$wgDebugLogFile = \"\/var\/log\/mediawiki\/debug-{$wgDBname}.log\";<\/pre>\n<p>When I upload a file using MediaWiki, I get the error:<\/p>\n<pre>Could not create directory \"mwstore:\/\/local-backend\/local-public\/1\/1e\".<\/pre>\n<p>The log file shows the following error:<\/p>\n<pre>[FileOperation] mkdir(): Permission denied\r\n[FileOperation] FSFileBackend::doPrepareInternal: cannot create directory \/1\/1e<\/pre>\n<p>I am unable to upload images, so I Google the error message and check my settings. Almost all of the sites talking about this error suggested permission issues with the images folder. I checked my permissions over, and over again with no luck. The rest fo the sites talked about having the $wgTmpDirectory set correctly, which I&#8217;m pretty sure I did.<\/p>\n<pre>$wgEnableUploads = true;\r\n$wgUseImageMagick = true;\r\n$wgImageMagickConvertCommand = \"\/usr\/bin\/convert\";\r\n$wgTmpDirectory = '\/var\/www\/html\/images\/temp';<\/pre>\n<p>What bothers me is that the error message in the log looks like it is trying to mkdir at the root level, however MediaWiki switches a lot between url paths (relative) and absolute. It wasn&#8217;t clear. The next debugging step was using strace to see what the OS was doing. I attached strace to one of the apache processes and uploaded a file, and lo:<\/p>\n<pre>mkdir(\"\/temp\", 0777)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = -1 EACCES (Permission denied)<\/pre>\n<p>It is trying to use my root directory as the images fodler location, even though I have a different tmp directory specified in my settings file.<\/p>\n<p>It turns out that there are default setting in the img_auth.php file that don&#8217;t appear to be correct. They get automatically set based on the environment. I chose to explicitely set them in the LocalSettings.php document instead.<\/p>\n<pre># Redefining Upload Directory and Path from img_auth.php\r\n$wgUploadDirectory = '\/var\/www\/html\/images';\r\n$wgUploadPath = '\/images';<\/pre>\n<p>Finally. My images instantly start working and I can upload files again. Thank goodness! This wasn&#8217;t a difficult thing, but it is surprising that I couldn&#8217;t find any help on the internet for this specific problem. And since I don&#8217;t install\/perform maintenance on MediaWikis very often, there is a lot of stuff I have to relearn. So here it is, some notes on this issue for my future self, in case I ever need it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve set up a few installations of MediaWiki in the past on different operating systems. It&#8217;s not the type of thing I do a lot, but when I do, It&#8217;s usually not too much trouble. I was migrating an old MediaWiki installation from a Windows 2007 server to CentOS 7. I figured it would be &hellip; <a href=\"https:\/\/www.coastalvectors.com\/blog\/2017\/03\/mediawiki-on-centos-7\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">MediaWiki on CentOS 7<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,1],"tags":[],"class_list":["post-1451","post","type-post","status-publish","format-standard","hentry","category-programming","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/posts\/1451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/comments?post=1451"}],"version-history":[{"count":2,"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/posts\/1451\/revisions"}],"predecessor-version":[{"id":1505,"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/posts\/1451\/revisions\/1505"}],"wp:attachment":[{"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/media?parent=1451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/categories?post=1451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coastalvectors.com\/blog\/wp-json\/wp\/v2\/tags?post=1451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}