Beginners Guide to Install Discourse on Ubuntu for Development

dev-install

(Arpit Jalan) #1

So you want to set up Discourse on Ubuntu to hack on and develop with?

We’ll assume that you don’t have Ruby/Rails/Postgre/Redis installed on your Ubuntu system. Let’s begin!

Although this guide assumes that you are using Ubuntu, but the set-up instructions will work fine for any Debian based distribution.

(If you want to install Discourse for production use, see our install guide)

Install Discourse Dependencies

As regular user run this script in terminal, to setup Rails development environment:

bash <(wget -qO- https://raw.githubusercontent.com/techAPJ/install-rails/master/linux)

This will install following new packages on your system:

In case you have any of this package pre-installed and don’t want to run entire script, see the script and pick the packages you don’t have currently installed. The script is fine-tuned for Discourse, and includes all the packages required for Discourse installation.

Now that we have installed Discourse dependencies, let’s move on to install Discourse itself.

Clone Discourse

Clone the Discourse repository (or your fork) in ~/discourse folder:

git clone https://github.com/discourse/discourse.git ~/discourse

Setup Database

Create role with the same name as your ubuntu system username:

sudo -u postgres createuser -s techapj

In the above command, I named the role as techapj, this means that my ubuntu system username is techapj. (It is necessary for role name to be same as system username, otherwise migrations will not run)

Bootstrap Discourse

Switch to your Discourse folder:

cd ~/discourse

Install the needed gems

source ~/.bashrc
bundle install

Now that you have successfully configured database connection, run these commands:

bundle exec rake db:create db:migrate
RAILS_ENV=test bundle exec rake db:create db:migrate

Now, try running the specs:

bundle exec rake autospec

Start rails server: (to have it available only on localhost)

bundle exec rails server

or use this command to have it listening on all interfaces and available remotely

bundle exec rails server --binding=0.0.0.0

You should now be able to connect to discourse app on http://localhost:3000 - try it out!

Create New Admin

To create a new admin, run the following command:

RAILS_ENV=development bundle exec rake admin:create

Follow the prompts, and a new admin account will be created.

Configure Mail

Run MailCatcher:

mailcatcher --http-ip 0.0.0.0

Congratulations! You are now the admin of your own Discourse installation!

Happy hacking! And to get started with that, see Beginner’s Guide to Creating Discourse Plugins.


HOWTO: Import MBOX (mailing list) files
Why is my dev server not showing me uploaded images in Topics?
How to add a new language
(OG) #150

I’ve just found out that when you need to make development webserver available not only from localhost, but remotely, you need to start it with:

bundle exec rails server --binding=0.0.0.0

Installation on fresh Ubuntu 14.04.4 LTS according to this guide was flawless, although I’ve got quite few failed rspec tests (31).


(Philip Colmer) #158

Errors are being reported during this step:

df: /home/ubuntu/discourse/public/uploads: No such file or directory

There definitely is a directory there:

df /home/ubuntu/discourse/public/uploads
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/xvda1      32888828 10808136  20639128  35% /

so I’m not sure what - if anything - can be done about that error.

Next:

jhead worker: `jhead` not found; please provide proper binary or disable this worker (--no-jhead argument or `:jhead => false` through options)

Do I need to install the jhead package?

Similarly:

svgo worker: `svgo` not found; please provide proper binary or disable this worker (--no-svgo argument or `:svgo => false` through options)

I’m not sure if there is an Ubuntu package for svgo, so that might need to be installed manually?

convert: unable to open image `/home/ubuntu/discourse/public/uploads/default/9/1234567890123456.png': No such file or directory @ error/blob.c/OpenBlob/2712.

This might be because jhead and svgo are missing, I guess.

Does it matter if autospec has problems? Presumably it is running a series of test?


(Mittineague) #159

Running autospec will run the tests that have been written.

I found this online, so I can’t say as it’s the best way to do it, inside ~/discourse

sudo apt install linuxbrew-wrapper
brew install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush pngquant

But I still get 29 Fails of these two

jhead worker: jhead not found; please provide proper binary or disable this worker (–no-jhead argument or :jhead => false through options)
svgo worker: svgo not found; please provide proper binary or disable this worker (–no-svgo argument or :svgo => false through options)svgo

AFAIK jhead and svgo are used for optimizing images, which is not that important to me in my localhost install.

The errors prickle me a bit, but the good news is that they haven’t gotten in the way of what I’vve been interested in doing yet.


(Philip Colmer) #160

Thanks, @Mittineague, for your feedback.

I find it a little bit concerning that a guide for beginners seems to be resulting in an installation that isn’t passing the tests. As a beginner, I don’t know how important it is that these tests are passed or not. Normally, one might expect it to be really important, otherwise why go to the trouble of writing the test?

Hopefully someone from the team (perhaps @techAPJ as the original author) might be able to suggest edits to the page in order to overcome whatever is causing the tests to fail.


(Arpit Jalan) #161

Yes, from developer’s point of view it matters.

Try installing image libraries via:

sudo apt-get -y install advancecomp gifsicle jpegoptim libjpeg-progs optipng pngcrush pngquant jhead

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get -y install nodejs
sudo npm install -g svgo

If the above commands fixes this issue for you I will add them to original install script.


Install discourse on localhost
(Philip Colmer) #162

Thanks for the prompt reply, @techAPJ.

The installation of jhead is failing:

sudo apt-get -y install advancecomp gifsicle jpegoptim libjpeg-progs optipng pngcrush pngquant jhead
Reading package lists... Done
Building dependency tree
Reading state information... Done
optipng is already the newest version (0.7.6-1).
gifsicle is already the newest version (1.88-1).
jpegoptim is already the newest version (1.4.3-1).
libjpeg-progs is already the newest version (1:9b-1ubuntu1).
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 jhead : Depends: libjpeg-turbo-progs but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

If I try to manually install libjpeg-turbo-progs, this is the output:

sudo apt-get install libjpeg-turbo-progs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  libjpeg9
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
  libjpeg-progs
The following NEW packages will be installed:
  libjpeg-turbo-progs

After that, jhead does install, and I’ve installed the rest of the packages so now I’ll run the tests.


(Philip Colmer) #163

It is looking a lot better, although I’m assuming the red Fs mean there are some failures.

The tests are still running but here is the first displayed problem:

convert: unable to open image `/home/ubuntu/discourse/public/uploads/default/25/1234567890123456.png': No such file or directory @ error/blob.c/OpenBlob/2712.
convert: unable to open file `/home/ubuntu/discourse/public/uploads/default/25/1234567890123456.png' @ error/png.c/ReadPNGImage/3922.
convert: no images defined `/tmp/discourse-thumbnail20170127-29049-19myulm.png' @ error/convert.c/ConvertImageCommand/3210.

There are only green dots leading up to that output.

Another message output during the tests:

WARN: Redis is in a readonly state. Performed a noop

then, after the tests, there were 11 failures that were noted as “expected and not affecting the suite’s status”, followed by:

bundler: failed to load command: rspec (/home/ubuntu/.rbenv/versions/2.3.0/bin/rspec)

#164

Anyone managed to overcome these problems? I have exactly same errors as @Philip_Colmer. I checked the listed paths and the needed folders don’t exist (I only have ‘optimized’ and ‘original’ folders under ‘default’):

convert: unable to open image `/media/files/PBF/discourse/public/uploads/default/17/1234567890123456.png': No such file or directory @ error/blob.c/OpenBlob/2712.
convert: unable to open file `/media/files/PBF/discourse/public/uploads/default/17/1234567890123456.png' @ error/png.c/ReadPNGImage/3922.
convert: no images defined `/tmp/discourse-thumbnail20170203-25274-iazz5i.png' @ error/convert.c/ConvertImageCommand/3210.

What’s more the ‘folder_name’ /media/files/PBF/discourse/public/uploads/default/folder_name
is generated randomly - it’s different number every time i run bundle exec rake autospec.

I can also confirm that the rspec file exists in the searched directory:
bundler: failed to load command: rspec (/home/lukasz/.rbenv/versions/2.3.0/bin/rspec)


(Jafeth Díaz Castañeda) #165

Hello,

I have followed this guide and everything was working fine except the email. When I wanted to sign up a new user, the mail didn’t appear in mailcatcher. I looked at the admin dashboard and noticed a message informing that sidekiq wasn’t running and therefore emails wouldn’t be sent. After that, I ran bundle exec sidekiq and everything worked fine.

I was wondering whether that is a required step or it happened only to me?


(cpradio) #166

Sidekiq is a required step.


#167

This works great.
Only issue I noticed: after following the full install process, redis-server is not launched at startup (you need to run it manually)


(Karl) #172

Thanks for the guide, it has been very helpful!

I just ran through the guide on an Ubuntu 16.04 system and had (broadly speaking) the same errors during rake auto spec as someone in the guide to installing on OSX.

To try and resolve them I installed a number of packages

apt install advancecomp gifsicle jhead jpegoptim optipng pngcrush pngquant

of which advancecomp jhead libjpeg-turbo-progs pngcrush pngquant were missing.

I had to install npm and nodejs-legacy so i could install and run svgo, another thing the tests were after.

then ran rake following the same post
RAILS_ENV=test rake db:drop db:create db:migrate

and then back to following the guide.

bundle exec rake db:migrate db:test:prepare db:seed_fu

and so on

It doesn’t seem to have fixed the spec issues, they seem to go on forever. I do have a discourse install that loads though!


(MorphZan) #173

Hi Guys

When I go to sidekiq it comes as follows:

But when I look in the Dashboard I get this:

Any Clues how to make this right?

EDIT: My Fix lasted all of 2min until i Rebooted and now I get the following:

Also any clues/links to posts on how to update the Development Version would be much appreciated:


(Owen Sullivan) #174

I created a tutorial on how to use Screen to allow a user to run commands after bootstrapping Discourse for development.


(Hosein Naseri) #176

complete newbie here. I run this script and it fails. I’m getting this error

Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) 2 Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) subscribe failed,


Update: I needed to install Redis :slightly_smiling_face:
sudo apt-get install redis-server


(John Prusinski) #182

Hi, I’m a complete newbie at this… it took me quite awhile to work through the steps in this post, updating bundles, etc., but I finally got everything working and entered the final command (bundle exec rails server --binding=0.0.0.0). At that point I get a bunch of output, including the error “Failed to report error: Error connecting to Redis on localhost:6379”. Any ideas what I need to do to get this working?

Thanks!

ps: This is under Ubuntu in VirtualBox on a Macbook…


(Nur) #183

I wonder what’s the username and password for admin on localhost:3000

anyone?


(Gerhard Schlager) #184

There is none until you create a user.

Afterwards you can login with the email and password you used when you created the admin.


(Tarak'ha) #186

Something is up with @techAPJ’s script to install dependencies. I had to manually install bundler; was missing or never installed.