2013-05-20 17:28:29 -04:00
# Discourse Install Guide on Ubuntu
## Install Ubuntu 12.04 with the package groups:
2013-06-05 03:33:20 -04:00
![screenshot of package group selection screen ](https://raw.github.com/discourse/discourse-docimages/master/install/ubuntu%20-%20install%20-%20software%20selection.png )
2013-05-20 17:28:29 -04:00
* Basic ubuntu server
* OpenSSH server
* Mail server
* PostgreSQL database (9.1+)
2013-06-05 03:33:20 -04:00
You may be working on an already-installed or automatically deployed system, in which case you can install them afterwards:
# Run these commands as your normal login (e.g. "michael")
sudo apt-get update & & sudo apt-get -y upgrade
sudo tasksel install openssh-server
sudo tasksel install mail-server
sudo tasksel install postgresql-server
2013-05-20 17:28:29 -04:00
### Configure the mail server:
2013-06-05 03:33:20 -04:00
![screenshot of mail server type configuration screen ](https://raw.github.com/discourse/discourse-docimages/master/install/ubuntu%20-%20install%20-%20mail_1%20system%20type.png )
2013-05-20 17:28:29 -04:00
In our example setup, we're going to configure as a 'Satellite system', forwarding all mail to our egress servers for delivery. You'll probably want to do that unless you're handling mail on the same machine as the Discourse software.
2013-06-05 03:33:20 -04:00
![screenshot of mail name configuration screen ](https://raw.github.com/discourse/discourse-docimages/master/install/ubuntu%20-%20install%20-%20mail_2%20mailname.png )
You probably want to configure your 'mail name' to be the base name of your domain. Note that this does not affect any email sent out by Discourse itself, just unqualified mail generated by systems programs.
![screenshot of relay host configuration screen ](https://raw.github.com/discourse/discourse-docimages/master/install/ubuntu%20-%20install%20-%20mail_3%20relayconfig.png )
If you have a mail server responsible for handling the egress of email from your network, enter it here. Otherwise, leave it blank.
## Additional system packages
2013-05-20 17:28:29 -04:00
Install necessary packages:
# Run these commands as your normal login (e.g. "michael")
sudo apt-get -y install build-essential libssl-dev libyaml-dev git libtool libxslt-dev libxml2-dev redis-server libpq-dev gawk curl pngcrush
2013-05-24 23:25:03 -04:00
## Web Server Option: nginx
2013-05-20 17:28:29 -04:00
2013-05-24 23:25:03 -04:00
At Discourse, we recommend the latest version of nginx (we like the new and
shiny). To install on Ubuntu:
2013-05-20 17:28:29 -04:00
# Run these commands as your normal login (e.g. "michael")
# Remove any existing versions of nginx
sudo apt-get remove '^nginx.*$'
# Add nginx repo to sources.list
cat < < 'EOF' | sudo tee -a /etc/apt/sources.list
deb http://nginx.org/packages/ubuntu/ precise nginx
deb-src http://nginx.org/packages/ubuntu/ precise nginx
EOF
# Add nginx key
curl http://nginx.org/keys/nginx_signing.key | sudo apt-key add -
# install nginx
sudo apt-get update & & sudo apt-get -y install nginx
2013-05-24 23:25:03 -04:00
## Web Server Option: apache2
If you instead want to use apache2 to serve the static pages:
2013-05-22 12:09:51 -04:00
# Run these commands as your normal login (e.g. "michael")
# If you don't have apache2 yet
sudo apt-get install apache2
# Edit your site details in a new apache2 config file
sudo vim /etc/apache2/sites-available/your-domain.com
# Put these info inside and change accordingly
< VirtualHost * :80 >
ServerName your-domain.com
ServerAlias www.your-domain.com
DocumentRoot /srv/www/apps/discourse/public
< Directory / srv / www / apps / discourse / public >
AllowOverride all
Options -MultiViews
< / Directory >
# Custom log file locations
ErrorLog /srv/www/apps/discourse/log/error.log
CustomLog /srv/www/apps/discourse/access.log combined
< / VirtualHost >
# Install the Passenger Phusion gem and run the install
gem install passenger
passenger-install-apache2-module
# Next, we "create" a new apache2 module, passenger
sudo vim /etc/apache2/mods-available/passenger.load
# Inside paste (change the user accodingly)
LoadModule passenger_module /home/YOUR-USER/.rvm/gems/ruby-2.0.0-p0/gems/passenger-4.0.2/libout/apache2/mod_passenger.so
# Now the passenger module configuration
sudo vim /etc/apache2/mods-available/passenger.conf
# Inside, paste (change the user accodingly)
2013-05-22 17:13:57 -04:00
PassengerRoot /home/YOUR-USER/.rvm/gems/ruby-2.0.0-p0/gems/passenger-4.0.2
2013-05-22 12:09:51 -04:00
PassengerDefaultRuby /home/YOUR-USER/.rvm/wrappers/ruby-2.0.0-p0/ruby
# Now activate them all
2013-06-10 16:08:00 -04:00
sudo a2ensite your-domain.com
2013-05-22 12:09:51 -04:00
sudo a2enmod passenger
sudo service apache2 reload
sudo service apache2 restart
2013-05-22 17:13:57 -04:00
If you get any errors starting or reloading apache, please check the paths above - Ruby 2.0 should be there if you are using RVM, but it could get tricky.
2013-05-20 17:28:29 -04:00
## Install rvm and ruby environment
2013-05-24 23:25:03 -04:00
### RVM Option: Systemwide installation
2013-05-20 17:28:29 -04:00
Taken from http://rvm.io/, the commands below installs RVM and users in the 'rvm' group have access to modify state:
# Run these commands as your normal login (e.g. "michael")
\curl -s -S -L https://get.rvm.io | sudo bash -s stable
sudo adduser $USER rvm
newgrp rvm
. /etc/profile.d/rvm.sh
rvm requirements
# Build and install ruby
2013-05-20 23:53:44 -04:00
rvm install 2.0.0
2013-05-20 17:28:29 -04:00
gem install bundler
2013-05-24 23:25:03 -04:00
### RVM Option: Single-user installation
Another sensible option (especially if only one Ruby app is on the machine) is
to install RVM isolated to a user's environment. Further instructions are
below.
2013-05-20 17:28:29 -04:00
## Discourse setup
Create discourse user:
# Run these commands as your normal login (e.g. "michael")
sudo adduser --shell /bin/bash discourse
2013-05-24 23:25:03 -04:00
# If this fails, it's because you're doing the RVM single-user install.
# In that case, you could just not run it if errors make you squirrely
2013-05-20 17:28:29 -04:00
sudo adduser discourse rvm
Give postgres DB rights to the `discourse` user:
# Run these commands as your normal login (e.g. "michael")
sudo -u postgres createuser -s discourse
sudo -u postgres psql -c "alter user discourse password 'todayisagooddaytovi';"
Change to the 'discourse' user:
# Run this command as your normal login (e.g. "michael"), further commands should be run as 'discourse'
sudo su - discourse
2013-05-24 23:25:03 -04:00
Install RVM if doing a single-user RVM installation:
2013-06-05 03:33:20 -04:00
# As 'discourse'
2013-05-24 23:25:03 -04:00
# Install RVM
\curl -s -S -L https://get.rvm.io | bash -s stable
2013-06-05 03:33:20 -04:00
. ~/.bash_profile
# rvm added shell initialization code to ~/.bash_profile,
# move it to ~/.profile instead
cat ~/.bash_profile >> ~/.profile
rm ~/.bash_profile
2013-05-24 23:25:03 -04:00
# Install necessary packages for building ruby
rvm requirements
# If discourse does not have sudo permissions (likely the case), run:
rvm --autolibs=read-fail requirements
# and rvm will tell you which packages you (or your sysadmin) need
# to install before it can proceed. Do that and then resume next:
Continue with discourse installation
# Build and install ruby
rvm install 2.0.0
gem install bundler
2013-05-21 23:02:38 -04:00
# Pull down the latest release
2013-05-20 17:28:29 -04:00
git clone git://github.com/discourse/discourse.git
2013-05-24 23:25:03 -04:00
cd discourse
2013-05-21 23:02:38 -04:00
git checkout latest-release
2013-05-20 17:28:29 -04:00
# Install necessary gems
2013-06-05 03:33:20 -04:00
bundle install --deployment --without test
2013-05-20 23:53:44 -04:00
2013-06-05 03:33:20 -04:00
_If you have errors building the native extensions, ensure you have sufficient free system memory. 1GB with no swap isn't enough, we recommend having 2GB as a minimum._
2013-05-20 17:28:29 -04:00
Configure discourse:
# Run these commands as the discourse user
2013-05-20 23:53:44 -04:00
cd ~/discourse/config
2013-05-24 23:25:03 -04:00
cp database.yml.production-sample database.yml
cp redis.yml.sample redis.yml
cp discourse.pill.sample discourse.pill
cp environments/production.rb.sample environments/production.rb
2013-05-20 17:28:29 -04:00
2013-06-15 01:25:41 -04:00
Edit ~/discourse/config/database.yml
2013-05-20 17:28:29 -04:00
2013-05-29 00:07:26 -04:00
- change production db name if appropriate
2013-05-24 23:25:03 -04:00
- change username/password if appropriate
- set db_id if using multisite
- change `host_names` to the name you'll use to access the discourse site
2013-05-20 17:28:29 -04:00
2013-06-15 01:25:41 -04:00
Edit ~/discourse/config/redis.yml
2013-05-20 17:28:29 -04:00
- no changes if this is the only application using redis, but have a look
2013-06-15 01:25:41 -04:00
Edit ~/discourse/config/discourse.pill
2013-05-20 17:28:29 -04:00
2013-05-29 00:07:26 -04:00
- change application name from 'discourse' if necessary
- Ensure appropriate Bluepill.application line is uncommented
2013-05-20 17:28:29 -04:00
- search for "host to run on" and change to current hostname
- note: clockwork should run on only one host
2013-06-15 01:25:41 -04:00
Edit ~/discourse/config/initializers/secret_token.rb
2013-05-29 00:07:26 -04:00
2013-05-20 17:28:29 -04:00
- uncomment secret_token line
2013-06-15 01:25:41 -04:00
- replace SET_SECRET_HERE with secret output from 'RAILS_ENV=production rake secret' command in discourse directory
2013-05-21 00:12:20 -04:00
- delete the lines below as per instructions in the file
2013-05-20 17:28:29 -04:00
2013-06-15 01:25:41 -04:00
Edit ~/discourse/config/environments/production.rb
2013-05-20 17:28:29 -04:00
- check settings, modify smtp settings if necessary
- See http://meta.discourse.org/t/all-of-my-internal-users-show-as-coming-from-127-0-0-1/6607 if this will serve "internal" users
Initialize the database:
# Run these commands as the discourse user
# The database name here should match the production one in database.yml
createdb discourse_prod
2013-06-06 04:58:39 -04:00
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production rake db:migrate
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production rake assets:precompile
2013-05-20 17:28:29 -04:00
## nginx setup
# Run these commands as your normal login (e.g. "michael")
sudo cp ~discourse/discourse/config/nginx.sample.conf /etc/nginx/conf.d/discourse.conf
2013-06-06 04:58:39 -04:00
Edit /etc/nginx/nginx.conf:
- add: `server_names_hash_bucket_size 64;` to the `http` section
- uncomment: `gzip on;`
2013-05-20 17:28:29 -04:00
Edit /etc/nginx/conf.d/discourse.conf
2013-05-29 00:07:26 -04:00
- edit `server_name` . Example: `server_name cain.discourse.org test.cain.discourse.org;`
- change socket paths if discourse is installed to a different location
- modify root location if discourse is installed to a different location
2013-05-20 17:28:29 -04:00
2013-05-30 19:03:06 -04:00
Reload nginx by running
# Run as your normal login (e.g. "michael")
sudo /etc/init.d/nginx reload
2013-05-20 17:28:29 -04:00
## Bluepill setup
Configure bluepill:
# Run these commands as the discourse user
gem install bluepill
2013-06-05 03:33:20 -04:00
echo 'alias bluepill="NOEXEC_DISABLE=1 bluepill --no-privileged -c ~/.bluepill"' >> ~/.bash_aliases
2013-05-20 23:53:44 -04:00
rvm wrapper $(rvm current) bootup bluepill
rvm wrapper $(rvm current) bootup bundle
2013-05-20 17:28:29 -04:00
Start Discourse:
# Run these commands as the discourse user
2013-06-06 04:58:39 -04:00
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ROOT=~/discourse RAILS_ENV=production NUM_WEBS=4 bluepill --no-privileged -c ~/.bluepill load ~/discourse/config/discourse.pill
2013-05-20 17:28:29 -04:00
Add the bluepill startup to crontab.
# Run these commands as the discourse user
crontab -e
2013-06-15 01:25:41 -04:00
Add the following lines:
2013-05-20 17:28:29 -04:00
2013-06-06 04:58:39 -04:00
@reboot RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ROOT=~/discourse RAILS_ENV=production NUM_WEBS=4 /home/discourse/.rvm/bin/bootup_bluepill --no-privileged -c ~/.bluepill load ~/discourse/config/discourse.pill
2013-06-15 01:25:41 -04:00
0 0 * * * /usr/sbin/logrotate ~/discourse/config/logrotate.conf
2013-05-20 17:28:29 -04:00
2013-06-13 06:15:58 -04:00
Note: in case of RVM system-wide installation RVM will be located in `/usr/local/rvm` directory instead of `/home/discourse/.rvm` , so update the line above respectively.
2013-05-20 17:28:29 -04:00
Congratulations! You've got Discourse installed and running!
2013-05-28 17:46:55 -04:00
2013-06-06 04:58:39 -04:00
Now make yourself an administrator account. Browse to your discourse instance
and create an account by logging in normally, then run the commands:
# Run these commands as the discourse user
cd ~/discourse
RAILS_ENV=production bundle exec rails c
# (in rails console)
> me = User.find_by_username_or_email('myemailaddress@me.com')[0]
> me.admin = true
> me.save
2013-05-28 17:46:55 -04:00
## Updating Discourse
# Run these commands as the discourse user
bluepill stop
# Pull down the latest release
2013-06-05 03:33:20 -04:00
cd ~/discourse
2013-05-28 17:46:55 -04:00
git checkout master
git pull
git fetch --tags
# To run on the latest version instead of bleeding-edge:
#git checkout latest-release
2013-06-05 03:33:20 -04:00
bundle install --without test --deployment
2013-06-06 04:58:39 -04:00
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production rake db:migrate
RUBY_GC_MALLOC_LIMIT=90000000 RAILS_ENV=production rake assets:precompile
2013-05-28 17:46:55 -04:00
bluepill start