In 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://keyserver.ubuntu.com:80 0xcbcb082a1bb943db user@vps:~# sudo add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu trusty main' user@vps:~# sudo apt-get install mariadb-server
When the installation is complete, run the following command to secure your installation:
mysql_secure_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)]> FLUSH PRIVILEGES; 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 ~/yourQ2aSite.com/{public_html,logs} user@vps:~# git clone https://github.com/q2a/question2answer.git ~/yourQ2aSite.com/public_html
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 ~/yourQ2aSite.com/public_html/qa-config.php
define('QA_MYSQL_HOSTNAME', '127.0.0.1'); 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:
user@vps:~# sudo tee /etc/php5/fpm/pool.d/$(whoami).conf << EOF [$(whoami)] user = $(whoami) group = $(whoami) listen = /var/run/php5-fpm-$(whoami).sock listen.owner = $(whoami) listen.group = $(whoami) listen.mode = 0666 pm = ondemand pm.max_children = 5 pm.process_idle_timeout = 10s; pm.max_requests = 200 chdir = / EOF
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/yourQ2aSite.com << EOF server { server_name yourQ2aSite.com; listen 80; root $HOME/yourQ2aSite.com/public_html; access_log $HOME/yourQ2aSite.com/logs/access.log; error_log $HOME/yourQ2aSite.com/logs/error.log; 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; } } EOF
Activate the server block by creating a symbolic link :
user@vps:~# sudo ln -s /etc/nginx/sites-available/yourQ2aSite.com /etc/nginx/sites-enabled/yourQ2aSite.com
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.