Can't connect to rails server on local machine - ruby-on-rails

TL;DR I randomly can't connect to a local Rails server and the problem follows me across computers.
I'm working on a website that uses Rails.
I started my work on an Arch VM using VirtualBox. Inside that VM I could start up rails s and connect to the website at 0.0.0.0:3000 no problem. I was using Chrome from inside the VM to connect to the website.
I added one line of code. I saved the file but did NOT commit or stage. Couldn't connect anymore.
Erased the line I and saved again. Still couldn't connect.
Deleted the folder the site was in. Recloned the repo. Reran the setup script (installs things like rvm, node.js, and rails; see end of post). No luck.
Exited the VM, booted up an Ubuntu install, cloned the repo again (this time into an NTFS drive because that's where I have the most space), ran setup again. Nope.
What was weird is that even though the rails server started, I appeared to not have rails on my system.
For some reason, node installed, rvm and rails did not.
Moved to ~, cloned repo yet again, ran setup again. Same deal. Don't have rails. Although again, rails s in the setup script ran but I couldn't connect in the browser.
Installed rvm, installed bundler, ran bundle install --without production staging just like in the script, and ran the rakes. rails s. Still can't connect.
Nmap says I'm accepting connections on port 3000.
So overflowers, any ideas on how a local connectivity problem could follow me across a computer with no changes to the code base? Or how things like rails can install and not install?
Setup script:
#vagrant
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
#Dependencies
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev -y
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev -y
sudo add-apt-repository ppa:chris-lea/node.js -y
sudo apt-get update
sudo apt-get install nodejs -y
#install rvm and ruby
curl -sSL https://get.rvm.io | bash -s stable --ruby
source ~/.rvm/scripts/rvm
echo "" >> ~/.bashrc
echo "# Auto-Generated source for RVM" >> ~/.bashrc
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.0
rvm use 2.0 --default
ruby -v
#Set up repo
ssh-keyscan github.com >> ~/.ssh/known_hosts
gem install bundler
bundle install --without production staging
rake db:create
rake db:migrate
rake db:seed
rails s

You are incorrectly connecting to your rails server.
=> Rails x.x.x application starting in development on http://0.0.0.0:3000
The line above states the ip address the server is listening on.
To connect to the server located in the same machine use
localhost:3000
If your VM is bridged to your LAN and you want to access it from the host computer, first get the adapter ip using ifconfig and then use it like
ADAPTER_IP:3000

well, you should type 127.0.0.1:3000 or localhost:3000 in the browser or terminal.
Listen 0.0.0.0:3000 means listen all IP addresses in the local machine.

Related

How to install rails in Ubuntu 16 OS X?

I am beginner of learning rails. I want to install rails5 in my Linux operating system.
How can I install rails in Ubuntu 16.04 LTS system ?
The first step is to install some dependencies for Ruby.
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs
Install rbenv and ruby:
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
rbenv install 2.4.0
rbenv global 2.4.0
ruby -v
The last step is to install Bundler
gem install bundler
Install nodejs:
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
Install rails now:
gem install rails -v 5.0.1
you'll need to run the following command to make the rails executable available:
rbenv rehash
Now that you've installed Rails, you can run the rails -v command to make sure you have everything installed correctly:
rails -v
# Rails 5.0.1
You should use RVM to install Rails. It's a virtualization system that will allow you to install multiple versions of Ruby, and maintain different sets of libraries (including Rails) for each project you work on. By default, it installs Rails and its libraries (gems) in your user directory. This is both safer (more secure) than system-wide installation, and much more flexible.
You could install Rails via Ubuntu's package manager (sudo apt-get install rails), and install its libraries via the system-wide RubyGems installer (gem), but that's not a best-practice. While Ruby and Rails don't change as often as they did a few years ago, the dev ecosystem still evolves faster than Linux distributions like Ubuntu can keep up with.
These days, everyone developing Rails apps uses either RVM or rbenv to manage user-space installations. There's no compelling reason to prefer RVM or rbenv as you start out, but RVM is more popular.

Rails Passenger and Nginx + GeoIP module

I install as always passanger gem and then:
rvmsudo passenger-install-nginx-module
and I chose auto configuration and
/opt/nginx
folder for nginx.
Now when I wrote
nginx -V
I only see
nginx:command not found
usr/local/bin is empty.
Of course app works but I try to install GeoIP and just can't check what modules nginx have installed.
ANSWER:
Standard auto installation of rvmsudo passenger-nginx-module doesn't load aditional modules.
Looks like something went wrong with the installation process. According to the passenger official docs, to install passenger do this (considering your are using Ubuntu 14.04):
# Install our PGP key and add HTTPS support for APT
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
# Add our APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
# Install Passenger + Nginx
sudo apt-get install -y nginx-extras passenger
If you already have nginx on the system this command will just upgrade Nginx to Phusion's version (with Passenger compiled in).
start it:
sudo service nginx restart
check if its working by running
sudo passenger-config validate-install

Error running 'requirements_debian_update_system ruby-1.9.3-p551',

Problem facing when installing rvm install 1.9.3
in ubuntu 12.04
Please help me
The problem here is that you didn't reboot (or log out) as per the ubuntu RVM instructions so your user is not (yet) part of the rvm group, and thus has no write permissions on the logs directory.
You can fix this by logging out, rebooting or opening a new shell using
sudo su - $USER
That will create a new shell with your user with the correct rights.
You can run following command from terminal and i think it will solve your problem.
N.B: If you don't need rails simply skip command after ruby installation
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm install 2.1.3
rvm use 2.1.3 --default
ruby -v
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
gem install rails
rails -v
For those who may have issues after running the commands shared on every thread out there, try opening ubuntu or the Linux environment you are working with as an administrator.
search for your app (in my case Ubuntu) using the search bar on the bottom-left of your computer's screen.
if you don't see the option "open as administrator" on the right side, then right-click over the app's icon and you should see it then.
Allow the app to make changes on your computer when prompted and then try the installation commands again.
If that didn't work then try the commands shared in this or other posts, but always as administrator.

Deploy Rails project on AWS

How can I deploy my Ruby on Rails project to EC2? I have a postgres database and currently use Heroku but I now need to shift to AWS.
Any help is much appreciated.
Googling it may help ;o)
https://www.google.fr/search?q=deploy+rails+on+EC2
Then you have a very nice railscast that details the steps to do so with the rubber gem.
http://railscasts.com/episodes/347-rubber-and-amazon-ec2/
My preference is the default AWS linux then jump start it with some basic libraries:
sudo yum update
sudo yum groupinstall -y "Development Tools"
sudo yum groupinstall -y "Development Libraries"
sudo yum install -y httpd httpd-devel apr-devel libcurl-devel libxslt-devel libcurl-devel openssl-devel mysql mysql-devel ImageMagick ImageMagick-devel sqlite-devel
\curl -L https://get.rvm.io | bash -s stable --rails
git clone your rails app to your directory
bundle install --without test
Then don't forget to increase your limits (if you do any significant file io)
Add this to the /etc/security/limits.conf
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
Then install passenger or something like this and have it use rvm 1.9.3.

How to configure yaws webserver in the linux terminal?

can someone help me on to write my yaws webserver configuration file in the Linux terminal. when i follow the yaws tutorials i get errors. thanks a lot.
This is how I installed Yaws 1.89 on Ubuntu Server 10.10.
1. Update your Ubuntu system
sudo apt-get update
sudo apt-get upgrade
2. Install the tools you need to compile
sudo apt-get install gcc
sudo apt-get install libpam0g-dev
3. Download, compile and install Yaws 1.89
wget http://yaws.hyber.org/download/yaws-1.89.tar.gz
tar xfz yaws-1.89.tar.gz
cd yaws
./configure && make
sudo make install

Resources