Created
January 31, 2012 22:18
-
-
Save brentkirby/1713410 to your computer and use it in GitHub Desktop.
Linode nginx, php, mysql stackscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Ruby 1.9.2 with options for database, and nginx install. Adds option to install RVM system-wide. | |
# Outputs to /root/stackscript.log | |
# | |
# <UDF name="deploy_user" Label="Name of deployment user." /> | |
# <UDF name="deploy_password" Label="Password for deployment user." /> | |
# <UDF name="deploy_sshkey" Label="Deployment user public ssh key." /> | |
# <UDF name="ssh_port" Label="SSH Port" /> | |
# <UDF name="new_hostname" Label="Server's hostname." /> | |
# <UDF name="default_editor" Label="Default text editor." Default="nano" /> | |
exec &> /root/stackscript.log | |
source <ssinclude StackScriptID=1> # Common bash functions | |
source <ssinclude StackScriptID=123> # Awesome ubuntu utils script | |
function log { | |
echo "$1 `date '+%D %T'`" | |
} | |
function system_sshd_portnumber { | |
sed -i "s/^#*\(Port\).*/\1 $1/" /etc/ssh/sshd_config | |
} | |
function system_sshd_append { | |
# $1 configuration option | |
# $2 value to set | |
echo "$1 $2" >> /etc/ssh/sshd_config | |
} | |
function install_nginx { | |
cd /usr/local/src | |
wget http://cdn.kurbmedia.com.s3.amazonaws.com/deb/nginx_1.0.11-km1_i386.deb | |
dpkg -i nginx_1.0.11-km1_i386.deb | |
} | |
function install_php { | |
aptitude -y install autoconf libcurl4-openssl-dev libjpeg62-dev libpng3-dev libxpm-dev libfreetype6-dev libt1-dev libmcrypt-dev libxslt1-dev libbz2-dev libxml2-dev libevent-dev libltdl-dev libmagickwand-dev imagemagick | |
cd /usr/local/src | |
wget http://us3.php.net/distributions/php-5.3.9.tar.gz | |
wget http://pecl.php.net/get/APC-3.1.9.tgz | |
tar -xvf php-5.3.9.tar.gz | |
tar xzvf APC-3.1.9.tgz | |
cd php-5.3.9 | |
./configure --with-mysql --prefix=/usr/local/php --with-fpm-user=www-data --with-fpm-group=www-data --enable-cgi --enable-fpm --with-config-file-path=/usr/local/php --with-pear --with-zlib --with-curl --with-xsl --enable-mbstring --with-mysqli --with-gd --with-mcrypt --enable-pdo=shared --with-sqlite=shared --with-pdo-sqlite=shared --with-pdo-mysql=shared --with-jpeg-dir=/usr/lib --enable-calendar --with-imap --with-kerberos --with-imap-ssl | |
mkdir /usr/local/php/var/log/php-fpm | |
chown -R www-data:www-data /usr/local/php/var/log/php-fpm | |
chown -R www-data:www-data /usr/local/php/var/run | |
cp -f php.ini-production /usr/local/php/etc/php.ini | |
chmod 644 /usr/local/php/php.ini | |
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf | |
cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm | |
chmod 755 /etc/init.d/php-fpm | |
update-rc.d -f php-fpm defaults | |
cd /usr/local/src/APC-3.1.9/ | |
./configure --enable-apc --with-php-config=/usr/local/php/bin/php-config --with-libdir=/usr/local/php/lib/php | |
make | |
make install | |
} | |
log "Adding universe repositories and updating." | |
system_enable_universe | |
log "Base packages updated" | |
log "Installing required packages, as well as git..." | |
aptitude -y install git-core build-essential zlib1g-dev libpcre3-dev libssl-dev libreadline5-dev gcc g++ libxslt-dev libxml2-dev curl wget python-software-properties openssh-server $DEFAULT_EDITOR | |
log "Packages installed" | |
# Add deploy user | |
log "Adding deploy user, and ssh key." | |
system_add_user $DEPLOY_USER $DEPLOY_PASSWORD "users,sudo" | |
system_user_add_ssh_key $DEPLOY_USER "$DEPLOY_SSHKEY" | |
system_update_locale_en_US_UTF_8 | |
log "Reconfiguring SSH" | |
system_sshd_portnumber $SSH_PORT | |
system_sshd_permitrootlogin No | |
system_sshd_passwordauthentication No | |
system_sshd_pubkeyauthentication Yes | |
system_sshd_append ClientAliveInterval 60 | |
/etc/init.d/ssh restart | |
log "Set hostname to $NEW_HOSTNAME" | |
system_update_hostname $NEW_HOSTNAME | |
aptitude -y install ufw | |
ufw logging on | |
ufw default deny | |
ufw allow 80/tcp | |
ufw allow 443/tcp | |
ufw allow $SSH_PORT | |
ufw enable | |
log "Installing nginx from custom package" | |
install_nginx | |
log "Installing MySQL" | |
aptitude -y install libmysqlclient-dev | |
mysql_install "$DEPLOY_PASSWORD" | |
mysql_tune 30 | |
log "Installing PHP" | |
install_php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment