2013-02-13 00:18:59 +08:00
# Discourse Developer Install Guide (Vagrant)
2013-02-06 03:16:51 +08:00
2013-04-11 06:05:22 +08:00
### If you are on a Mac or PC, please try our [Discourse as Your First Rails App](http://blog.discourse.org/2013/04/discourse-as-your-first-rails-app/) blog post first!
2013-04-11 05:55:14 +08:00
2013-05-24 22:32:45 +08:00
(If you have experience setting up Rails projects, you might want to take a look at our ** [Discourse Advanced Developer Guide ](DEVELOPER-ADVANCED.md )**. It also contains instructions on building your own Vagrant VM.)
2013-02-06 03:16:51 +08:00
2013-02-06 07:08:39 +08:00
The following instructions will automatically download and provision a virtual machine for you to begin hacking
on Discourse with:
2013-02-06 03:16:51 +08:00
### Getting Started
2013-03-24 06:26:17 +08:00
1. Install Git: http://git-scm.com/downloads (or [GitHub for Windows ](http://windows.github.com/ ) if you want a GUI)
2. Install VirtualBox: https://www.virtualbox.org/wiki/Downloads
2013-04-11 05:58:12 +08:00
3. Install Vagrant: http://www.vagrantup.com/ (We require Vagrant 1.1.2+ or later)
2013-03-24 06:26:17 +08:00
4. Open a terminal
2013-04-17 23:26:27 +08:00
5. Clone the project: `git clone https://github.com/discourse/discourse.git`
2013-03-24 06:26:17 +08:00
6. Enter the project directory: `cd discourse`
2013-02-06 03:16:51 +08:00
### Using Vagrant
When you're ready to start working, boot the VM:
```
vagrant up
```
2013-02-08 09:51:54 +08:00
Vagrant will prompt you for your admin password. This is so it can mount your local files inside the VM for an easy workflow.
2013-02-06 03:16:51 +08:00
(The first time you do this, it will take a while as it downloads the VM image and installs it. Go grab a coffee.)
2013-04-30 11:54:51 +08:00
If you would like to download a smaller VM (574MB instead of 935MB), or if you are having **trouble** downloading the VM:
- Download this file: http://www.discourse.org/vms/discourse-0.8.4.box.7z using your favorite web browser/download tool.
- If you don't have 7z available, you can still get the larger image from http://www.discourse.org/vms/discourse-0.8.4.box
- Extract it using 7z: `7z e discourse-0.8.4.box.7z`
2013-03-20 01:39:16 +08:00
- Add it to vagrant: `vagrant box add discourse-0.8.4 /path/to/the/downloaded/discourse-0.8.4.box virtualbox` .
2013-03-03 23:58:45 +08:00
2013-04-30 11:54:51 +08:00
**Note to Linux users**: Your Discourse directory cannot be on an ecryptfs mount or you will receive an error: `exportfs: /home/your/path/to/discourse does not support NFS export`
2013-02-22 23:43:56 +08:00
**Note to OSX/Linux users**: Vagrant will mount your local files via an NFS share. Therefore, make sure that NFS is installed or else you'll receive the error message:
```
Mounting NFS shared folders failed. This is most often caused by the NFS
client software not being installed on the guest machine. Please verify
that the NFS client software is properly installed, and consult any resources
specific to the linux distro you're using for more information on how to
do this.
```
2013-04-22 02:52:23 +08:00
For example, on Ubuntu, you can install NFS support by installing nfs-kernel-server with `apt-get install` .
2013-02-06 03:16:51 +08:00
Once the machine has booted up, you can shell into it by typing:
```
vagrant ssh
```
2013-04-01 22:52:35 +08:00
The discourse code is found in the /vagrant directory in the image.
2013-02-18 05:11:57 +08:00
**Note to Windows users**: You cannot run ```vagrant ssh``` from a cmd prompt; you'll receive the error message:
```
`vagrant ssh` isn't available on the Windows platform. You are still able
2013-03-20 01:39:16 +08:00
to SSH into the virtual machine if you get a Windows SSH client (such as
2013-02-18 05:11:57 +08:00
PuTTY). The authentication information is shown below:
Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Users/Your Name/.vagrant.d/insecure_private_key
```
At this point, you will want to get an SSH client, and use it to connect to your Vagrant VM instead. We recommend
PuTTY:
**[PuTTY Download Link](http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)**
You may use this client to connect to the VM by using ```vagrant/vagrant``` as your username/password, or by [using
PuTTYGen to import the insecure_private_key file](http://jason.sharonandjason.com/key_based_putty_logins_mini_how_to.htm)
(mentioned above) into a PuTTY profile to quickly access your VM.
2013-02-06 03:16:51 +08:00
### Keeping your VM up to date
Now you're in a virtual machine is almost ready to start developing. It's a good idea to perform the following instructions
2013-03-20 01:39:16 +08:00
*every time* you pull from master to ensure your environment is still up to date.
2013-02-06 03:16:51 +08:00
```
2013-04-01 22:52:35 +08:00
cd /vagrant
2013-02-06 03:16:51 +08:00
bundle install
bundle exec rake db:migrate
bundle exec rake db:seed_fu
```
### Starting Rails
2013-04-01 22:52:35 +08:00
Once your VM is up to date, you can start a rails instance using the following command from the /vagrant directory:
2013-02-06 03:16:51 +08:00
```
2013-02-22 06:33:49 +08:00
bundle exec rails s
2013-02-06 03:16:51 +08:00
```
2013-02-19 02:44:11 +08:00
In a few seconds, rails will start serving pages. To access them, open a web browser to [http://localhost:4000 ](http://localhost:4000 ) - if it all worked you should see discourse! Congratulations, you are ready to start working!
2013-02-06 03:16:51 +08:00
2013-02-12 04:49:23 +08:00
You can now edit files on your local file system, using your favorite text editor or IDE. When you reload your web browser, it should have the latest changes.
2013-02-06 03:16:51 +08:00
2013-03-20 01:39:16 +08:00
### Changing the Seed Data
By default, the Vagrant virtual machine comes seeded with test data. You'll have a few topics to play around with
and some user accounts. If you'd like to use the default production seed data instead you can execute the following
commands:
```
vagrant ssh
cd /vagrant
psql discourse_development < pg_dumps / production-image . sql
rake db:migrate
rake db:test:prepare
```
If you change your mind and want to use the test data again, just execute the above but using `pg_dumps/development-image.sql` instead.
2013-02-06 03:16:51 +08:00
### Guard + Rspec
2013-03-25 13:14:19 +08:00
If you're actively working on Discourse, we recommend that you run [Guard ](https://github.com/guard/guard ). It'll automatically run our unit tests over and over, and includes support
2013-02-06 03:16:51 +08:00
for live CSS reloading.
To use it, follow all the above steps. Once rails is running, open a new terminal window or tab, and then do this:
```
vagrant ssh
2013-04-01 22:52:35 +08:00
cd /vagrant
2013-02-10 03:44:49 +08:00
bundle exec rake db:test:prepare
2013-02-06 03:16:51 +08:00
bundle exec guard -p
```
Wait a minute while it runs all our unit tests. Once it has completed, live reloading should start working. Simply save a file locally, wait a couple of seconds and you'll see it change in your browser. No reloading of pages should be necessary for the most part, although if something doesn't update you should refresh to confirm.
2013-02-10 01:59:43 +08:00
### Sending Email
2013-04-01 22:52:35 +08:00
Mail is sent asynchronously by Sidekiq, so you'll need to have sidekiq running to process jobs. Run it with this command in the /vagrant directory:
2013-02-12 00:42:25 +08:00
```
bundle exec sidekiq
```
2013-02-10 02:49:39 +08:00
Mailcatcher is used to avoid the whole issue of actually sending emails: https://github.com/sj26/mailcatcher
2013-02-10 01:59:43 +08:00
To start mailcatcher, run the following command in the vagrant image:
```
2013-04-30 11:54:51 +08:00
gem install mailcatcher & & mailcatcher --http-ip 0.0.0.0
2013-02-10 01:59:43 +08:00
```
2013-02-19 02:44:11 +08:00
Then in a browser, go to [http://localhost:4080 ](http://localhost:4080 )
2013-02-10 01:59:43 +08:00
Sent emails will be received by mailcatcher and shown in its web ui.
2013-02-06 03:16:51 +08:00
### Shutting down the VM
2013-04-30 11:54:51 +08:00
When you're done working on Discourse, you can shut down Vagrant with:
2013-02-06 03:16:51 +08:00
2013-03-20 01:39:16 +08:00
```
2013-02-06 03:16:51 +08:00
vagrant halt
```