nginx installation shell script
- Download nginx & pcre source files.
- Put nginx-x.x.x-tar.gz and pcre-x.x.x into /tmp.
- Make nginx_install.sh file and give it execute permission. (you need to fix NGINX_VERSION, PCRE_VERSION for your own versions)
- Run the nginx_install.sh
#!bin/sh
NGINX_VERSION="1.6.3"
PCRE_VERSION="8.35"
OPENSSL_VERSION="1.0.2a"
ZLIB_VERSION="1.2.8"
INSTALL_FILE_DIR="/tmp"
NGINX_PACKAGE_FILE="$INSTALL_FILE_DIR/nginx-$NGINX_VERSION.tar.gz"
NGINX_SOURCE_DIR="/usr/local/src/nginx"
NGINX_SOURCE_PATH="$NGINX_SOURCE_DIR/nginx-$NGINX_VERSION"
PCRE_PATH="/usr/local/lib/libpcre.so"
PCRE_PACKAGE_FILE="$INSTALL_FILE_DIR/pcre-$PCRE_VERSION.tar.gz"
PCRE_SOURCE_DIR="/usr/local/src/pcre"
PCRE_SOURCE_PATH="$PCRE_SOURCE_DIR/pcre-$PCRE_VERSION"
OPENSSL_PACKAGE_FILE="$INSTALL_FILE_DIR/openssl-$OPENSSL_VERSION.tar.gz"
OPENSSL_SOURCE_DIR="/usr/local/src/openssl"
OPENSSL_SOURCE_PATH="$OPENSSL_SOURCE_DIR/openssl-$OPENSSL_VERSION"
ZLIB_PACKAGE_FILE="$INSTALL_FILE_DIR/zlib-$ZLIB_VERSION.tar.gz"
ZLIB_SOURCE_DIR="/usr/local/src/zlib"
ZLIB_SOURCE_PATH="$ZLIB_SOURCE_DIR/zlib-$ZLIB_VERSION"
LIB_CONF_DIR="/etc/ld.so.conf.d"
NGINX_SYMBOLIC_LINK_DIR="/usr/local/sbin"
echo "NGINX VERSION: $NGINX_VERSION"
echo "PCRE VERSION: $PCRE_VERSION"
echo "OPENSSL VERSION: $OPENSSL_VERSION"
echo "ZLIB VERSION: $ZLIB_VERSION"
echo "NGINX PACKAGE FILE:$NGINX_PACKAGE_FILE"
echo "PCRE PACKAGE FILE: $PCRE_PACKAGE_FILE"
echo "OPENSSL PACKAGE FILE: $OPENSSL_PACKAGE_FILE"
echo "ZLIB PACKAGE FILE: $ZLIB_PACKAGE_FILE"
if [ -r $NGINX_PACKAGE_FILE ]
then
echo "Found Nginx Package File!"
else
echo "Can't find nginx package file at $NGINX_PACKAGE_FILE"
exit 1;
fi
if [ -r $PCRE_SOURCE_PATH ];
then
echo "PCRE already extracted"
else
if [ -r $PCRE_SOURCE_DIR ];
then
echo "PCRE source directory exists"
else
echo "PCRE source directory no exists. package will be extracted."
mkdir $PCRE_SOURCE_DIR
fi
echo "PCRE source package will be extracted in $PCRE_SOURCE_PATH"
tar -xvzf $PCRE_PACKAGE_FILE -C $PCRE_SOURCE_DIR > pcre_extract.log 2> pcre_extract.err
fi
if [ -r $OPENSSL_SOURCE_PATH ];
then
echo "OPENSSL already extracted"
else
if [ -r $OPENSSL_SOURCE_DIR ];
then
echo "OPENSSL source directory exists"
else
echo "OPENSSL source directory no exists."
mkdir $OPENSSL_SOURCE_DIR
fi
echo "OPENSSL source package will be extracted in $OPENSSL_SOURCE_PATH"
tar -xvzf $OPENSSL_PACKAGE_FILE -C $OPENSSL_SOURCE_DIR > openssl_extract.log 2> openssl_extract.err
fi
if [ -r $ZLIB_SOURCE_PATH ];
then
echo "ZLIB already extracted"
else
if [ -r $ZLIB_SOURCE_DIR ];
then
echo "ZLIB source directory exists"
else
echo "ZLIB source directory no exists. package will be extracted."
mkdir $ZLIB_SOURCE_DIR
fi
echo "ZLIB source package will be extracted in $ZLIB_SOURCE_PATH"
tar -xvzf $ZLIB_PACKAGE_FILE -C $ZLIB_SOURCE_DIR > openssl_extract.log 2> openssl_extract.err
fi
if [ -r $NGINX_SOURCE_PATH ];
then
echo "Found nginx sources. skip extracting..."
else
echo "Make nginx source directory at $NGINX_SOURCE_DIR"
mkdir $NGINX_SOURCE_DIR
tar -xvzf $NGINX_PACKAGE_FILE -C $NGINX_SOURCE_DIR > $INSTALL_FILE_DIR/nginx_extract.log 2> $INSTALL_FILE_DIR/nginx_extract.err
echo "Extracted nginx sources successfully at $NGINX_SOURCE_PATH"
fi
echo "Installing nginx..."
cd $NGINX_SOURCE_PATH
echo "Configuring..."
./configure --prefix=/usr/local/nginx --builddir=./objs --sbin-path=/usr/local/sbin --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --with-pcre=$PCRE_SOURCE_PATH --with-zlib=$ZLIB_SOURCE_PATH --with-openssl=$OPENSSL_SOURCE_PATH --with-http_ssl_module > $INSTALL_FILE_DIR/nginx_configure.log 2> $INSTALL_FILE_DIR/nginx_configure.err
echo "Making..."
make > $INSTALL_FILE_DIR/nginx_make.log 2> $INSTALL_FILE_DIR/nginx_make.err
make install > $INSTALL_FILE_DIR/nginx_make_install.log 2> $INSTALL_FILE_DIR/nginx_make_install.err
echo "Make lib directory configuration file at $LIB_CONF_DIR"
echo "/usr/local/lib" > $LIB_CONF_DIR/nginx.conf
ldconfig
echo "Checking symbolic link at $NGINX_SYMBOLIC_LINK_DIR"
if [ -r $NGINX_SYMBOLIC_LINK_DIR ]
then
echo "symbolic link already exists!"
else
echo "Making symbolic link..."
ln -s /usr/local/nginx/sbin/nginx $NGINX_SYMBOLIC_LINK_DIR/nginx
fi
cd $NGINX_SYMBOLIC_LINK_DIR
./nginx
echo "All done! nginx has been started. enjoy it!"