Skip to content

Instantly share code, notes, and snippets.

@jianyuan
Last active January 1, 2016 04:08
Show Gist options
  • Save jianyuan/8089508 to your computer and use it in GitHub Desktop.
Save jianyuan/8089508 to your computer and use it in GitHub Desktop.
Setting up Ubuntu servers
# Copy my ssh public key to the server
ssh-copy-id root@<ip>
# Log into server
ssh root@<ip>
# Create new user
adduser app
usermod -a -G sudo app
su - app
# Stop and remove apache
sudo service apache2 stop
sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
sudo apt-get autoremove --purge
whereis apache2
sudo rm -Rf /etc/apache2 /usr/lib/apache2 /usr/include/apache2
# Update packages
sudo apt-get update
# Update locale
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales
# Install Postgresql
sudo apt-get install postgresql postgresql-contrib
sudo pg_createcluster 9.1 main --start
# Change Postgresql password
sudo su - postgres
psql -d postgres -U postgres
# or
sudo -u postgres psql template1
# \password postgres
# \q
postgres createdb mydb
logout
# Install Ruby using Railsready
wget --no-check-certificate https://raw.github.com/joshfng/railsready/master/railsready.sh && bash railsready.sh
# Install nginx + rails using Passenger
passenger-install-nginx-module
# Create nginx upstart (Insert into /etc/init)
sudo wget https://gist.github.com/sickill/2492523/raw/d1ecb87e9eba9e59ddd44d3c3aaf6c3c52b16374/nginx.conf /etc/init
# Edit nginx.conf
sudo vim /opt/nginx/conf/nginx.conf
Add this:
...
server {
listen 80;
server_name www.yourhost.com;
root /somewhere/public; # <--- be sure to point to 'public'!
passenger_enabled on;
}
...
mkdir /var/www/app_name
sudo chown -R app:www-data .
# Set up Upstart (Taken from http://blog.thehippo.de/2012/12/server/install-nginx-from-source-on-ubuntu/)
sudo vim /etc/init/nginx.conf
...
# nginx
description "nginx http daemon"
author "Philipp Klose <me@'thisdomain'.de>"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/opt/nginx/sbin/nginx
env PID=/opt/nginx/logs/nginx.pid
expect fork
respawn
respawn limit 10 5
#oom never
pre-start script
$DAEMON -t
if [ $? -ne 0 ]
then exit $?
fi
end script
exec $DAEMON
...
bundle exec cap production deploy:check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment