Skip to content

Setup Web Server on Ubuntu

Minjie Zha edited this page Oct 14, 2013 · 19 revisions

This wiki describes the steps about how to setup and configure the SearchPocket web server on a Ubuntu server.

Add a normal user

  1. Create a normal user.
# adduser mzha --home /home/mzha --shell /bin/bash
  1. Add the user to sudoers.
# adduser mzha sudo

MySQL database

  1. Install MySQL.
$ sudo apt-get install mysql-server
  1. Start MySQL server at boot time:
$ sudo update-rc.d mysql defaults

To remove it:

$ sudo update-rc.d mysql remove
  1. Set encoding to UTF-8 in /etc/mysql/my.conf.
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
  1. Restart MySQL and login to it. Make sure the encodings are correct by running:
mysql> show variables like 'char%';

and

mysql> show variables like 'collation%';

Sphinx search engine

  1. Install compilers and other build tools.
$ sudo apt-get install build-essential
  1. Install MySQL development libs.
$ sudo apt-get install libmysqlclient-dev
  1. Downlaod the latest sphinx release.
$ wget http://sphinxsearch.com/files/sphinx-2.1.2-release.tar.gz
  1. Extract the file, go into its folder, and run the following commands to build and install sphinx:
$ ./configure --with-mysql
$ make
$ sudo make install
  1. Follow Quick Sphinx usage tour to make sure it is correctly installed.

Ruby

  1. Run the following commands to install ruby 2.0.0 in Ubuntu:
$ sudo apt-get update
$ sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
$ cd /tmp
$ wget http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
$ tar -xvzf ruby-2.0.0-p247.tar.gz
$ cd ruby-2.0.0-p247/
$ ./configure --prefix=/usr/local
$ make
$ make install
  1. Install bundler.
$ sudo gem install bundler

Git

  1. Install Git:
$ sudo apt-get install git

SearchPocket project

  1. Clone search_pocket project from github.
$ git clone https://github.com/magic003/search_pocket.git
  1. Go to search_pocket and install the dependencies.
$ sudo bundle
  1. Create database/user for both development and production environments.
$ mysql -uroot -p
mysql> create database spdev; 
mysql> grant all on spdev.* to 'spdev'@'localhost' identified by '<password>';
  1. Change configurations in config/config.ym.

  2. Change configurations in config/sphinx.conf.

  3. Run sequel migration to setup databases.

$ sequel -m db/migrations mysql2://spdev:<password>@localhost/spdev
  1. Start application in development mode, to make sure it is working.
$ ruby search_pocket_app.rb

Nginx

  1. Install nginx and start it.
$ sudo apt-get install nginx
$ sudo /etc/init.d/nginx start
  1. Create nginx user and web group.
$ sudo useradd -s /sbin/nologin -r nginx
$ sudo groupadd web
$ sudo usermod -a -G web nginx
$ sudo usermod -a -G web mzha
  1. Create /var/www.
$ sudo mkdir /var/www
$ sudo chgrp -R web /var/www # set /var/www owner group to "web"
$ sudo chmod -R 775 /var/www # group write permission
  1. Edit /etc/nginx/nginx.conf and /etc/nginx/sites-enabled/default.
user nginx web;
worker_processes 1;
root: '/var/www';

Unicorn

  1. Install unicorn.
$ sudo gem install unicorn
  1. Go to /var/www/search_pocket, get unicorn conf and change it.
$ curl -o config/unicorn.rb https://raw.github.com/defunkt/unicorn/master/examples/unicorn.conf.rb
  1. Start unicorn.
$ unicorn -c config/unicorn.rb -E development -D
  1. Add sp to /etc/nginx/sites-enabled.

  2. Restart nginx.

$ sudo /etc/init.d/nginx restart

Refer to:

Clone this wiki locally