Skip to content
This repository has been archived by the owner on Feb 24, 2018. It is now read-only.

Hosting your own MALgraph

Marcin Kurczewski edited this page Apr 19, 2015 · 5 revisions

I assume you have basic knowledge about Apache, virtual hosts etc. This guide is for Debian, but Windows users should be good with some googling. So let's talk CLI:

Basic checkout

rr-@burza:/srv/www$ git clone https://github.com/rr-/malgraph4.git
rr-@burza:/srv/www$ cd malgraph4
rr-@burza:/srv/www/malgraph4$ git submodule init
rr-@burza:/srv/www/malgraph4$ git submodule update

Installing prerequisities

rr-@burza:/srv/www/malgraph4$ su
root@burza:/srv/www/malgraph4# apt-get install apache2.2-mpm-prefork
root@burza:/srv/www/malgraph4# apt-get install php5 #I have 5.6.7
root@burza:/srv/www/malgraph4# apt-get install php5-curl #for talking to MAL
root@burza:/srv/www/malgraph4# apt-get install php5-gd #for the score distribution images
root@burza:/srv/www/malgraph4# apt-get install php5-sqlite #for storage

Configuring Apache

root@burza:/srv/www/malgraph4# cd /etc/apache2/sites-available/
root@burza:/etc/apache2/sites-available# vim malgraph

Paste following:

<VirtualHost *:80>
    ServerName mg.example.com
    DocumentRoot /srv/www/malgraph4/
</VirtualHost>

then save the file and exit.

root@burza:/etc/apache2/sites-available# a2ensite malgraph
root@burza:/etc/apache2/sites-available# service apache2 reload
root@burza:/etc/apache2/sites-available# exit

Configuring MG for first use

Creating database files

This is going to create the database in data/db: 64 .sqlite files for user data and 1 file for media.

rr-@burza:/srv/www/malgraph4$ php scripts/make-db.php

Creating other files

This is going to download JQuery dependencies and create necessary files.

rr-@burza:/srv/www/malgraph4$ php scripts/init.php

Note that this script should finish almost instantly. Other people have reported it to run seemingly forever; this is because something is broken in their CURL version. To fix this, try adding to the config in local.php (which is going to be described later in the tutorial) either one of the following lines:

Config::$downloaderMaxParallelJobs = 1;
Config::$downloaderUseMultiHandles = false;

Granting required privileges to Apache

rr-@burza:/srv/www/malgraph4$ chmod -R 0777 data/db
rr-@burza:/srv/www/malgraph4$ chmod -R 0777 data/logs
rr-@burza:/srv/www/malgraph4$ chmod -R 0777 data/cache
rr-@burza:/srv/www/malgraph4$ chmod -R 0777 data/mirror
rr-@burza:/srv/www/malgraph4$ chmod 0777 data/queue-users.lst
rr-@burza:/srv/www/malgraph4$ chmod 0777 data/queue-media.lst
rr-@burza:/srv/www/malgraph4$ chmod 0777 data/queue-sizes.json
rr-@burza:/srv/www/malgraph4$ chmod 0777 data/banned-users.lst

Changing default settings

For MG to work you're going to need API key. You can ask Xinil for this. More details below.

rr-@burza:/srv/www/malgraph4$ vim src/local.php

Then let's paste some basic config:

<?php
ini_set('memory_limit', '512M');
Config::$cacheEnabled = true; //enable .html cache so that pages don't rerender on each visit

Config::$adminPassword = 'ZettaiRyouiki'; //admin is located at mg.example.com/a/.

//the message that appears during disasters; supports html.
#Config::$maintenanceMessage =
#[
#        'Something bad happened. We\'ll be back soon.',
#        'In the meantime, visit <a href="http://myanimelist.net/clubs.php?cid=30017">our club on MAL</a>.'
#];

//the message that appears at the top; supports html.
#Config::$noticeMessage = 'MALgraph will shut down on June 1st, 2015. <a href="http://myanimelist.net/forum/?topicid=1373476">Read more here.</a>';

Config::$mail = '[email protected]'; //contact e-mail, used in some circumstances. not sure what happens if it's empty.

Config::$enforcedDomain = 'mg.example.com'; //domain for all the links.
Config::$mediaQueueMinWait = 5 * 24 * 60 * 60; //time until given media has to be requeued, in seconds.

//it's probably a good idea to leave these alone.
Config::$usersPerCronRun = 35;
Config::$mediaPerCronRun = 40;
Config::$downloaderMaxParallelJobs = 2;

Config::$downloaderUserAgent = 'malgraph'; //this is de facto API key. You need to get this from Xinil.
Config::$downloaderProxy = 'example.com:81'; //if you get banned, this is how you deal with it.
Config::$cronInterval = 5; //for queue time calculations.

For more options, see base config located at src/Config.php.

Adding queue processor to cron

rr-@burza:/srv/www/malgraph4$ crontab -e

and paste the cron definitions:

*/5 * * * * php -f /srv/www/malgraph4/scripts/cron-queue.php
*/5 * * * * php -f /srv/www/malgraph4/scripts/cron-queue-sizes.php
5 0 * * * php -f /srv/www/malgraph4/scripts/cron-globals.php
5 0 * * * php -f /srv/www/malgraph4/scripts/cron-cache.php

Then run scripts/cron-globals.php for the first time so that you don't get errors on the globals page:

php -f scripts/cron-globals.php

Test your configuration

That concludes this little tutorial. If everything worked, you should be able to visit mg.example.com and see your site.

At first you're going to get "Unknown anime entry". With enough time this should fix on its own thanks to cron that downloads a little bit every time.

If you regularly get errors with the queue cron script, it means you don't have correct API key, or your IP has been banned.