Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
252 lines (207 sloc) 8.14 KB
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install lnmp"
exit 1
fi
clear
echo "========================================================================="
echo "Nginx installation bash for Ubuntu VPS , Written by Licess "
echo "========================================================================="
echo "A tool to auto-compile & install Nginx on Linux "
echo ""
echo "For more information please visit http://www.lnmp.org/"
echo "========================================================================="
cur_dir=$(pwd)
if [ "$1" != "--help" ]; then
#set main domain name
domain="www.lnmp.org"
echo "Please input domain:"
read -p "(Default domain: www.lnmp.org):" domain
if [ "$domain" = "" ]; then
domain="www.lnmp.org"
fi
echo "==========================="
echo "domain=$domain"
echo "==========================="
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start..."
char=`get_char`
dpkg -l |grep mysql
dpkg -P libmysqlclient15off libmysqlclient15-dev mysql-common
dpkg -l |grep apache
dpkg -P apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-common
dpkg -l |grep php
dpkg -P php
apt-get update
apt-get remove -y apache2 apache2-doc apache2-utils apache2.2-common apache2.2-bin apache2-mpm-prefork apache2-doc apache2-mpm-worker mysql-client mysql-server mysql-common php
killall apache2
apt-get install -y ntpdate
ntpdate -u pool.ntp.org
date
apt-get update
apt-get autoremove -y
apt-get -fy install
apt-get install -y build-essential gcc g++ make git-core
for packages in build-essential gcc g++ make automake autoconf re2c wget cron bzip2 libzip-dev libc6-dev file rcconf flex vim nano bison m4 gawk less make cpp binutils diffutils unzip tar bzip2 libbz2-dev unrar p7zip libncurses5-dev libncurses5 libncurses5-dev libncurses5-dev libtool libevent-dev libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlibc openssl libsasl2-dev libxml2 libxml2-dev libltdl3-dev libltdl-dev libmcrypt-dev libmysqlclient15-dev zlib1g zlib1g-dev libbz2-1.0 libbz2-dev libglib2.0-0 libglib2.0-dev libpng3 libfreetype6 libfreetype6-dev libjpeg62 libjpeg62-dev libjpeg-dev libpng-dev libpng12-0 libpng12-dev curl libcurl3 libmhash2 libmhash-dev libpq-dev libpq5 gettext libncurses5-dev libcurl4-gnutls-dev libjpeg-dev libpng12-dev libxml2-dev zlib1g-dev libfreetype6 libfreetype6-dev libssl-dev libcurl3 libcurl4-openssl-dev libcurl4-gnutls-dev mcrypt libssl-dev libpcre3-dev git-core;
do apt-get install -y $packages --force-yes;apt-get -fy install;apt-get -y autoremove; done
echo "============================check files=================================="
if [ -s pcre-8.30.tar.gz ]; then
echo "pcre-8.30.tar.gz [found]"
else
echo "Error: pcre-8.30.tar.gz not found!!!download now......"
wget -c http://sourceforge.net/projects/pcre/files/pcre/8.30/pcre-8.30.tar.gz/download
fi
if [ -s nginx-1.0.14.tar.gz ]; then
echo "nginx-1.0.14.tar.gz [found]"
else
echo "Error: nginx-1.0.14.tar.gz not found!!!download now......"
wget -c http://nginx.org/download/nginx-1.0.14.tar.gz
fi
if [ -s libmcrypt-2.5.8.tar.gz ]; then
echo "libmcrypt-2.5.8.tar.gz [found]"
else
echo "Error: libmcrypt-2.5.8.tar.gz not found!!!download now......"
wget -c http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
fi
echo "============================check files=================================="
cd $cur_dir
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make && make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
cd ../../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
ln -s /usr/lib/x86_64-linux-gnu/libpng* /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libjpeg* /usr/lib/
else
ln -s /usr/lib/i386-linux-gnu/libpng* /usr/lib/
ln -s /usr/lib/i386-linux-gnu/libjpeg* /usr/lib/
fi
ulimit -v unlimited
sysctl -w net.core.somaxconn="32768"
sysctl -w net.core.netdev_max_backlog="32768"
if [ ! `grep -l "/lib" '/etc/ld.so.conf'` ]; then
echo "/lib" >> /etc/ld.so.conf
fi
if [ ! `grep -l '/usr/lib' '/etc/ld.so.conf'` ]; then
echo "/usr/lib" >> /etc/ld.so.conf
fi
if [ -d "/usr/lib64" ] && [ ! `grep -l '/usr/lib64' '/etc/ld.so.conf'` ]; then
echo "/usr/lib64" >> /etc/ld.so.conf
fi
if [ ! `grep -l '/usr/local/lib' '/etc/ld.so.conf'` ]; then
echo "/usr/local/lib" >> /etc/ld.so.conf
fi
ldconfig
cat >>/etc/security/limits.conf<<eof
* soft noproc 65535
* hard noproc 65535
* soft nofile 65535
* hard nofile 65535
eof
cat >>/etc/sysctl.conf<<eof
fs.file-max=65535
eof
echo "========================== nginx install ==============================="
groupadd www
useradd -s /sbin/nologin -g www www
mkdir -p /home/wwwroot
chmod +w /home/wwwroot
mkdir -p /home/wwwlogs
chmod 777 /home/wwwlogs
touch /home/wwwlogs/nginx_error.log
cd $cur_dir
chown -R www:www /home/wwwroot
rm -f /usr/local/php/etc/php-fpm.conf
cp conf/php-fpm.conf /usr/local/php/etc/php-fpm.conf
# tcp-patch
cd $cur_dir
git clone https://github.com/yaoweibin/nginx_tcp_proxy_module.git
# nginx
cd $cur_dir
tar zxvf pcre-8.30.tar.gz
cd pcre-8.30/
./configure
make && make install
cd ../
tar zxvf nginx-1.0.14.tar.gz
cd nginx-1.0.14/
patch -p1 < ../nginx_tcp_proxy_module/tcp.patch
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --add-module=../nginx_tcp_proxy_module/
make && make install
cd ../
cd $cur_dir
rm -f /usr/local/nginx/conf/nginx.conf
cp conf/nginx.conf /usr/local/nginx/conf/nginx.conf
cp conf/dabr.conf /usr/local/nginx/conf/dabr.conf
cp conf/discuz.conf /usr/local/nginx/conf/discuz.conf
cp conf/sablog.conf /usr/local/nginx/conf/sablog.conf
cp conf/typecho.conf /usr/local/nginx/conf/typecho.conf
cp conf/wordpress.conf /usr/local/nginx/conf/wordpress.conf
cp conf/discuzx.conf /usr/local/nginx/conf/discuzx.conf
cp conf/wp2.conf /usr/local/nginx/conf/wp2.conf
cp conf/none.conf /usr/local/nginx/conf/none.conf
sed -i 's/www.lnmp.org/'$domain'/g' /usr/local/nginx/conf/nginx.conf
rm -f /usr/local/nginx/conf/fcgi.conf
cp conf/fcgi.conf /usr/local/nginx/conf/fcgi.conf
echo "==================== nginx install completed ==========================="
cp conf/index.html /home/wwwroot/index.html
#start up
cd $cur_dir
cp conf/init.d.nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
update-rc.d -f nginx defaults
/etc/init.d/nginx start
echo "===================================== Check install ==================================="
clear
if [ -s /usr/local/nginx ]; then
echo "/usr/local/nginx [found]"
else
echo "Error: /usr/local/nginx not found!!!"
fi
echo "========================== Check install ================================"
if [ -s /usr/local/nginx ]; then
echo "Install Nginx completed! enjoy it."
echo "========================================================================="
echo "Nginx installation bash for Ubuntu VPS , Written by Licess "
echo "========================================================================="
echo ""
echo "For more information please visit http://www.lnmp.org/"
echo ""
echo "The path of some dirs:"
echo "nginx dir: /usr/local/nginx"
echo "nginx configure files dir: /usr/local/nginx/conf"
echo "web dir : /home/wwwroot"
echo "hints:"
echo "manage nginx: /etc/init.d/nginx {start|stop|reload|restart|kill}"
echo "check nginx file: /usr/local/nginx/sbin/nginx -t"
echo "Every time you change the nginx conf files, you have to reload or restart nginx by hands."
echo ""
echo "========================================================================="
netstat -ntl
else
echo "Sorry,Failed to install nginx!"
echo "Please visit http://bbs.vpser.net/forum-25-1.html feedback errors and logs."
fi
fi