Server Setup - quattro004/scratches GitHub Wiki
Note: this is based on Ubuntu Server 12.10
- When installing Ubuntu select all of the defaults. When asked to enter a user use 'deploy' as this guide will assume that user name during configuration. When presented with the features to use select SSH and Mail Server. At some point I'd like to provide an unattended installation but that's down the road.
- Login to the server, I typically use ssh from another computer but you can login to the terminal directly if desirable.
- Ensure all of the packages are up to date:
sudo apt-get update
- Install Rmagick Prerequisites:
sudo apt-get install imagemagick
sudo apt-get install libmagickwand-dev
- Install RVM
\curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled
Note: this installs Ruby and Rails as well. - Install NodeJS
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get -y update
sudo apt-get -y install nodejs
- Install MySQL
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
Follow the instructions presented.- Update the my.cnf file to set max_allowed_packet = 1048576000
- Add the deployment user to the mysql database by entering the following commands:
-
mysql -u root -p
Enter the root password when prompted. -
create user 'deploy'@'localhost' identified by 'pass';
Replace 'pass' with your password. GRANT ALL ON *.* TO 'deploy'@'localhost';
FLUSH PRIVILEGES;
exit
-
- Install Phusion Passenger and nginx:
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:brightbox/passenger-nginx
gem install passenger
-
rvmsudo passenger-install-nginx-module
Follow the instructions presented, select the recommended option #1. Leave the default prefix directory [/opt/nginx].
- Grab an init script from Linode’s website and install it. Necessary when installing from source.
wget -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 defaults
- Once that’s done, you can start and stop nginx like so:
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start
- Configure nginx:
sudo nano /opt/nginx/conf/nginx.conf
- Change the commented out line that says '#user nobody;' to 'user deploy staff;'
- Uncomment the first error_log entry => error_log logs/error.log; if you wish to log errors, recommended.
- Replace the server section with the following:
- Change server_name to use your IP (if configuring for a LAN) or your website name (website.com for example)
-
server { listen 80; server_name recipieces.com; root /home/deploy/scratches/public; passenger_enabled on; rails_env production; #access_log logs/host.access.log main;
- Increase the default client_max_body_size 1000M; add that to the http section.
- Restart nginx
- Git the code
git clone git://github.com/quattro004/scratches.git
- Update the config/database.yml file to include your production database settings, I remove the test and development settings. Also remove the cucumber information at the bottom.
cd scratches
nano config/database.yml
- Run
bundle install
from the scratches directory to setup the application. - Edit recreate_database.sh for production:
nano recreate_database.sh
rake db:reset RAILS_ENV=production rake db:seed RAILS_ENV=production
- Recreate the database with the shell script included with the application source:
sh recreate_database.sh
- Precompile application assets:
bundle exec rake assets:precompile
- Restart your application without restarting nginx at any time merely by creating a file named tmp/restart.txt:
touch tmp/restart.txt
- Setup complete you should now be able to browse to the application. Enjoy and remember 'ya ain't livin if you ain't eatin good!'.
- Note: you have to signup to create the first user, I typically login to the server and update that user to be an admin via mysql.