Skip to content

Instantly share code, notes, and snippets.

@alispat
Created April 16, 2012 13:28
Show Gist options
  • Save alispat/2398821 to your computer and use it in GitHub Desktop.
Save alispat/2398821 to your computer and use it in GitHub Desktop.
Server Setup
#--------------------------------------------------------------------------------------------------------------
# Atualização e Instalação de pacotes Básicos
#--------------------------------------------------------------------------------------------------------------
apt-get -y update
apt-get -y install curl git-core python-software-properties
#--------------------------------------------------------------------------------------------------------------
# Correção de um possível erro com os locales
#--------------------------------------------------------------------------------------------------------------
locale-gen pt_BR pt_BR.UTF-8
dpkg-reconfigure locales
#--------------------------------------------------------------------------------------------------------------
# Configuração Nginx stable ou Apache2 (Ainda existe a instalação do Nginx sugerido pelo Passenger)
#--------------------------------------------------------------------------------------------------------------
# Install Nginx
add-apt-repository ppa:nginx/stable
apt-get -y update
apt-get -y install nginx
service nginx start
# Install Apache2
apt-get -y install apache2
#--------------------------------------------------------------------------------------------------------------
# Configuração das Databases PostgreSQL ou MySQL
#--------------------------------------------------------------------------------------------------------------
# Install PostgreSQL
add-apt-repository ppa:pitti/postgresql
apt-get -y update
apt-get -y install postgresql libpq-dev
# Manager PostreSQL
sudo -u postgres psql
#\password
# create user blog with password 'secret';
# create database blog_production owner blog;
# \q
# Install MySQL
apt-get -y install mysql-server mysql-client libmysqlclient-dev
# Manager MySQL
mysql -u root -p
# create database blog_production;
# grant all on blog_production.* to blog@localhost identified by 'secret';
# exit
#--------------------------------------------------------------------------------------------------------------
# Instalação Nodejs (Necessário para rodar o Rails)
#--------------------------------------------------------------------------------------------------------------
add-apt-repository ppa:chris-lea/node.js
apt-get -y update
apt-get -y install nodejs
#--------------------------------------------------------------------------------------------------------------
# Criando e adicionando um usuário no grupo Admin
#--------------------------------------------------------------------------------------------------------------
adduser ruby --ingroup admin
su ruby
cd
#--------------------------------------------------------------------------------------------------------------
# Instalando e Configurando o Ruby através do rbenv - Ruby Version Management
# Utilizando o rbenv installer - https://github.com/fesplugas/rbenv-installer
# OBS: Ao intalar uma nova gem para utilizar é priciso rodar (rbenv rehash)
#--------------------------------------------------------------------------------------------------------------
curl -L https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash
vim ~/.bashrc # adicionar rbenv no topo do arquivo
. ~/.bashrc
rbenv bootstrap-ubuntu-10-04
rbenv install 1.9.3-p125
rbenv global 1.9.3-p125
gem install bundler --no-ri --no-rdoc
rbenv rehash
# get to know github.com or codeplane.com
ssh [email protected]
ssh [email protected]
#--------------------------------------------------------------------------------------------------------------
# Instalação e Configuração do Phusion Passenger
#--------------------------------------------------------------------------------------------------------------
sudo apt-get -y install libcurl4-openssl-dev libapr1-dev libaprutil1-dev libsqlite3-0 libsqlite3-dev sqlite3
gem install passenger --no-rdoc --no-ri
rbenv rehash
sudo sh -c "PATH=\"$PATH\" passenger-install-nginx-module \
--auto \
--prefix=/opt/nginx \
--auto-download \
--extra-configure-flags='\
--with-http_gzip_static_module \
--with-http_ssl_module'"
# adicionar linha em /opt/nginx/conf/nginx.conf
include /opt/nginx/sites-enabled/*;
mkdir /opt/nginx/sites-enabled
# Arquivo para iniciar o Nginx
sudo vim /etc/init/nginx.conf
#--------------------------------------------------------------------------------------------------------------
# Arquivo nginx.conf - /etc/init/nginx.conf
#--------------------------------------------------------------------------------------------------------------
description "Nginx HTTP Server"
start on filesystem
stop on runlevel [!2345]
respawn
exec /opt/nginx/sbin/nginx -g "daemon off;"
#--------------------------------------------------------------------------------------------------------------
# End Arquivo nginx.conf - /etc/init/nginx.conf
#--------------------------------------------------------------------------------------------------------------
# Reniciar o servidor para levantar o serviço Nginx
sudo shutdown -r now
# Listar o Serviço Nginx
sudo initctl list | grep nginx
# Comando do Nginx
sudo service nginx stop
sudo service nginx start
sudo service nginx restart
#--------------------------------------------------------------------------------------------------------------
# EXTRAS - Instalação do phpmyadmin e phppgmyadmin
#--------------------------------------------------------------------------------------------------------------
# Instalação do phpmyadmin
sudo apt-get -y install php5-cgi php5-mysql phpmyadmin
# Arquivo de configuração PHP
sudo vim /etc/init.d/php-fastcgi
#--------------------------------------------------------------------------------------------------------------
# Arquivo php-fastcgi - /etc/init.d/php-fastcgi
#--------------------------------------------------------------------------------------------------------------
#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000
PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0
start() {
echo -n "Starting PHP FastCGI: "
start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
RETVAL=$?
echo "$PHP_CGI_NAME."
}
stop() {
echo -n "Stopping PHP FastCGI: "
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo "$PHP_CGI_NAME."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
#--------------------------------------------------------------------------------------------------------------
# End Arquivo php-fastcgi - /etc/init.d/php-fastcgi
#--------------------------------------------------------------------------------------------------------------
# Configurações Padrões do phpmyadmin
sudo chmod +x /etc/init.d/php-fastcgi
sudo service php-fastcgi start
sudo update-rc.d php-fastcgi defaults
# Vhost do phpmyadmin
sudo vim /opt/nginx/sites-enabled/phpmyadmin.conf
#--------------------------------------------------------------------------------------------------------------
# Arquivo phpmyadmin.conf - /opt/nginx/sites-enabled/phpmyadmin.conf
#--------------------------------------------------------------------------------------------------------------
server{
listen 80;
server_name phpmyadmin;
access_log /var/log/phpmyadmin.access_log;
error_log /var/log/phpmyadmin.error_log;
location / {
root /usr/share/phpmyadmin;
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
include fastcgi_params;
}
}
#--------------------------------------------------------------------------------------------------------------
# End Arquivo phpmyadmin.conf - /opt/nginx/sites-enabled/phpmyadmin.conf
#--------------------------------------------------------------------------------------------------------------
# Reniciar o Serviço Nginx
sudo service nginx restart
# Instalação do phppgadmin
sudo apt-get -y install php5-pgsql phppgadmin
#--------------------------------------------------------------------------------------------------------------
# Arquivo phppgadmin.conf - /opt/nginx/sites-enabled/phppgadmin.conf
#--------------------------------------------------------------------------------------------------------------
server{
listen 80;
server_name phppgadmin;
access_log /var/log/phppgadmin.access_log;
error_log /var/log/phppgadmin.error_log;
location / {
root /usr/share/phppgadmin;
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phppgadmin$fastcgi_script_name;
include fastcgi_params;
}
}
#--------------------------------------------------------------------------------------------------------------
# End Arquivo phppgadmin.conf - /opt/nginx/sites-enabled/phppgadmin.conf
#--------------------------------------------------------------------------------------------------------------
# Talvez seja preciso reniciar o php
sudo service php-fastcgi restart
sudo update-rc.d php-fastcgi defaults
# Reniciar o Serviço Nginx
sudo service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment