Created
August 20, 2014 08:31
-
-
Save samgooi4189/416d20bbb9bbfd9b1070 to your computer and use it in GitHub Desktop.
Setting up Nginx with Passenger with Rails 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Taken from: http://alexbachuk.com/launch-rails-4-application-with-passenger-and-nginx/ | |
ssh [email protected] SSH as root, using IP address and password you get by email | |
adduser alex Create new username, because using root is not recommended. | |
visudo Open sudo config file and add admin privileges to newly created user. | |
alex ALL=(ALL) ALL) add this and ctrl+x to save ‘y’ and enter to overwrite | |
sudo apt-get update update system packages | |
curl -L get.rvm.io | bash -s stable install ruby version manager | |
source ~/.rvm/scripts/rvm load RVM | |
rvm requirements install all RVM dependencies | |
rvm install 2.0.0 install ruby version, in this case 2 | |
rvm use 2.0.0 load installed ruby version as default | |
rvm rubygems current install rubygems | |
gem install rails install latest rails, in this case Rails 4 | |
gem install passenger install latest passenger | |
sudo apt-get install libcurl4-openssl-dev install openssl required by nginx | |
rvmsudo passenger-install-nginx-module select all default options. | |
sudo apt-get install nodejs install Node.js | |
sudo apt-get install npm install node package manager | |
I tried to update node through npm – even after success node version was the same… | |
Make nginx command availablewget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh | |
sudo mv init-deb.sh /etc/init.d/nginx | |
sudo chmod +x /etc/init.d/nginx | |
sudo /usr/sbin/update-rc.d -f nginx defaultsafter that you can control nginx with | |
sudo /etc/init.d/nginx stop | |
sudo /etc/init.d/nginx start | |
sudo /etc/init.d/nginx restart | |
sudo nano /opt/nginx/conf/nginx.conf edit nginx configurations | |
server_name – your IP or domain name, root – location of rails app public folderserver { | |
listen 80; | |
server_name example.com; | |
passenger_enabled on; | |
root /var/www/my_awesome_rails_app/public; | |
} | |
Don’t forget to comment out “location / { index.html }” line in config file | |
sudo /etc/init.d/nginx start open IP or domain in browser and see welcome message | |
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql install mysql server | |
sudo mysql_install_db and then sudo /usr/bin/mysql_secure_installation | |
mysql -u root -p login to mysql shell with password you just set | |
while in mysql shell create new database and add this to database.yml production | |
CREATE DATABASE database name; | |
CREATE USER 'alex'@'localhost' IDENTIFIED BY 'set_your_password_here'; | |
GRANT ALL PRIVILEGES ON your_database.* TO 'alex'@'localhost' WITH GRANT OPTION; | |
exit; | |
sudo apt-get install git-core install git | |
sudo apt-get install libmysql-ruby libmysqlclient-dev install mysql adapter for rails | |
bundle install CD to your rails app and install all dependencies | |
rake db:migrate RAILS_ENV=production run all migrations in production mode | |
RAILS_ENV=production bundle exec rake assets:precompile precompile all assets | |
if you see permission error, run sudo chown -R alex:www-data public to gain ownership over the directory | |
sudo /etc/init.d/nginx start restart nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment