Skip to content

Instantly share code, notes, and snippets.

@stevenyap
Created November 21, 2013 02:04
Show Gist options
  • Save stevenyap/7574900 to your computer and use it in GitHub Desktop.
Save stevenyap/7574900 to your computer and use it in GitHub Desktop.

Revisions

  1. stevenyap revised this gist Jun 6, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -111,7 +111,7 @@ mkdir -p ${deploy_to}/{releases,shared}
    # so that later deployment will not face bundling issues
    # create a new rails app and copy your app Gemfile to be bundled over
    # You should make sure bundle install works for your Gemfile
    rvm gemset use glabal # for root purposes only
    rvm gemset use global # for root purposes only
    bundle install

    # Or to install gems in your gemset
  2. stevenyap revised this gist Feb 18, 2014. 1 changed file with 32 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -174,3 +174,35 @@ ssh localhost
    # Test: accept host authenticity for git
    git ls-remote ssh://user@domain/~/git/depot.git master
    ```

    ## Access SSH via Public Key
    - This will skip the step of entering password everytime you push into the server

    ```sh
    ssh-keygen -t rsa -C "[email protected]"
    # go with the default file storage (~/.ssh/id_rsa.pub) and enter a good passphrase
    ```

    - Send your id_rsa.pub to the server

    ```sh
    # Make sure .ssh directory exists in the server
    scp ~/.ssh/id_rsa.pub root@localhost:~/.ssh/id_rsa.pub

    # or send with port 2222 if you are using VirtualBox
    scp -P 2222 ~/.ssh/id_rsa.pub root@localhost:~/.ssh/id_rsa.pub
    ```

    - Next, SSH into the server and run the following command:

    ```sh
    cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

    # Need to do this for CentOS
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys

    restorecon -Rv ~/.ssh
    ```

    - That's it!
  3. stevenyap revised this gist Feb 18, 2014. 1 changed file with 96 additions and 0 deletions.
    96 changes: 96 additions & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -78,3 +78,99 @@ chcon -R -h -t httpd_sys_content_t /path-to-passenger-root
    # Ensure your rvm gemset use default before you do passenger-install-apache2-module
    ```

    ## Pre-deployment
    - CentOS 6
    - SSH Access (You should not be using root)
    - depot is the assumed name of the project in this guide. Please change it to your own project name.
    - Server is installed with Apache/Passenger/Bundler/RVM.

    ```sh
    # Setup a user for the access (instead of root)
    adduser deploy
    passwd -l deploy
    # This locks the password of deploy.
    # Use public key to access SSH.
    # Read section Access SSH via Public Key below

    # add t rvm group so that bundling can work for capistrano
    usermod -a -G rvm deploy

    # set directory for the app
    deploy_to=/var/www/depot/staging
    mkdir -p ${deploy_to}
    chown deploy:deploy ${deploy_to}
    umask 0002
    chmod g+s ${deploy_to}
    mkdir -p ${deploy_to}/{releases,shared}

    # Remember to setup your database user/password/DB
    # See Postgres.md

    # Prebundling
    # You should install all the gems necessary (in global gemset) for your app using your Gemfile
    # so that later deployment will not face bundling issues
    # create a new rails app and copy your app Gemfile to be bundled over
    # You should make sure bundle install works for your Gemfile
    rvm gemset use glabal # for root purposes only
    bundle install

    # Or to install gems in your gemset
    # Use your user (not root) to do the below:
    rvm gemset create <gemset>
    rvm gemset use <gemset>
    bundle install
    ```

    ## Apache Config
    - Create a file at `sudo vi /etc/httpd/conf.d/localhost.conf`
    ```sh
    <VirtualHost *:80>
    ServerName localhost

    # Note that current is the folder created by Capistrano
    # It is created as a sym-link to /releases which contains the latest codes
    DocumentRoot /var/www/depot/staging/current/public

    # Set the rails environment
    RailsEnv development

    <Directory /var/www/depot/staging/current/public>
    # This relaxes Apache security settings.
    AllowOverride all
    # MultiViews must be turned off.
    Options -MultiViews
    Order Allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
    ```

    ## Setup Git on Server
    - This setups the git server on the remote server
    - Developer will push to this folder (~/git/depot.git) and Capistrano will pull from this folder and deploy it

    ```sh
    mkdir -p ~/git/depot.git
    cd ~/git/depot.git
    git --bare init
    ```

    Next, we need to setup the SSH for Capistrano to access the Git:

    ```sh
    test -e ~/.ssh/id_dsa.pub || ssh-keygen -t dsa
    cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

    # Need to do this for CentOS
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    restorecon -Rv ~/.ssh

    # Accepting host authenticity for user
    # Test it (you need to accept the host authenticity):
    ssh localhost
    # if you did not see any prompt for password, it is done!

    # Test: accept host authenticity for git
    git ls-remote ssh://user@domain/~/git/depot.git master
    ```
  4. stevenyap revised this gist Dec 18, 2013. 1 changed file with 0 additions and 19 deletions.
    19 changes: 0 additions & 19 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -55,25 +55,6 @@ service httpd restart

    # Install postgres - Please follow Postgres.md

    # Setup a user for the access (instead of root)
    adduser deploy
    passwd -l deploy

    # add t rvm group so that bundling can work for capistrano
    usermod -a -G rvm deploy

    # set directory for the app
    deploy_to=/var/www/depot/staging
    mkdir -p ${deploy_to}
    chown deploy:deploy ${deploy_to}
    umask 0002
    chmod g+s ${deploy_to}
    mkdir -p ${deploy_to}/{releases,shared}

    # Prebundling
    # You should install all the gems necessary (in global gemset) for your app using your Gemfile
    # so that later deployment will not face bundling issues

    # All done! Now to deployment!!
    ```

  5. stevenyap revised this gist Dec 18, 2013. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -53,12 +53,7 @@ passenger-install-apache2-module
    # Restart the service
    service httpd restart

    # Install postgres
    yum install postgresql postgresql-server postgresql-contrib postgresql-devel
    service postgresql initdb
    service postgresql start
    chkconfig postgresql on
    # Look at Postgres.md to setup users/database
    # Install postgres - Please follow Postgres.md

    # Setup a user for the access (instead of root)
    adduser deploy
  6. stevenyap revised this gist Dec 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ gem install rails --version 4.0.0 --no-ri --no-rdoc
    rails -v

    # Install Apache
    yum install httpd httpd-devel
    yum -y install httpd httpd-devel

    # Allow port 80 to server webpage
    iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
  7. stevenyap revised this gist Dec 18, 2013. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -26,8 +26,6 @@ gem install bundler
    gem install rails --version 4.0.0 --no-ri --no-rdoc

    # You can verify rails successful installation
    # You should install all the gems necessary (in global gemset) for your app using your Gemfile
    # so that later deployment will not face bundling issues
    rails -v

    # Install Apache
    @@ -77,6 +75,10 @@ umask 0002
    chmod g+s ${deploy_to}
    mkdir -p ${deploy_to}/{releases,shared}

    # Prebundling
    # You should install all the gems necessary (in global gemset) for your app using your Gemfile
    # so that later deployment will not face bundling issues

    # All done! Now to deployment!!
    ```

  8. stevenyap revised this gist Dec 18, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@ yum clean all
    yum -y update
    yum -y install curl-devel git sqlite-devel libxml2-devel
    yum -y install libxml2 libxml2-devel libxslt libxslt-devel
    yum -y install gcc-c++ readline-devel libyaml-devel libffi-devel openssl-devel libtool bison
    yum -y install nodejs # If this does not work, do it again after you installed RVM

    # install RVM
  9. stevenyap revised this gist Dec 18, 2013. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -64,7 +64,17 @@ chkconfig postgresql on
    # Setup a user for the access (instead of root)
    adduser deploy
    passwd -l deploy
    usermod -a -G rvm deploy # add t rvm group so that bundling can work for capistrano

    # add t rvm group so that bundling can work for capistrano
    usermod -a -G rvm deploy

    # set directory for the app
    deploy_to=/var/www/depot/staging
    mkdir -p ${deploy_to}
    chown deploy:deploy ${deploy_to}
    umask 0002
    chmod g+s ${deploy_to}
    mkdir -p ${deploy_to}/{releases,shared}

    # All done! Now to deployment!!
    ```
  10. stevenyap revised this gist Dec 18, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -64,6 +64,7 @@ chkconfig postgresql on
    # Setup a user for the access (instead of root)
    adduser deploy
    passwd -l deploy
    usermod -a -G rvm deploy # add t rvm group so that bundling can work for capistrano

    # All done! Now to deployment!!
    ```
  11. stevenyap revised this gist Dec 18, 2013. No changes.
  12. stevenyap revised this gist Dec 18, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -61,6 +61,10 @@ service postgresql start
    chkconfig postgresql on
    # Look at Postgres.md to setup users/database

    # Setup a user for the access (instead of root)
    adduser deploy
    passwd -l deploy

    # All done! Now to deployment!!
    ```

  13. stevenyap revised this gist Dec 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ passenger-install-apache2-module
    service httpd restart

    # Install postgres
    yum install postgresql postgresql-server postgresql-contrib postgresql-libs
    yum install postgresql postgresql-server postgresql-contrib postgresql-devel
    service postgresql initdb
    service postgresql start
    chkconfig postgresql on
  14. stevenyap revised this gist Dec 18, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -58,6 +58,7 @@ service httpd restart
    yum install postgresql postgresql-server postgresql-contrib postgresql-libs
    service postgresql initdb
    service postgresql start
    chkconfig postgresql on
    # Look at Postgres.md to setup users/database

    # All done! Now to deployment!!
  15. stevenyap revised this gist Dec 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ passenger-install-apache2-module
    service httpd restart

    # Install postgres
    yum install postgres postgres-server postgres-contrib
    yum install postgresql postgresql-server postgresql-contrib postgresql-libs
    service postgresql initdb
    service postgresql start
    # Look at Postgres.md to setup users/database
  16. stevenyap revised this gist Dec 18, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -79,5 +79,7 @@ ifconfig eth0 | grep inet | awk '{ print $2 }'
    # If there are error loading passenger
    passenger-config --root
    chcon -R -h -t httpd_sys_content_t /path-to-passenger-root

    # Ensure your rvm gemset use default before you do passenger-install-apache2-module
    ```

  17. stevenyap revised this gist Dec 18, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,6 @@ yum clean all
    yum -y update
    yum -y install curl-devel git sqlite-devel libxml2-devel
    yum -y install libxml2 libxml2-devel libxslt libxslt-devel
    yum -y install gcc
    yum -y install nodejs # If this does not work, do it again after you installed RVM

    # install RVM
  18. stevenyap revised this gist Dec 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ yum -y update
    yum -y install curl-devel git sqlite-devel libxml2-devel
    yum -y install libxml2 libxml2-devel libxslt libxslt-devel
    yum -y install gcc
    yum -y install nodejs
    yum -y install nodejs # If this does not work, do it again after you installed RVM

    # install RVM
    curl -L https://get.rvm.io | bash -s stable
  19. stevenyap revised this gist Dec 18, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@ yum clean all
    yum -y update
    yum -y install curl-devel git sqlite-devel libxml2-devel
    yum -y install libxml2 libxml2-devel libxslt libxslt-devel
    yum -y install gcc
    yum -y install nodejs

    # install RVM
  20. stevenyap revised this gist Dec 18, 2013. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,10 @@ You can test it yourself using VirtualBox to run all the scripts - read VirtualB
    ```sh
    # install the necessary libraries
    yum clean all
    yum update
    yum install curl-devel git sqlite-devel libxml2-devel
    yum install libxml2 libxml2-devel libxslt libxslt-devel
    yum install nodejs
    yum -y update
    yum -y install curl-devel git sqlite-devel libxml2-devel
    yum -y install libxml2 libxml2-devel libxslt libxslt-devel
    yum -y install nodejs

    # install RVM
    curl -L https://get.rvm.io | bash -s stable
  21. stevenyap revised this gist Dec 18, 2013. 1 changed file with 18 additions and 18 deletions.
    36 changes: 18 additions & 18 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,22 @@
    This guide setup Apache2/Passenger/Ruby/Rails on a CentOS.
    This guide setup Apache2/Passenger/Ruby/Rails on a CentOS 6.4 LiveCD.
    You can test it yourself using VirtualBox to run all the scripts - read VirtualBox.md for more info.

    ```sh
    # install the necessary libraries
    yum clean all
    yum update
    yum install curl-devel git sqlite-devel libxml2-devel
    yum install libxml2 libxml2-devel libxslt libxslt-devel
    yum install nodejs

    # install RVM
    curl -L https://get.rvm.io | bash -s stable
    # runs RVM
    source /etc/profile.d/rvm.sh
    # Setups required files for RVM
    rvm requirements --autolibs=enable

    # Install Ruby
    rvm install 2.0.0

    # Config RVM to use ruby 2.0.0
    rvm use 2.0.0
    rvm --default 2.0.0
    rvm --default use 2.0.0

    # Install bundler
    gem install bundler
    @@ -29,21 +25,21 @@ gem install bundler
    gem install rails --version 4.0.0 --no-ri --no-rdoc

    # You can verify rails successful installation
    # You should install all the gems necessary (in global gemset) for your app using your Gemfile
    # so that later deployment will not face bundling issues
    rails -v

    # Install Apache
    yum install httpd httpd-devel

    # Allow port 80 to server webpage
    iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    # Or to turn off firewall completely: service iptables stop

    # starts the service
    chkconfig httpd on # sets httpd to run on startup
    chkconfig httpd on
    service httpd start

    # find out your server IP
    ifconfig eth0 | grep inet | awk '{ print $2 }'

    # You can check if your apache is running by viewing http://localhost:8888 on your browser

    # Install passenger
    @@ -53,21 +49,18 @@ gem install passenger --version 4.0.8
    passenger-install-apache2-module

    # There will be instructions to load your passenger module via http conf
    # Put the code in a new file at /etc/httpd/conf.d/passenger.conf
    # Put the config in a new file at /etc/httpd/conf.d/passenger.conf

    # Restart the service
    service httpd restart

    # If there are error loading passenger
    passenger-config --root
    chcon -R -h -t httpd_sys_content_t /path-to-passenger-root

    # Install postgres
    yum install postgres postgres-server postgres-contrib

    service postgresql initdb

    service postgresql start
    # Look at Postgres.md to setup users/database

    # All done! Now to deployment!!
    ```

    ## Diagnostic
    @@ -79,5 +72,12 @@ cat /var/log/httpd/error_log
    # Error with yum update
    yum clean all
    yum check-update

    # find out your server IP
    ifconfig eth0 | grep inet | awk '{ print $2 }'

    # If there are error loading passenger
    passenger-config --root
    chcon -R -h -t httpd_sys_content_t /path-to-passenger-root
    ```

  22. stevenyap revised this gist Dec 17, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@ You can test it yourself using VirtualBox to run all the scripts - read VirtualB
    # install the necessary libraries
    yum update
    yum install curl-devel git sqlite-devel libxml2-devel
    yum install libxml2 libxml2-devel libxslt libxslt-devel
    yum install nodejs

    # install RVM
  23. stevenyap revised this gist Dec 17, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ You can test it yourself using VirtualBox to run all the scripts - read VirtualB
    ```sh
    # install the necessary libraries
    yum update
    yum install curl-devel git sqlite-devel
    yum install curl-devel git sqlite-devel libxml2-devel
    yum install nodejs

    # install RVM
  24. stevenyap revised this gist Dec 17, 2013. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -74,4 +74,9 @@ service postgresql start
    ```sh
    # see httpd error log
    cat /var/log/httpd/error_log
    ```

    # Error with yum update
    yum clean all
    yum check-update
    ```

  25. stevenyap revised this gist Nov 26, 2013. No changes.
  26. stevenyap revised this gist Nov 25, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -32,12 +32,12 @@ rails -v

    # Install Apache
    yum install httpd httpd-devel
    chkconfig httpd on # sets httpd to run on startup

    # Allow port 80 to server webpage
    iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT

    # starts the service
    chkconfig httpd on # sets httpd to run on startup
    service httpd start

    # find out your server IP
  27. stevenyap revised this gist Nov 25, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -32,6 +32,7 @@ rails -v

    # Install Apache
    yum install httpd httpd-devel
    chkconfig httpd on # sets httpd to run on startup

    # Allow port 80 to server webpage
    iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
  28. stevenyap revised this gist Nov 25, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@ You can test it yourself using VirtualBox to run all the scripts - read VirtualB

    ```sh
    # install the necessary libraries
    yum update
    yum install curl-devel git sqlite-devel
    yum install nodejs

  29. stevenyap revised this gist Nov 23, 2013. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -58,6 +58,13 @@ service httpd restart
    # If there are error loading passenger
    passenger-config --root
    chcon -R -h -t httpd_sys_content_t /path-to-passenger-root

    # Install postgres
    yum install postgres postgres-server postgres-contrib

    service postgresql initdb

    service postgresql start
    ```

    ## Diagnostic
  30. stevenyap revised this gist Nov 23, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Server Setup.md
    Original file line number Diff line number Diff line change
    @@ -24,10 +24,10 @@ rvm --default 2.0.0
    gem install bundler

    # Install Rails gem
    #gem install rails --version 4.0.0 --no-ri --no-rdoc
    gem install rails --version 4.0.0 --no-ri --no-rdoc

    # You can verify rails successful installation
    #rails -v
    rails -v

    # Install Apache
    yum install httpd httpd-devel