diff --git a/README b/README deleted file mode 100644 index fb2b7bc..0000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -FIXME the README! diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a7333f --- /dev/null +++ b/README.md @@ -0,0 +1,113 @@ +##### Currently system, exim4, csf, nginx, mysql, php, htmlsite, drupal6, drupal7 commands are working. Others are being fixed and don't work. + +A simple bash shell script to optimize your Debian or Ubuntu VPS server for serving PHP and MySQL driven website platforms like Drupal and Wordpress. + +### TESTED ON +* Ubuntu 10.04 LTS, Ubuntu 12.04 LTS +* Debian 5, Debian 6 + +### INSTALLATION +Download setup-debian.sh using one of the following commands: + + wget --no-check-certificate https://github.com/sk33lz/lowendscript/raw/master/setup-debian.sh + +or + + git clone git://github.com/sk33lz/lowendscript.git + +### USAGE +This script should be run by the root user for maximum compatibility. + +#### Install System Tools +Installs Dropbear, cron, and inetutils-syslog (replaces rsyslog), htop, smartmontools + +Command: + + bash setup-debian.sh system + +#### Install ConfigServer Firewall +Installs Config Server Firewall for server security and intrusion detection. +Edit the /etc/csf/csf.cfg file to add your email address, or enable specific ports. + +Command: + + bash setup-debian.sh csf + +#### Install Exim4 Mail Server +Lightweight replacement for sendmail. Re-configured to allow Internet delivery. + +Command: + + bash setup-debian.sh exim4 + +#### Install Nginx HTTP Server +Low memory footprint httpd replacement for Apache web server. + +Command: + + bash setup-debian.sh nginx + +#### Install MySQL Database Server +Re-configured to remove innodb support, remove query cache, and reduce key buffer size. + +Command: + + bash setup-debian.sh mysql + +#### Install PHP FastCGI. +Built-in FastCGI running only 1 child process with respawn after 5,000 request. + +Command: + + bash setup-debian.sh php + +#### Install Wordpress +Installs the latet version of Wordpress. Then creates the Virtual Host configuration for the domain supplied in the command, the MySQL Database, the Database User, and the Database User Password. + +Example Command: (Creates a Wordpress site for example.com in /var/www/) + + bash setup-debian.sh wordpress example.com + +#### Install Drupal 6 +Installs the latest version of Drupal 6. Then creates the Virtual Host configuration for the domain supplied in the command, the MySQL Database, the Database User, and the Database User Password.. + +Example Command: (Creates a Drupal 6 installation for example.com in /var/www/example.com) + + bash setup-debian.sh drupal6 example.com + +#### Install Drupal 7 +Installs the latest version of Drupal 7. Then creates the Virtual Host configuration for the domain supplied in the command, the MySQL Database, the Database User, and the Database User Password.. + +Example Command: (Creates a Drupal 7 installation for example.com in /var/www/example.com) + + bash setup-debian.sh drupal7 example.com + +#### Install Magento Community Ecommerce CMS +Installs the latest version of Magento Community, the best open source Ecommerce solution available today. + +Example Command: (Creates a Magento Community installation for example.com in /var/www/vhosts/magento/example.com) + + bash setup-debian.sh magento example.com + +#### Install HTML Site +Creates a directory and sets up the Nginx mapping for the supplied domain name. Also adds a simple index.html file in the domains directory. + +Example Command: (Creates HTML site directory for example.com in /usr/share/nginx/www/example.com) + + bash setup-debian.sh htmlsite example.com + +### SOFTWARE STACK +##### Dropbear +Replaces openssh. Invoked from xinetd. +##### Inetutils-syslogd +Replaces resyslog. +##### Exim4 +Replaces sendmail (if installed). Re-configured to allow Internet delivery. +##### Cron +Schedule tasks on your server, similar to that of the task manager in Windows. +##### Nginx +Lightweight httpd replacement for Apache web server. +##### MySQL +Optimized with innodb and query caching removed with reduced key buffer size. +##### PHP +Optimized PHP built with FastCGI and only running 1 child process which respawns ever 5,000 requests. diff --git a/setup-debian.sh b/setup-debian.sh index 48d32eb..c2bfe52 100755 --- a/setup-debian.sh +++ b/setup-debian.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [[ $EUID -ne 0 ]]; then +echo "This script must be run as root" 1>&2 + exit 1 +fi + function check_install { if [ -z "`which "$1" 2>/dev/null`" ] then @@ -75,6 +80,26 @@ function install_dash { ln -s dash /bin/sh } +function install_htop { + check_install htop htop +} + +function install_smart { + check_install smartmontools smartmontools +} + +function install_locate { + check_install locate locate +} + +function fix_locale { + dpkg-reconfigure locales +} + +function var_www { + mkdir -p /var/www/ +} + function install_dropbear { check_install dropbear dropbear check_install /usr/sbin/xinetd xinetd @@ -113,31 +138,46 @@ function install_exim4 { } function install_mysql { - # Install the MySQL packages - check_install mysqld mysql-server - check_install mysql mysql-client - - # Install a low-end copy of the my.cnf to disable InnoDB, and then delete - # all the related files. - invoke-rc.d mysql stop - rm -f /var/lib/mysql/ib* - cat > /etc/mysql/conf.d/lowendbox.cnf < /etc/mysql/conf.d/lowendbox.cnf < ~/.my.cnf < ~/.my.cnf < /etc/nginx/fastcgi_php < "/usr/share/nginx/www/$1/index.html" < "/etc/nginx/sites-enabled/$1.conf" <" + fi + + #Download PHP5-gd package + apt-get -q -y install php5-gd + /etc/init.d/php-cgi restart + + # Downloading the Drupal' latest and greatest distribution. + mkdir /tmp/drupal.$$ + wget -O - http://ftp.drupal.org/files/projects/drupal-6.30.tar.gz | \ + tar zxf - -C /tmp/drupal.$$/ + mkdir -p /var/www/$1 + cp -Rf /tmp/drupal.$$/drupal*/* "/var/www/$1" + rm -rf /tmp/drupal* + chown root:root -R "/var/www/$1" + + # Setting up the MySQL database + dbname=`echo $1 | tr . _` + + # MySQL dbname cannot be more than 15 characters long + dbname="${dbname:0:15}" + + userid=`get_domain_name $1` + + # MySQL userid cannot be more than 15 characters long + userid="${userid:0:15}" + passwd=`get_password "$userid@mysql"` + cp "/var/www/$1/sites/default/default.settings.php" "/var/www/$1/sites/default/settings.php" + chmod 777 /var/www/$1/sites/default/settings.php + mkdir /var/www/$1/sites/default/files + chmod -R 777 /var/www/$1/sites/default/files + mysqladmin create "$dbname" + echo "GRANT ALL PRIVILEGES ON \`$dbname\`.* TO \`$userid\`@localhost IDENTIFIED BY '$passwd';" | \ + mysql + + #Copy DB Name, User, and Pass to settings.php and set to read only. + sed -i "91 s/username/$userid/; 91 s/password/$passwd/; 91 s/databasename/$dbname/" "/var/www/$1/sites/default/settings.php" + chmod 644 /var/www/$1/sites/default/settings.php + + # Setting up Nginx mapping + cat > "/etc/nginx/sites-enabled/$1.conf" <" + fi + + #Download PHP5-gd package + apt-get -q -y install php5-gd + /etc/init.d/php-cgi restart + + # Downloading the Drupal' latest and greatest distribution. + mkdir /tmp/drupal.$$ + wget -O - http://ftp.drupal.org/files/projects/drupal-7.26.tar.gz | \ + tar zxf - -C /tmp/drupal.$$/ + mkdir -p /var/www/$1 + cp -Rf /tmp/drupal.$$/drupal*/* "/var/www/$1" + rm -rf /tmp/drupal* + chown root:root -R "/var/www/$1" + + # Setting up the MySQL database + dbname=`echo $1 | tr . _` + + # MySQL dbname cannot be more than 15 characters long + dbname="${dbname:0:15}" + + userid=`get_domain_name $1` + + # MySQL userid cannot be more than 15 characters long + userid="${userid:0:15}" + passwd=`get_password "$userid@mysql"` + + # Copy default.settings.php to settings.php and set write permissions. + cp "/var/www/$1/sites/default/default.settings.php" "/var/www/$1/sites/default/settings.php" + chmod 777 /var/www/$1/sites/default/settings.php + mkdir /var/www/$1/sites/default/files + chmod -R 777 /var/www/$1/sites/default/files + + # Create MySQL database + mysqladmin create "$dbname" + echo "GRANT ALL PRIVILEGES ON \`$dbname\`.* TO \`$userid\`@localhost IDENTIFIED BY '$passwd';" | \ + mysql + + #Copy DB Name, User, and Pass to settings.php and set to read only. + echo "\$databases['default']['default'] = array(" >> /var/www/$1/sites/default/settings.php + echo "'driver' => 'mysql'," >> /var/www/$1/sites/default/settings.php + echo "'database' => '$dbname'," >> /var/www/$1/sites/default/settings.php + echo "'username' => '$userid'," >> /var/www/$1/sites/default/settings.php + echo "'password' => '$passwd'," >> /var/www/$1/sites/default/settings.php + echo "'host' => 'localhost');" >> /var/www/$1/sites/default/settings.php + chmod 644 /var/www/$1/sites/default/settings.php + + #Echo DB Name + echo -e $COL_BLUE"*** COPY FOR SAFE KEEPING ***" + COL_BLUE="\x1b[34;01m" + COL_RESET="\x1b[39;49;00m" + echo -e $COL_BLUE"Database Name: "$COL_RESET"$dbname" + + #Echo DB User value + echo -e $COL_BLUE"Database User: "$COL_RESET"${userid:0:15}" + + #Echo DB Password + echo -e $COL_BLUE"Database Password: "$COL_RESET"$passwd" + + #Echo Install URL + echo -e $COL_BLUE"Visit to finalize installation: "$COL_RESET"http://$1/install.php" + + + + # Setting up Nginx mapping + cat > "/etc/nginx/sites-enabled/$1.conf" <