Memcached with Newznab Server

This guide will help you install memcached on your new server (assuming you’ve just followed the Ubuntu 14.04.2 guide).

Note

This assumes you know linux in general, and know how to use CLI.

Guide written by Stifler. Find me on synIRC #newznab

Version 0.1 - Initial Release

Version 0.2 - Added memcache install and confiure;

Step 1: Install Memcached

Memcached is in the Ubuntu repository and is up to date.:

sudo apt-get install php5-memcached memcached php5-dev

Easy!!! You now have memcached. Now it should have automagically started and also restarted your Apache2, but in case:

sudo service memcached start

Step 2: Lets get some monitoring

INSTALL

Lets install phpMemcacheAdmin so we can monitor memcached. It can be found here : http://blog.elijaa.org/

At the time of writing version 1.2.2 was the latest, so in terminal:

cd /tmp
wget http://phpmemcacheadmin.googlecode.com/files/phpMemcachedAdmin-1.2.2-r262.tar.gz
cd /var/www
sudo mkdir phpmemcacheadmin
cd phpmemcacheadmin
sudo tar -zxvf /tmp/phpMemcachedAdmin-1.2.2-r262.tar.gz

Note

replace phpMemcachedAdmin-1.2.2-r262.tar.gz with whatever the current version is.

Serving the page

Time to get apache2 to serve the new webpage.:

sudo nano /etc/apache2/sites-available/phpmemcacheadmin.conf

Now paste this into the file:

<VirtualHost *:12323>
                ServerName   phpmemcacheadmin
                UseCanonicalName Off
                ServerAdmin  "webmaster@example.com"
                DocumentRoot "/var/www/phpmemcacheadmin"
                CustomLog  /var/log/phpmemcacheadmin-access_log common
                ErrorLog   /var/log/phpmemcacheadmin-error_log
</VirtualHost>

Save the file.

Now we need to listen on the port 12323:

sudo nano /etc/apache2/ports.conf

Find the line Listen 80 and add Listen 12323 under it. Then save the file.

Now we have to enable the site:

sudo a2ensite phpmemcacheadmin

Finally, we need to enable the phpmemcacheadmin some write permissions:

cd /var/www/phpmemcacheadmin/
sudo chmod 777 Config

Finally, restart apache so the page is served:

sudo service apache2 restart

Now you should be able to browse to http://yourserver:12323 and see the monitoring page.

Step 3: Memcache extension for PHP

Now we need to install and setup the memcache extension. First we have to install it:

sudo pecl install memcache

That will build the extension and install it in /var/lib/php5

Next we need to enable the extension in php.ini.

Note

There are two php.ini files, edit both of them and make the same changes to both files.

sudo nano /etc/php5/cli/php.ini

and:

sudo nano /etc/php5/apache2/php.ini

Find these are labelled Dynamic Extensions and add the following line:

extension=memcache.so

Save the file. Once you have changed both files, you can now restart apache2.

Note

Stop your screen script(s) first.

sudo service apache2 restart

Now you can restart your screen scripts.

Step 4: Enable Memcached and configuration

Firstly we need to enable newznab to use memcache:

sudo nano /var/www/newznab/www/config.php

Find define('CACHEOPT_METHOD', 'none'); and change it to:

define('CACHEOPT_METHOD', 'memcache');

Save the file and restart apache2:

sudo service apache2 restart

If you need to tweak the settings for memcached, they are located in this file /etc/memcached.conf

Done!!