Installing Tiny Tiny RSS from scratch
Considering that a couple of times now I've been a proponent of using an RSS reader, I figured it was time I wrote a tutorial on how to install Tiny Tiny RSS, using Nginx as the server and PostgreSQL for the database. While as with any piece of software there are a number of tutorials and guides already out there, I've found that none of them provided a complete instruction set that didn't have me running into and searching for solutions to multiple errors. To that end, this tutorial aims to both provide as complete a set of fool-proof instructions as I can make, both for newbies to self-hosting, and simply as a reference for my future self should I need to do this again.
This set of instructions assumes that you're running a Debian based Linux distro. I've tested this setup on a clean Ubuntu Server 12.04 virtual machine, and the settings are roughly the same as I'm using on my Debian server. It's assumed that you either know how to set up a server already, or are capable of reading a tutorial to do so (If not, then why are you reading this? Go use Feedly). There are some very good tutorials at Digital Ocean and Linode, and I'd recommend either of them for hosting purposes.
Installation
On to the install. While not strictly necessary, the first thing I recommend is to make sure that your server is using the correct time, so install ntp to keep the system clock updated.
sudo apt-get install ntp
For most of the commands in this tutorial you'll need super user privileges, so you can either run them as root (not recommended) or use sudo
like I've used in this tutorial.
You'll also need to edit a bunch of files in a text editor. I've used nano
for this tutorial because it's easier to use and you can just copy the commands straight, but I usually use vim
.
PHP
Unfortunately, despite the fact that PHP sucks (seriously, read the article, even if you disagree it's an interesting read), Tiny Tiny RSS is built with PHP. However, just because a language sucks doesn't mean that programs written in it necessarily have to, and tt-rss is the best of the self-hosted RSS readers. Still, that means you're going to have to install PHP, and get it working nicely with Nginx.
Install PHP 5 and the components necessary to get it playing nicely with everything else.
sudo apt-get install php5 php5-fpm php5-curl php5-pgsql php5-gd php5-mcrypt php5-cli
There's one line in php.ini you'll need to change, which will prevent a possible security issue.
sudo nano /etc/php5/fpm/php.ini
Change this line:
cgi.fix_pathinfo=1
To this:
cgi.fix_pathinfo=0
The other change is to make PHP-FPM listen on a UNIX socket rather than a TCP socket.
sudo nano /etc/php5/fpm/pool.d/www.conf
Change the line:
listen = 127.0.0.1:9000
To:
listen = /var/run/php5-fpm.sock
Finally, restart PHP.
sudo /etc/init.d/php5-fpm restart
Nginx
Now that PHP is configured, you'll want to configure Nginx. There's a very good primer by Martin Fjordvald on the basics of Nginx configuration which you can read to get an understanding of what's going on. If you want to dig deeper for various other settings, the documentation for Nginx is quite thorough.
This tutorial is going to have you build Nginx from source, since the .deb packages are not always up to date. It's really not that much harder than setting it up from a package install anyway.
First, install the packages required to compile the source.
sudo apt-get install gcc make libpcre3-dev openssl libssl-dev
I also prefer to have Nginx use a dedicated system account with no login or password access for a bit of extra security.
sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx
Then download and unpack the latest Nginx version.
wget http://nginx.org/download/nginx-1.5.6.tar.gz
tar -xzvf nginx-1.5.6.tar.gz
cd nginx-1.5.6
The configure command sets the parameters for the build. This is where you can change the default install directory and the different modules that Nginx uses. Nginx doesn't allow you to change modules without rebuilding, so you'll need to select or deselect any modules here. The only module I'll add is the http_ssl module, which will allow you to add SSL to your site later if you wish. I also prefer to just use the default install directory, so I won't change that, but I'll set the user and group Nginx uses to the one I created earlier.
./configure --user=nginx --group=nginx --with-http_ssl_module
Now we can build and install Nginx.
make && sudo make install
Nginx Configuration
Change to the directory you installed Nginx to:
cd /usr/local/nginx
There are various methods people use for controlling the sites on their server. The .deb install uses a sites-enabled
and sites-disabled
style configuration, but since I don't have many sites on my server, I prefer to keep each site configuration file in the conf/ folder, and include each one manually in nginx.conf.
So, for this tutorial, we'll create a ttrss.conf file.
sudo nano conf/ttrss.conf
My ttrss.conf looks something like this (except I have SSL enabled):
# Tiny Tiny RSS Configuration
server {
listen 80;
server_name domainname www.domainname;
root /var/www/ttrss;
index index.php;
error_log /var/log/nginx/ttrss.error.log;
access_log /var/log/nginx/ttrss.access.log;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include fastcgi.conf; # don't use fastcgi_params
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
}
}
A brief primer:
- listen: the port that the server listens for incoming connections on.
- server_name: the FQDN (fully qualified domain name) that the server uses for this connection. I set this to listen on both example.com and www.example.com.
- root: the root directory that the site's files are located at.
- index: the index file that the server directs traffic to. In this case you only need index.php, but can also include index.html or .htm, or any other file you want to use as a homepage.
- error_log: the location of the error log for this site.
- access_log: the location of the access log for this site. The first location block accepts all incoming requests:
- try_files: this just makes the URL search engine friendly. Not really necessary in this case, but it doesn't hurt. The second location block catches all incoming php requests:
-
include fastcgi.conf: this file comes with Nginx and includes all the parameters for using fastcgi. It's almost the same as fastcgi_params, but you'll have issues using fastcgi_params in Ubuntu 12.04, unless you include the line
SCRIPT_FILENAME $document_root$fastcgi_script_name
. - fastcgi_pass: the socket that fastcgi passes requests through.
- fastcgi_index: the index file that fastcgi uses.
Next, you'll need to edit nginx.conf.
sudo nano conf/nginx.conf
The only change that you really need to make to this file is to add the line include ttrss.conf
in the http block, but this is my recommended configuration below.
# Nginx Configuration
user nginx nginx;
worker_processes auto; # optimal value is number of cpu cores
error_log /var/log/nginx/error.log
events {
worker_connections 2048;
}
http {
# Virtual Host Configuration
include ttrss.conf;
# Basic Settings
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
client_header_timeout 20s;
client_body_timeout 20s;
send_timeout 20s;
# Disable Nginx version number in error pages and Server header
server_tokens off;
# Silently block all undefined vhost access
server {
server_name _;
return 444;
}
# Gzip Settings
gzip on;
gzip_disable "msie6";
gzip_comp_level 5;
gzip_min_length 256;
gzip_vary on;
gzip_proxied any;
gzip_types *;
}
Finally, start Nginx.
sudo /usr/local/nginx/sbin/nginx
If you need to make any changes to Nginx after it's been started, just open and change the config files. Then run this command to reload the Nginx with the new configuration.
sudo /usr/local/nginx/sbin/nginx -s reload
Postgres
Tiny Tiny RSS recommends using PostgreSQL over MySQL for the database, as PostgreSQL is slightly faster. For a single user, it probably wouldn't make much difference, depending on how many feeds you have. The instructions for installing PostgreSQL are mostly taken from the Ubuntu community wiki here.
Install PostgreSQL.
sudo apt-get install postgresql
Log in to the postgres command line as user postgres.
sudo -u postgres psql postgres
Change the password for the postgres user. Type in the command below, hit enter, then enter as password. Make sure to save all your passwords in a good password manager somewhere. I recommend KeePass.
\password postgres
While you're still in the postgres command line, create a database and database user for tt-rss. The password must be entered surrounded by single quotes.
postgres=# CREATE USER ttrss WITH PASSWORD 'password';
postgres=# CREATE DATABASE ttrssdb;
postgres=# GRANT ALL PRIVILEGES ON DATABASE ttrssdb to ttrss;
Exit the postgres command line.
\q
From this point, you might be able to get tt-rss to access the database, but I wasn't until I edited a line in the postgresql config to allow access.
sudo nano /etc/postgresql/9.1/main/pg_hba.conf
Add this line to allow tt-rss to use the database:
local all ttrss md5
Now restart PostgreSQL.
sudo service postgresql restart
Tiny Tiny RSS
Finally, it's now time to install Tiny Tiny RSS itself. Yeah, I know it takes a while to get here. I assure you, it's worth it in the end, and you shouldn't have to worry about it much at all once you've got it properly set up. The installation instructions for tt-rss can be be found here, but once again they seem somewhat incomplete.
First, make a directory for tt-rss to be served from. This should be the same as the directory you specified as root in your ttrss.conf file for Nginx.
sudo mkdir -p /var/www/ttrss
You'll need to set the owner of the directory to the user that you're installing and running tt-rss as.
sudo chown -R user:group /var/www/
Now change to the directory above.
cd /var/www
Download and extract the latest version of Tiny Tiny RSS.
wget https://github.com/gothfox/Tiny-Tiny-RSS/archive/1.10.tar.gz
tar -xzvf 1.10.tar.gz
Rename the extracted directory so that it matches the root directory you specified earlier, then open the directory.
mv Tiny-Tiny-RSS-1.10/ ttrss
cd /var/www/ttrss
The following folders need to have their permissions changed to be writable by anyone with an account on the system, or tt-rss won't be able to save files there.
sudo chmod -R 777 cache/images/ cache/js/ cache/export/ cache/upload/ feed-icons/ lock/
Now you should be able to navigate in your browser to the site that you are hosting tt-rss from. This should be the same as the server_name you specified in ttrss.conf. If you installed tt-rss into a sub-folder of the domain, then the address will be http://domainname/ttrss/
. If you got the configuration correct, you should see the Tiny Tiny RSS install page.
The installation page will have a few fields to enter. These will be the credentials for tt-rss to use the database, as well as the full URL that you'll access tt-rss from. Once you've entered the database details, click the 'Test Configuration' button. If there are errors, you'll get a message saying so, and it shouldn't be too hard to figure out what to do from there. If it's good to go, you'll see a text box with a lot of configuration lines. Copy that config data to your clipboard, and then into a config file on your server with:
sudo nano /var/www/ttrss/config.php
Save that file, and reload tt-rss in your browser. You should now be able to login with the default user admin
and password password
. Once you're logged in, change the admin settings in the preferences at top right.
The final required step is to set up automatic updating of your feeds. You can skip this, but you'll have to manually click on each feed to check for updates if you don't. The screen command will permanently run feed updates in the background, defaulting to once every 30 minutes.
screen -d -m php ./update_daemon2.php
Conclusion
You should now have a working installation of Tiny Tiny RSS on your server, accessible from anywhere in the world. If you've used RSS Readers before, you can import your feeds from an OPML file, otherwise, find some good blogs and start adding feeds.