build server with nginx, php53, mysql, mongo
## This is to build a Ubuntu 9.10
## server on Rackspace Cloud Servers
## complete with nginx, php 5.3
## pgsql, mysql, mongodb
## Hopefully this will be helpful for Lithium/li3 PHP framework users that are unsure how to
## get a php 5.3 server up and running :-)
## http://rad-dev.org/lithium/wiki
# Change password
passwd
# Edit .bashrc to add aliases
# Find "# some more ls aliases", add the following below:
# alias free="free -m"
# alias update="aptitude update"
# alias install="aptitude install"
# alias upgrade="aptitude safe-upgrade"
# alias remove="aptitude remove"
# alias search="aptitude search"
# alias show="aptitude show"
nano .bashrc
# Update Apt
update
# Perform a safe upgrade
upgrade
# Install Nginx
install nginx
# Edit sources.list to add dotdeb PHP sources:
# PHP 5.3 Dotdeb Sources
# deb http://php53.dotdeb.org stable all
# deb-src http://php53.dotdeb.org stable all
nano /etc/apt/sources.list
# Update to fetch dotdeb repo info
update
# Perform safe upgrade to catch any new packages
upgrade
# Download & install needed dependencies
cd /root/
install autotools-dev
wget http://us.archive.ubuntu.com/ubuntu/pool/main/k/krb5/libkrb53_1.6.dfsg.4~beta1-5ubuntu2_amd64.deb
wget http://us.archive.ubuntu.com/ubuntu/pool/main/i/icu/libicu38_3.8-6ubuntu0.2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/libt/libtool/libtool_1.5.26-1ubuntu1_amd64.deb
dpkg --force-depends -i *.deb
# Install memcached
install memcached
# Install PHP, Postgres, MySQL
install php5 php5-cgi php5-cli php5-common php5-curl php5-exactimage php5-fpm php5-gd php5-geoip php5-http php5-imagick php5-imap php5-json php5-mailparse php5-mcrypt php5-memcache php5-mysql php5-odbc php5-pgsql php5-pspell php5-sqlite php5-svn php5-tidy php5-xmlrpc php5-xcache php5-xsl php5-dev php-pear postgresql postgresql-client mysql-server mysql-client mysql-common build-essential
# Move into web dir
cd /var/www
# Make directory structure for your domains
# Each set of {} brackets will accept a comma-delimited
# list of folder names for your domain structure
# Replace DOMAIN/SUB.DOMAIN w/ your actual domains
mkdir -p {DOMAIN.com,SUB.DOMAIN.com}/{public,private,backup,log,conf}
# Make SSH use a different port (pick a high port number, i.e. - 9922)
# Search for 22, replace with your custom port number
nano /etc/ssh/sshd_config
# Install firewall, change SSH port to
install ufw
ufw enable
ufw logging on
# Allow access to your custom port number
# Replace 9922 with your custom port number
ufw allow 9922/tcp
# Allow web traffic
ufw allow 80/tcp
ufw allow 443/tcp
# Restart SSH
service ssh restart
# At this point you should disconnect your session
# and then reconnect using your custom port
# Once connected, block all traffic by default
ufw default deny
# Configure nginx params
# Here's my conf: http://pastium.org/view/af6080f2abbb0f74e651cd560f8f5101
nano /etc/nginx/nginx.conf
# Configure fastcgi params
# Here's my fastcgi conf: http://pastium.org/view/1aea1db24c8d59daccefccef4f8ca9f4
nano /etc/nginx/fastcgi_params
# Configure domain params
# Perform this routine for each domain you set up
# Below is my nginx site config for a Lithium/li3 based website (similar to CakePHP)
# http://pastium.org/view/259e4e5935615bf04a367fb80c3e8811
nano /var/www/DOMAIN.com/conf/nginx.conf
# Edit PHP-FPM configuration
# Here is my php5-fpm conf: http://pastium.org/view/28d7c1b53bd702a4c5df92e33af15f2a
nano /etc/php5/fpm/php5-fpm.conf
# Install Mongo
mkdir /mongodb
cd /mongodb/
wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-1.2.1.tgz
tar xzvf mongodb-linux-x86_64-1.2.1.tgz
mv mongodb-linux-x86_64-1.2.1/* .
rmdir mongodb-linux-x86_64-1.2.1
# Make mongo data storage folder
mkdir -p /data/db
/mongodb/bin/mongod --fork --logpath /var/log/mongodb.log --logappend
# Install PHP's mongodb
pecl install mongo
# Make sure mongo is enabled if not already
# Content should be:
# extension=mongo.so
nano /etc/php5/conf.d/mongo.ini
# Start PHP-FPM
service php5-fpm start
# Start nginx
service nginx start
# Create index page to ensure PHP is functioning
# Contents of this file should be:
# <?php phpinfo(); ?>
nano /var/www/DOMAIN.com/public/index.php