In this guide, we’re going to look at How to Setup Askbot Questions and Answers Framework on Ubuntu 18.04. Askbot is an open source question and answers web forum with a look similar to StackOverflow. Askbot is based on Django framework and most parts are written in Python programming language with some good features like a karma-based system, voting, and content moderation.
Askbot is used by Ask-FedoraProject and Ask-OpenStack projects to enable its users to ask questions and let other members of the community contribute.
In our installation of Askbot on Ubuntu 18.04, we will setup below prerequisites:
- Database server – MySQL/MariaDB/PostgreSQL
- Web Server – Nginx
Step 1: Install Askbot Dependencies
Start by installing all required dependencies, this will be python packages and pip package manager.
Update and upgrade system packages:
sudo apt-get update && sudo apt-get upgrade
Install python dependencies:
sudo apt-get install -y python-dev python-setuptools python-pip libmysqlclient-dev
Step 2: Install and Configure Database
For a database server, we’ll use MariaDB database server. Refer to our guide below for how to install and configure MariaDB database server on Ubuntu 18.04: Install MariaDB 10.3 on Ubuntu 18.04 and CentOS 7
If you’re interested in using MySQL Server, check Installing MySQL Server on CentOS 7 / CentOS 6
Once the database server has been installed, Create a database and associated user for Askbot:
[email protected]:~# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 21 Server version: 10.3.7-MariaDB-1:10.3.7+maria~bionic mariadb.org binary distribution Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE DATABASE askbot_db; Query OK, 1 row affected (0.000 sec) MariaDB [(none)]> create user [email protected] identified by 'Password'; Query OK, 0 rows affected (0.000 sec) MariaDB [(none)]> grant all privileges on askbot_db.* to [email protected]; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.000 sec) MariaDB [(none)]> exit Bye
Step 3: Install and Configure Askbot
Now that we have installed the packages we need to install Askbot, and we have a database ready, let us install Askbot application. We will use Python Virtualenv for this.
Start by creating askbot user:
[email protected]:~# adduser askbot Adding user `askbot' ... Adding new group `askbot' (1000) ... Adding new user `askbot' (1000) with group `askbot' ... Creating home directory `/home/askbot' ... Copying files from `/etc/skel' ... New password: Retype new password: passwd: password updated successfully Changing the user information for askbot Enter the new value, or press ENTER for the default Full Name : Room Number : Work Phone : Home Phone : Other : Is the information correct? [Y/n] y [email protected]:~# id askbot uid=1000(askbot) gid=1000(askbot) groups=1000(askbot)
Add askbot user to sudo group:
$ sudo usermod -aG sudo askbot
$ sudo pip install virtualenv Collecting virtualenv Downloading https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB) 100% |████████████████████████████████| 1.9MB 526kB/s Installing collected packages: virtualenv Successfully installed virtualenv-16.0.0
Create a directory for Askbot content:
# mkdir /srv/askbot # chown askbot:askbot /srv/askbot/ # su - askbot $ cd /srv/askbot/
After installing virtualenv package, create a Virtual environment for askbot:
$ virtualenv venv New python executable in /srv/askbot/venv/bin/python Installing setuptools, pip, wheel...done.
Source the env to start using it:
$ cd venv/ $ [email protected]:/srv/askbot/venv$ source bin/activate (venv) [email protected]:/srv/askbot/venv$
Then install askbot and mysql python module:
$ pip install askbot gunicorn mysqlclient mysql-python
(venv) [email protected]:/srv/askbot/venv$ mkdir askbot-app (venv) [email protected]:/srv/askbot/venv$ cd askbot-app
Run the command
askbot-setup to install askbot.
(venv) [email protected]:/srv/askbot/venv/askbot-app$ askbot-setup Deploying Askbot - Django Q&A forum application Problems installing? -> please email [email protected] To CANCEL - hit Ctr-C at any time Enter directory path (absolute or relative) to deploy askbot. To choose current directory - enter "." > . Please select database engine: 1 - for postgresql, 2 - for sqlite, 3 - for mysql, 4 - oracle type 1/2/3/4: 3 Please enter database name (required) > askbot_db Please enter database user (required) > askbot Please enter database password (required) > Password Copying files: * __init__.py * manage.py * urls.py * django.wsgi Creating settings file settings file created copying directories: * doc * cron * upfiles Done. Please find further instructions at http://askbot.org/doc/
Generate static files to AskBot installation directory:
$ python manage.py collectstatic
If you get an error like “TypeError: Error when calling the metaclass bases“, there is a fix for it. You need to install six version 1.10.0. Uninstall the latest version and install v1.10.0
(venv) [email protected]:/srv/askbot/askbot-app$ pip uninstall six (venv) [email protected]:/srv/askbot/askbot-app$ pip install six==1.10.0
When done, generate static files to AskBot installation directory:
$ python manage.py collectstatic
Type ‘yes‘ and press Enter to continue to finish generation of files.
(venv) [email protected]:/srv/askbot/askbot-app$ python manage.py makemigrations WARNING!!! You are using a 'locmem' (local memory) caching backend, which is OK for a low volume site running on a single-process server. For a multi-process configuration it is neccessary to have a production cache system, such as redis or memcached. With local memory caching and multi-process setup you might intermittently see outdated content on your site. System check identified some issues: WARNINGS: django_authopenid.UserPasswordQueue.user: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField. HINT: ForeignKey(unique=True) is usually better served by a OneToOneField. group_messaging.SenderList.recipient: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField. HINT: ForeignKey(unique=True) is usually better served by a OneToOneField. Migrations for 'askbot': 0013_auto_20180630_1518.py: - Change Meta options on activity - Change Meta options on award - Change Meta options on badgedata - Change Meta options on favoritequestion - Change Meta options on postflagreason - Change Meta options on postrevision - Change Meta options on replyaddress - Change Meta options on repute - Change Meta options on threadtogroup - Change Meta options on vote - Alter field frequency on emailfeedsetting - Alter field primary_language on userprofile
Generate the MySQL database with the option
(venv) [email protected]:/srv/askbot/askbot-app$ python manage.py migrate
You can also use:
$ python manage.py syncdb ... Synchronizing apps without migrations: Creating tables... Running deferred SQL... Installing custom SQL... Running migrations: No migrations to apply. You have installed Django's auth system, and don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (leave blank to use 'askbot'): askbot Email address: [email protected] Password: Password (again): Superuser created successfully.
When the script asks you if you want to create a superuser, answer yes if you want to create one. By default Askbot sets admin status(superuser) for the first user created automatically but also supports this form.
Test Askbot installation using:
(venv):/srv/askbot/askbot-app$ python manage.py runserver 0.0.0.0:8080
Access your server IP and port 8080. If everything is okay, you should get to its dashboard below:
Step 5: Install and Configure uWSGI & Nginx
Install uWSGI from apt:
$ sudo apt-get install uwsgi
Create uwsgi configuration file for Askbot:
$ sudo vim /etc/uwsgi/apps-enabled/askbot.ini
Modify the file accordingly then save it.
$ sudo apt-get install nginx
Restart uwsgi service with
www-data as socket file owner:
$ sudo systemctl restart uwsgi
Install certbot for generating Letsencrypt SSL Certificate:
# wget https://dl.eff.org/certbot-auto -P /usr/local/bin # chmod a+x /usr/local/bin/certbot-auto
Generate Letsencrypt SSL certificate:
# systemctl stop nginx # export DOMAIN='ask.computingforgeeks.com' # export EMAIL="[email protected]" # certbot-auto certonly --standalone -d $DOMAIN \ --preferred-challenges http --agree-tos -n -m $EMAIL \ --keep-until-expiring
If successful, certbot will give you a successful message:
Create Nginx configuration file:
$ sudo vim /etc/nginx/conf.d/askbot.conf
Ensure you replace variables with your valid values then save the file.
Confirm that the syntax is okay:
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart that both
nginx services after making the change.
$ sudo systemctl restart uwsgi nginx