Skip to content

Instantly share code, notes, and snippets.

@wzul
Last active August 21, 2022 05:01
Show Gist options
  • Save wzul/8a66913781b9591f149cc33a7f643248 to your computer and use it in GitHub Desktop.
Save wzul/8a66913781b9591f149cc33a7f643248 to your computer and use it in GitHub Desktop.
Using Vagrant with Ruby on Rails

Vagrant X Ruby On Rails

I'm the bigfan of gorails.com website and I'm using for the past 5 years. It helps me to setup Ruby on Rails locally either on Windows or Ubuntu.

For Vagrant, I'm following this article to setup it with Ruby on Rails: https://gorails.com/guides/using-vagrant-for-rails-development

Issue

There is multiple when following those article. Hence, I decided to configure it manually where Vagrant only works as ruby interpreter and PostgreSQL installed on the host operating system.

Vagrantfile base

The base can created with vagrant init execution.

Using Postgres installed in host Operating System

Just point to IP Address where usually displayed upon first vagrant ssh access. Or we may execute as follows. Usually it is: 10.0.2.2:

$ ip r

Using for PHP development

Sometimes I occasionally do some PHP development. Hence, I want PHP too. In Vagrantfile

config.vm.provision "shell", inline: <<-SHELL
  apt-get update
  apt-get install -y apache2 php libapache2-mod-php php-mysql php-pgsql
SHELL

Starting Rails server on Vagrant

I need to bind the address to 0.0.0.0 and set port forwarding in Vagrantfile.

Binding IP for Rails Server

$ rails server -b 0.0.0.0

Set port forwarding in Vagrantfile

config.vm.network "forwarded_port", guest: 3000, host: 8081

Terminal for Windows 11

I'm using Windows 11 and so far I'm happy with new Terminal provided by Windows. However, I'm interested in Cmder too.

Mounting file from Host OS to Guest OS (Vagrant)

I define the synched folder in Vagrantfile:

config.vm.synced_folder "/var/www/sendiri.com", "/var/www/html/a"

Vagrant OS Choice

I'm using ubuntu/jammy64.

Vagrant Plugins

I'm using plugin to allow larger size of disk instead of default 40GB

vagrant plugin install vagrant-disksize
@wzul
Copy link
Author

wzul commented Aug 20, 2022

Somehow chef didn't work for me. Hence, I'm skipping chef at the moment

@wzul
Copy link
Author

wzul commented Aug 21, 2022

This gist ignored~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment