How to shrink LVM Logical Volumes


DO NOT do this unless the partition you’re going to shrink is not actively being used.

This means stopping services if necessary.

Check with lsof if files om the mount point of the partition are still in use and stop the responsible services before proceeding!

First we need to check the volume:

umount /var/www
e2fsck -f /dev/mapper/data–fe–02

Then we resize the filesystem to less than 90% of the desired size after

reduction (ie 200 to 100 gb -> resize to 90 GB if possible)
resize2fs /dev/mapper/data–fe–02 15G

Reduce LVM to preferred size
lvreduce -L18G /dev/mapper/data–fe–02
Resize filesystem to LVM size, the -p gives a progress bar
resize2fs -p /dev/mapper/data–fe–02
Remount, check if data is still there, admire your work
mount -a
ls /var/www
df -h

IPtables source and destination NAT to internal FTP

Consider the following scenario:

You have an FTP server in an internal network.

You would like to give access to this FTP server from the internet, but you do not control the network/default gateway.

You have access to a machine with an external IP, that is able to setup a connection to the FTP server.

In this case, you would like to setup the following:

incoming: Internet -> ExternalIP -> InternalIP
outgoing: InternalIP -> ExternalIP -> Internet

You will need to execute the following commands at the external server to set this up:

modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
$IPTABLES -t nat -A PREROUTING -i <external interface> -d <external ip> -p tcp -j DNAT –to-dest <internal ftpserver ip>
$IPTABLES -A FORWARD -p tcp –dport 21 -d <internal ftpserver ip> -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o <internal interface> -d <internal ftpserver ip> -j SNAT –to-source <internal interface ip>

For example:

$IPTABLES -t nat -A PREROUTING -i eth2 -d -p tcp -j DNAT –to-dest
$IPTABLES -A FORWARD -p tcp –dport 21 -d -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o vlan927 -d -j SNAT –to-source

Pay special care to the FORWARD rule: this is done *after* PREROUTING, so the destination IP is DNAT’ed already!

Installing SpotWEB on Ubuntu Server 14.04

This tutorial will show you how to install SpotWEB on Ubuntu Server 14.04.

SpotWEB is used as a Usenet Indexer, and NewzNAB provider.


Install Ubuntu Server, and enable the SSH server during installation.

Switch to the root account with this command:

sudo su

Update the server:

apt-get update
apt-get upgrade

Reboot if needed.

Now let’s install Apache and PHP.

apt-get install apache2 php5 php5-curl php5-gd php5-gmp

Edit these 2 files, to set the correct timezone.

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

Search for the “date.timezone” value in the ini files, and fill out the correct time zone.

 date.timezone = Europe/Brussels

Install MySQL

apt-get install mysql-server mysql-client php5-mysql

Set the MySQL root password


Edit the following file:

nano /etc/apache2/sites-available/000-default.conf

Change this line

DocumentRoot /var/www/html

to this

DocumentRoot /var/www

Restart the Apache server

service apache2 restart

Now let’s login to the MySQL server and create the SpotWEB database.

mysql -u root -p

Enter the MySQL root password, then enter these commands:

CREATE USER 'spotweb'@'localhost' IDENTIFIED BY 'spotweb';
GRANT ALL PRIVILEGES ON spotweb.* TO spotweb @'localhost' IDENTIFIED BY 'spotweb';

Now let’s install GIT to download the SpotWEB files:

apt-get install git

Download SpotWEB in “/var/www/spotweb” and set permissions.

cd /var/www
git clone
cd /var/www/spotweb
git pull
chmod 777 cache

Surf to your spotweb server:


On this page, everything has to be OK, except “DB::pgsql” and “Own settings file”

Fill out the MySQL settings as shown in the screenshot.

If you didn’t modify the MySQL DB script earlier, then Database, Username and Password shoudl all be “spotweb“.


Enter your usenet provider credentials.


Select the SpotWEB type you need. I’m choosing “Shared”, because this allows me to assign API keys to user account later, which we need for the NewzNAB provider.

(I’m not sure this is allowed in Single user mode)

Then choose your admin username.


At the end of the wizard, you will still need to create the DB config file manually.


Edit the config file:

nano /var/www/spotweb/

Paste the contents as shown in the wizard:

$dbsettings['engine'] = 'pdo_mysql';
$dbsettings['host'] = 'localhost';
$dbsettings['dbname'] = 'spotweb';
$dbsettings['user'] = 'spotweb';
$dbsettings['pass'] = 'spotweb';

Now let’s start the first synchronization manually, by using this command:

php /var/www/spotweb/retrieve.php

We’ll configure the cronjob that does the automated synchronization later.

Let’s take a look at the NewzNAB part first, this is very useful, because applications like SickBeard, SickRage, Sonar, CouchPotato, Headphones, Mylar and others, can use it to find content, and send it to SabNZBd.

Create/edit a .htaccess file in the Spotweb folder

cd /var/www/spotweb
nano .htaccess

The file contents should like this:

<IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_URI} !api/
        RewriteRule api/?$ index.php?page=newznabapi [QSA,L]

Edit the file /etc/apache2/sites-available/000-default.conf

nano /etc/apache2/sites-available/000-default.conf

On the bottom, just above </VirtualHost> paste this code.

<Directory /var/www/spotweb/>
        RewriteEngine on
        RewriteCond %{REQUEST_URI} !api/
        RewriteRule ^api/?$ index.php?page=newznabapi [QSA,L]
        Options Indexes FollowSymLinks Multiviews
        AllowOverride None
        Order allow,deny
        allow from all

Now enable mod rewrite, and restart apache.

sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart

To test if NewzNAB is working, browse to this URL:


If you see an XML page now, everything is working fine, close the page.


To get your API api key, click your “user name” in the top right corner, and click “Change user


Here you will see your personal API key.


Let’s go through the other SpotWEB settings now.

Go to “Config –> Change Preferences
Select the “NZB Handling” tab.

Fill out the info for your SabNZBd host, if you want to send NZB’s directly to SabNZBd.


Then go to “Config –> Settings” and open the “Retrieve” tab.

Fill out the retention for your usenet provider.
Enable all check-boxes on the bottom of the page.


You should already have a fully working SpotWEB server now, with some content synchronized.


We still need to create a crontab job, which will automatically synchronize new spots.

crontab -e

Paste this code at the end of the file.

All new spots will be retrieved at 05h01, every day.

Adjust the cron if you want to have it synchonize more often.

1 5 * * * /usr/bin/php /var/www/spotweb/retrieve.php

One more thing before we’re ready.

A lot of spam spots are listed in SpotWEB lately, so let’s create a filter that will remove these spots.

The SpotWEB database comes preconfigured with a blacklist that can remove spam, however this doesn’t seem to work by default.

Login to the MySQL server again.

mysql -p -u root spotweb

Enter your MySQL root password, and then execute these commands:

select value from settings where name="blacklist_url";
select value from settings where name="whitelist_url";

If the results point to the old* URL’s then you need to update your settings, otherwise you don’t need to do anything else .

Enter this to start using the correct URL’s:

update settings set value="" where name="blacklist_url";
 update settings set value="" where name="whitelist_url";

Manually run the retrieve script again, and the blacklist will be applies.

php /var/www/spotweb/retrieve.php

All done.

WordPress: ‘Page not found’ after setting permalinks to ‘post name’

When installing your own WordPress server on a Linux machine, you might want to change the default permalink setting to ‘Post name’.


However, this might result in ‘Page not Found’ errors.

In the screenshot you’ll already see that it can be necessary to create a .htaccess file manually, but this alone doesn’t always resolve the problem.

SSH to your Linux WordPress box, and navigate to the folder where you installed WordPress.

Usually this should be somewhere in ‘/var/www/yourwebsite’ (Same folder where your ‘wp-config.php’ is)

Now create a file called ‘.htaccess’ (Don’t forget the leading . )

Paste this code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Set permissions on the .htaccess file.

chmod 666 .htaccess 
chown www-data:www-data .htaccess

Now we still need to enable mod-rewite, to allow the rewrites to work.

a2enmod rewrite 

Restart the Apache server:

service apache2 restart

Test again, you should be able to access your posts once again.