Install Question2Answer on an Ubuntu 14.04 VPS

install-question2answer-on-an-ubuntu-14-04-vps-with-nginxIn this tutorial we will show you how to install Question2Answer on an Ubuntu 14.04 VPS with MariaDB, PHP-FPM and Nginx. Question2Answer is an open source question-answer system written in PHP, used by over 14,000 sites in 40 languages. This guide should work on other Linux VPS systems as well but was tested and written for Ubuntu 14.04 VPS.

Login to your VPS via SSH

ssh user@vps

Update the system and install necessary packages

user@vps:~# sudo apt-get update && sudo apt-get -y upgrade
user@vps:~# sudo apt-get install python-software-properties software-properties-common git vim

Install MariaDB 10.0

user@vps:~# sudo apt-key adv --recv-keys --keyserver hkp:// 0xcbcb082a1bb943db
user@vps:~# sudo add-apt-repository 'deb trusty main'
user@vps:~# sudo apt-get install mariadb-server

When the installation is complete, run the following command to secure your installation:


Next, we need to create a database for our Question2Answer installation.

mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE q2a;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON q2a.* TO 'q2auser'@'localhost' IDENTIFIED BY 'q2auser_passwd';
MariaDB [(none)]> \q

Clone the Question2Answer git repository

Create a root directory for your web site and clone the git repository from github using the following commands:

user@vps:~# mkdir -p ~/{public_html,logs}
user@vps:~# git clone ~/

Question2Answer configuration

Rename qa-config-example.php to qa-config.php.

mv qa-config-example.php qa-config.php

Open qa-config.php in your text editor of choice and insert the MySQL details:

vim ~/
        define('QA_MYSQL_HOSTNAME', '');
        define('QA_MYSQL_USERNAME', 'q2auser');
        define('QA_MYSQL_PASSWORD', 'q2auser_passwd');
        define('QA_MYSQL_DATABASE', 'q2a');

Install PHP-FPM and Nginx

Installing PHP and Nginx is pretty easy, just run the following command:

user@myVPS:~# sudo apt-get install nginx php5-common php5-fpm php5-cli php5-mysqlnd

PHP-FPM configuration

Create a new PHP-FPM pool for your user:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer

Now just $43 .99

user@vps:~# sudo tee /etc/php5/fpm/pool.d/$(whoami).conf << EOF
user = $(whoami)  
group = $(whoami)  
listen = /var/run/php5-fpm-$(whoami).sock  
listen.owner = $(whoami) = $(whoami)  
listen.mode = 0666  
pm = ondemand  
pm.max_children = 5  
pm.process_idle_timeout = 10s;  
pm.max_requests = 200  
chdir = /  

Restart PHP-FPM

user@vps:~# sudo service php5-fpm restart

Nginx configuration

Create a new Nginx server block with the following content:

user@vps:~# sudo tee /etc/nginx/sites-available/ << EOF
server {
    listen 80;
    root $HOME/;
    access_log $HOME/;
    error_log $HOME/;
    index index.php;
    location / {
        try_files \$uri \$uri/ /index.php?qa-rewrite=\$uri&\$args;
    location ~* \.(?:ico|css|js|gif|jpe?g|png|ttf|woff)\$ {
        access_log off;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, mustrevalidate, proxy-revalidate";
    location ~ \.php\$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)\$;
        fastcgi_pass unix:/var/run/php5-fpm-$(whoami).sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    location ~ /\.ht {
        deny all;

Activate the server block by creating a symbolic link :

user@vps:~# sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Test the Nginx configuration and restart nginx:

user@vps:~# sudo nginx -t
user@vps:~# sudo service nginx restart

That’s it. You have successfully installed your Question2Answer. For more information about Question2Answer, please refer to the Question2Answer website.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post 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 Comment