From bf2f22a152b75e142db2ea0a66db7028979071f3 Mon Sep 17 00:00:00 2001
From: Rafael dos Santos Silva <xfalcox@gmail.com>
Date: Wed, 1 Jun 2016 15:42:05 -0300
Subject: [PATCH] Update the guide

---
 docs/DEVELOPER-ADVANCED.md | 169 ++++++++++---------------------------
 1 file changed, 44 insertions(+), 125 deletions(-)

diff --git a/docs/DEVELOPER-ADVANCED.md b/docs/DEVELOPER-ADVANCED.md
index c8e893345a9..102533a692d 100644
--- a/docs/DEVELOPER-ADVANCED.md
+++ b/docs/DEVELOPER-ADVANCED.md
@@ -4,144 +4,63 @@ This guide is aimed at advanced Rails developers who have installed their own Ra
 
 Note: If you are developing on a Mac, you will probably want to look at [these instructions](DEVELOPMENT-OSX-NATIVE.md) as well.
 
-## First Steps
+# Preparing a fresh Ubuntu install
 
-1. Install and configure PostgreSQL 9.3+.
-  1. Run `postgres -V` to see if you already have it.
-  1. Make sure that the server's messages language is English; this is [required](https://github.com/rails/rails/blob/3006c59bc7a50c925f6b744447f1d94533a64241/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L1140) by the ActiveRecord Postgres adapter.
-2. Install and configure Redis 2.8.12+.
-  1. Run `redis-server -v` to see if you already have it.
-3. Install ImageMagick
-4. Install libxml2, libpq-dev, g++, gifsicle, libjpeg-progs and make.
-5. Install Ruby 2.1.3 and Bundler.
-6. Clone the project and bundle.
+To get your Ubuntu 16.04 LTS install up and running to develop Discourse and Discourse plugins follow the commands below. We assume and English install of Ubuntu.
 
-## Before you start Rails
+    # Basics
+    whoami > /tmp/username
+    sudo add-apt-repository ppa:chris-lea/redis-server
+    sudo apt-get -yqq update
+    sudo apt-get -yqq install python-software-properties vim curl expect debconf-utils git-core build-essential zlib1g-dev libssl-dev openssl libcurl4-openssl-dev libreadline6-dev libpcre3 libpcre3-dev imagemagick postgresql postgresql-contrib-9.5 libpq-dev postgresql-server-dev-9.5 redis-server advancecomp gifsicle jhead jpegoptim libjpeg-progs optipng pngcrush pngquant
 
-1. `bundle install`
-2. Start up Redis by running `redis-server`
-3. `bundle exec rake db:create db:migrate db:test:prepare`
-4. Try running the specs: `bundle exec rake autospec`
-5. `bundle exec rails server`
-
-You should now be able to connect to rails on [http://localhost:3000](http://localhost:3000) - try it out! The seed data includes a pinned topic that explains how to get an admin account, so start there! Happy hacking!
+    # Ruby
+    curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
+    \curl -sSL https://get.rvm.io | bash -s stable
+    echo 'gem: --no-document' >> ~/.gemrc
+    rvm install 2.3.1
+    rvm --default use 2.3.1 # If this error out check https://rvm.io/integration/gnome-terminal
+    gem install bundler mailcatcher
 
 
-# Building your own Vagrant VM
-
-Here are the steps we used to create the **[Vagrant Virtual Machine](VAGRANT.md)**. They might be useful if you plan on setting up an environment from scratch on Linux:
-
-
-## Base box
-
-Vagrant version 1.1.2. With this Vagrantfile:
-
-    Vagrant::Config.run do |config|
-      config.vm.box     = 'precise32'
-      config.vm.box_url = 'http://files.vagrantup.com/precise32.box'
-      config.vm.network :hostonly, '192.168.10.200'
-
-      if RUBY_PLATFORM =~ /darwin/
-        config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
-      end
-    end
-
-    vagrant up
-    vagrant ssh
-
-## Some basic setup:
-
-    sudo su -
-    ln -sf /usr/share/zoneinfo/Canada/Eastern /etc/localtime
-    apt-get -yqq update
-    apt-get -yqq install python-software-properties
-    apt-get -yqq install vim curl expect debconf-utils git-core build-essential zlib1g-dev libssl-dev openssl libcurl4-openssl-dev libreadline6-dev libpcre3 libpcre3-dev imagemagick
-
-## Unicode
-
-    echo "export LANGUAGE=en_US.UTF-8" >> /etc/bash.bashrc
-    echo "export LANG=en_US.UTF-8" >> /etc/bash.bashrc
-    echo "export LC_ALL=en_US.UTF-8" >> /etc/bash.bashrc
-    export LANGUAGE=en_US.UTF-8
-    export LANG=en_US.UTF-8
-    export LC_ALL=en_US.UTF-8
-
-    locale-gen en_US.UTF-8
-    dpkg-reconfigure locales
-
-## RVM and Ruby
-
-    apt-get -yqq install libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config curl build-essential git
-
-    su - vagrant -c "sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)"
-    adduser vagrant rvm
-    source /etc/profile.d/rvm.sh
-    su - vagrant -c "rvm pkg install libyaml"
-    su - vagrant -c "rvm install 2.0.0-turbo"
-    su - vagrant -c "rvm use 2.0.0-turbo --default"
-
-    echo "gem: --no-document" >> /etc/gemrc
-    su - vagrant -c "echo 'gem: --no-document' >> ~/.gemrc"
-
-## Postgres
-
-Configure so that the vagrant user doesn't need to provide username and password.
-
-    apt-get -yqq install postgresql postgresql-contrib-9.3 libpq-dev postgresql-server-dev-9.3
-    su - postgres
-    createuser --createdb --superuser -Upostgres vagrant
-    psql -c "ALTER USER vagrant WITH PASSWORD 'password';"
-    psql -c "create database discourse_development owner vagrant encoding 'UTF8' TEMPLATE template0;"
-    psql -c "create database discourse_test        owner vagrant encoding 'UTF8' TEMPLATE template0;"
+    # Postgresql
+    sudo su postgres
+    createuser --createdb --superuser -Upostgres $(cat /tmp/username)
+    psql -c "ALTER USER $(cat /tmp/username) WITH PASSWORD 'password';"
+    psql -c "create database discourse_development owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
+    psql -c "create database discourse_test        owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
     psql -d discourse_development -c "CREATE EXTENSION hstore;"
     psql -d discourse_development -c "CREATE EXTENSION pg_trgm;"
 
+    # Node
+    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
+    # exit the terminal and open it again
+    nvm install 6.2.0
+    nvm alias default 6.2.0
+    npm install -g svgo phantomjs-prebuilt
 
-Edit /etc/postgresql/9.3/main/pg_hba.conf to have this:
 
-    local all all trust
-    host all all 127.0.0.1/32 trust
-    host all all ::1/128 trust
-    host all all 0.0.0.0/0 trust # wide-open
+If everything goes alright, let's clone Discourse and start hacking:
 
-## Redis
+    git clone https://github.com/discourse/discourse.git ~/discourse
+    cd ~/discourse
+    bundle install
+    bundle exec rake db:create db:migrate db:test:prepare
+    bundle exec rake autospec # CTRL + C to stop
+    bundle exec rails server # Open browser on http://localhost:3000 and you should see Discourse
 
-    sudo su -
-    mkdir /tmp/redis_install
-    cd /tmp/redis_install
-    wget http://redis.googlecode.com/files/redis-2.6.7.tar.gz
-    tar xvf redis-2.6.7.tar.gz
-    cd redis-2.6.7
-    make
-    make install
-    cd utils
-    ./install_server.sh
-    # Press enter to accept all the defaults
-    /etc/init.d/redis_6379 start
+Create a test account, and enable it with:
 
-## Sending email (SMTP)
+    bundle exec rails c
+    u = User.find_by_id 1
+    u.activate
+    u.grant_admin!
+    exit
 
-By default, development.rb will attempt to connect locally to send email.
+Discourse does a lot of stuff async, so it's better to run sidekiq even on development mode:
 
-```rb
-config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
-```
+    ruby $(mailcatcher) # open http://localhost:1080 to see the emails, stop with pkill -f mailcatcher
+    bundle exec sidekiq -d -l log/sidekiq.log # open http://localhost:3000/sidekiq to see the queue, stop with pkill -f sidekiq
+    bundle exec rails server
 
-Set up [MailCatcher](https://github.com/sj26/mailcatcher) so the app can intercept
-outbound email and you can verify what is being sent.
-
-Note also that mail is sent asynchronously by Sidekiq, so you'll need to have it running to process jobs. Run it with this command:
-
-```
-bundle exec sidekiq
-```
-
-## Phantomjs
-
-Needed to run javascript tests.
-
-    cd /usr/local/share
-    wget https://phantomjs.googlecode.com/files/phantomjs-1.8.2-linux-i686.tar.bz2
-    tar xvf phantomjs-1.8.2-linux-i686.tar.bz2
-    rm phantomjs-1.8.2-linux-i686.tar.bz2
-    ln -s /usr/local/share/phantomjs-1.8.2-linux-i686/bin/phantomjs /usr/local/bin/phantomjs
+And happy hacking!