How to Install, Configure and Run AskBot with Let’s Encrypt SSL on Ubuntu 16.04

How to Install, Configure and Run AskBot with Let’s Encrypt SSL on Ubuntu 16.04

Spread the love

Askbot is an commercial open source question and answer platform. StackOverflow and YahooAnswer were the inspiration for Askbot, and it has the same features like karma points, up votes and down votes. AskBot launched in 2009 and its used by LibreOffice, Fedora, Ros.org, Sage and other, for their Q&A sections. It written in Python on top of the Django platform, and in this tutorial we’ll show you how to install, configure and run AskBot and deploy with NGINX as a web server, PostgreSQL as a database server, and LetsEncrypt as a free SSL certificates provider on your Ubuntu 16.04 server. Let’s get started with the tutorial, and if you carefully follow the steps bellow you should have AskBot installed on Ubuntu 16.04 in less than 10 minutes.

1. Install Dependencies

The first step is the installation of the required packages. Run the following command to install them:

apt-get install python-pip python-dev python-setuptools python-flup libpng12-dev zlib1g-dev libpng-dev libjpeg-dev build-essential

2. Install and configure PostgreSQL database

Install PostgreSQL from the Ubuntu package repository . You can do that using this command:

sudo apt-get install -y postgresql postgresql-contrib

At this point, in order to configure local user authentication, you need to edit the pg_hba.conf  using some text editor, e.g. nano:

nano /etc/postgresql/9.5/main/pg_hba.conf

If you want to activate password authentication using an MD5 hash then you should replace peer with md5 on this line:

local   all          all                  md5

Save and exit. You should restart the PostgreSQL service in order to enable automatic start at system boot and at the same time to enable these changes.

systemctl restart postgresql
systemctl enable postgresql

Create a new PostgreSQL database and user for Askbot installation. In this tutorial, a new database ‘askbot_db’ with username ‘askbot_user’ and password ‘YOUR_PASSWORD’ was created.

You need to login as the postgres user and access the PostgreSQL shell ‘psql’.

su - postgres
psql

Using the next queries you should create a new database named ‘askbot_db’ and a new user ‘askbot_user’ with password ‘YOUR_PASSWORD’.

create database askbot_db;
create user askbot_user with password 'YOUR_PASSWORD';
grant all privileges on database askbot_db to askbot_user;
\q

Now, you have created a new PostgreSQL database for Askbot installation.

3. Install and Configure Askbot Django App

You have installed all packages which are needed for the installation of Askbot and also you have created the PostgreSQL database. The next thing on your list is to install and configure Askbot.

Now, for the installation of Askbot a new user should be created, because the root user won`t be uses for it. You need to create a new user ‘askbot‘ and to give a new password to that user.

useradd -m -s /bin/bash askbot
passwd askbot

Then, you should add the askbot user to the sudo group by the usermod command.

usermod -a -G sudo askbot

You need to create a Symbolic link to /user/bin

sudo ln -s /usr/local/bin/pip /usr/bin/

You have created a new user has been created. The next step is to update python-pip and install virtualenv package. Using the following pip commands you can install these packages.

pip install --upgrade pip
pip install virtualenv

At this point you should log in as the ‘askbot’ user with the su command, and install Askbot.

su - askbot

Next we would need a new virtual environment for the installation of askbot and we can create it with virtualenv command.

virtualenv example_user

To activate the new virtual environment, use the following command:

source example_user/bin/activate

Next you should install Askbot Django app with pip, including psycopg2 for PostgreSQL database connection.

pip install askbot psycopg2

Now, you need to create a new directory for Askbot Django app – we choose to use the name ‘my_app’. You should install Askbot in the created directory.

mkdir my_app/
cd my_app

You can now install Askbot using the following command:

askbot-setup

You should only give the single ‘.‘ and press ‘Enter’ when asked about the Askbot installation directory. In a similar way, by choosing number ‘1‘ you can choose PostgreSQL for database config. Input the database name ‘askbot_db‘, username ‘askbot_user‘ with password ‘YOUR_PASSWORD‘.

pip install six==1.10

Using this command you will generate Django static files directory.

python manage.py collectstatic

In order to continue type ‘yes’ and press Enter.

With the use of the syncdb option you can generate the PostgreSQL database.

python manage.py syncdb

You should type ‘yes’ and then type your admin user, email, and password when asked to create the admin user.

Now you have installed Askbot on the system under the ‘askbot’ user virtual environment. If you want to test the installation of Askbot you can run the runserver command below.

python manage.py runserver 0.0.0.0:8080

If you desire to check the Askbot’ page you need to open your web browser and type the server IP with port 8080.

4. AskBot with Let’s Encrypt SSL

uWSGI supports applications based on Python, Perl, and Ruby. Here, we are going to use uWSGI with the Nginx web server for our Askbot installation. You can install uWSGI using the pip command below.

sudo pip install uwsgi

The next step is the creation of a new directory for the uWSGI site configuration ‘/etc/uwsgi/sites’.

mkdir -p /etc/uwsgi/sites
cd /etc/uwsgi/sites

You need to add new uWSGI configuration file ‘askbot.ini’ to the ‘sites’ directory and then to edit it with nano.

nano  askbot.ini

There, paste the following uWSGI configuration.

[uwsgi]

# Project directory, Python directory
chdir = /home/askbot/example_user/my_app
home = /home/askbot/example_user/
static-map = /m=/home/askbot/example_user/my_app/static
wsgi-file = /home/askbot/example_user/my_app/django.wsgi

master = true
processes = 5

# Askbot will running under the sock file
socket = /home/askbot/example_user/my_app/askbot.sock
chmod-socket = 664
uid = askbot
gid = www-data
vacuum = true

# uWSGI Log file
logto = /var/log/uwsgi.log

5. Install and configure Nginx to use SSL Certificates with AskBot

You have now installed Askbot and it’s running under the uWSGI sock file ‘askbot.sock’. At this point, we are going to use Nginx web server as a reverse proxy for uWSGI application Askbot.

Using the apt command below you can install Nginx from the repository.

apt-get install nginx

Now, using the pip command below, you can install LetsEncrypt.

pip install letsencrypt-nginx==0.7.0

certbot --nginx -d your_domain.com -d www.your_domain.com

Once you have completed the installation, don`t forget to add new nginx virtual host file ‘askbot.conf’.

nano /etc/nginx/sites-available/askbot.conf

You need to paste the following askbot nginx virtual host configuration.

server {
        listen 80;
        server_name your_domain.com www.your_domain.com;
        location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/home/askbot/example_user/my_app/askbot.sock;
   }
 listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/your_domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your_domain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

}
server {
    if ($host = your_domain.com) {
        return 301 https://$host$request_uri;
    }


        listen 80;
        server_name your_domain.com www.your_domain.com;
    return 404;

}

}

Save and exit.

Next, with the creation of a symlink for ‘askbot’ file to ‘sites-enabled’ directory you will enable the Askbot virtual host file.

ln -s /etc/nginx/sites-available/askbot.conf /etc/nginx/sites-enabled/askbot.conf

Run the following command if you want to test the nginx configuration:

nginx -t

That’s it, you have successfully installed Nginx web server and configured for the Askbot Python Django app.

install, configure and run askbot with lets encrypt ssl on ubuntu 16.04

 

Of course, you don’t have to install, configure and run Askbot on Ubuntu 16.04, if you use one of our outsourced Linux server support services in which case you can simply ask our expert Linux admins to install and configure Askbot on Ubuntu 16.04 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to install, configure and run AskBot with Let’s Encrypt SSL on Ubuntu 16.04, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *