A simple shell script that automatically installs LNMP

Source: Internet
Author: User
Tags curl diff fpm imagemagick ldap openssl readline openldap



This script has been used on the production server for more than a year, this script advocates simple aesthetics, only need a script to be able to automatically configure LNMP on any server with network.
This script will be used in the script execution directory to build the packages directory for storing the software required for LNMP. You can delete the directory after you install it.



How to use:
1. Save the contents of the shell script as nginx_php
2. Run under root privileges:
chmod u+x nginx_php; ./nginx_php init; ./nginx_php ins_mysql-server; ./nginx_php ins_mysql-client; ./nginx_php ins_php52; ./nginx_php ins_php52-ext; ./nginx_php ins_mysql



You need to enter a Y acknowledgment during the script run.



The shell script contents are as follows:


#/bash
# author:coralzd powered by www.freebsdsystem.org
# written by coralzd 2011.05.05
# version 0.1.3 build 20110505
nginx_dir="/usr/local/nginx"
php52_dir="/usr/local/php52"
mysql_dir="/usr/local/mysql"



function init()
{



LANG=C
yum -y install wget gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers



read -p "Now,will download nginxphp software...Y|y:" nginxphp



case "$nginxphp" in



Y|y)


echo-n "Starting download nginx_php ..."
cat > List << EOF &&
nginx-1.0.0.tar.gz
php-5.2.17.tar.gz
php-5.2.17-fpm-0.5.14.diff.gz
libiconv-1.13.1.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
memcache-2.2.5.tgz
mhash-0.9.9.9.tar.gz
mysql-5.1.52.tar.gz
pcre-8.10.tar.gz
eaccelerator-0.9.6.1.tar.bz2
pdo_mysql-1.0.2.tgz
libunwind-0.99.tar.gz
ImageMagick.tar.gz
imagick-2.3.0.tgz
google-perftools-1.6.tar.gz
fcgi.conf
php.ini
nginx.conf
php-fpm.conf
EOF
mkdir Packages
For i in ' Cat list '
Do
if [-S packages/$i]; Then
echo "$i [found]"
Else
echo "Error: $i not found!!! Download now ... "
wget http://www.freebsdsystem.org/linux/nginx-php/$i-P packages/
fi
Done
;;


*)



Echo-n "Exit Install script"
Exit 0
;;



Esac



Groupadd www && useradd www-s/sbin/nologin-g www
Groupadd MySQL && useradd mysql-s/sbin/nologin-g MySQL
echo "www and mysql user && group create!"



/BIN/RM-RF List



Echo-e "All of installed sucussful!"
}
function Is_version ()



{
If [' uname-m ' = = ' x86_64 '];then
Tar zxf libunwind-0.99.tar.gz
Tar zxvf libunwind-0.99.tar.gz
CD libunwind-0.99/
Cflags=-fpic./configure
Make Cflags=-fpic
Make Cflags=-fpic Install
Cd.. /
Else



echo "Your system is 32bit, not install Libunwind lib!"
Fi
}



function Ins_nginx ()



{



CD Packages



Is_version
Tar zxf google-perftools-1.6.tar.gz
CD google-perftools-1.6
./configure
Make
Make install



CD..
tar zxf pcre-8.10.tar.gz
cd pcre-*
./configure
make
make install
CD..
tar zxf nginx-1.0.0.tar.gz
CD nginx-1.0.0



Make && make install
Cd..
Rm-rf/usr/local/nginx/conf/nginx.conf
echo "/usr/local/lib" >/etc/ld.so.conf.d/usr_local_lib.conf
CP nginx.conf/usr/local/nginx/conf/
CP fcgi.conf/usr/local/nginx/conf/
echo "Nginx installed sucussfully!"



}
function Ins_mysql-server ()
{



cd packages/
tar zxf mysql-5.1.52.tar.gz
chost= "X86_64-pc-linux-gnu"
cflags= "-march=nocona-o2-pipe"
cxxflags= "${cflags}"
./configure "--prefix=${mysql_dir}" "-- With-server-suffix=-dzwww ""--with-mysqld-user=mysql ""--without-debug ""--with-charset=utf8 ""-- With-extra-charsets=all "--with-pthread" "--with-big-tables" "--enable-thread-safe-client" "--enable-assembler" "- -with-readline ""--with-ssl ""--enable-local-infile ""--WITH-PLUGINS=PARTITION,MYISAMMRG ""--without-ndb-debug "



make && make install
CP Support-*/mysql.server/etc/init.d/mysqld
cd/usr/local/mysql
chown-r mysql:mysql.
rm-rf sql-bench mysql-test
echo " MySQL server 5.1.52 installed successfully! "
}
function ins_mysql-client ()
{



cd packages/
tar zxf mysql-5.1.52.tar.gz
chost= "X86_64-pc-linux-gnu"
cflags= "-march=nocona-o2-pipe"
cxxflags= "${cflags}"
./configure "--prefix=${mysql_dir}" "-- With-mysqld-user=mysql ""--without-debug ""--with-charset=utf8 ""--with-extra-charsets=all ""--with-pthread ""-- With-big-tables ""--enable-thread-safe-client ""--enable-assembler ""--with-readline ""--with-ssl ""-- Enable-local-infile ""--without-server "



make && make install
cd/usr/ Local/mysql
chown-r mysql:mysql.
rm-rf sql-bench mysql-test
echo " MySQL client 5.1.52 installed successfully! "
}
function ins_php52 ()
Span style= "FONT-SIZE:16PX;" >{
tar zxf libiconv-1.13.1.tar.gz
./configure--prefix=/usr/local
make
make install
CD. /



Tar zxf 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.. /.. /



Tar zxf mhash-0.9.9.9.tar.gz
CD mhash-0.9.9.9/
./configure
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
ln-s/usr/local/lib/libmhash.a/usr/lib/libmhash.a
ln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.la
ln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.so
ln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2
ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1
ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config

tar zxf mcrypt-2.6.8.tar.gz
CD mcrypt-2.6.8/
/sbin/ldconfig
./configure
Make
Make Install
CD.. /
tar zxf php-5.2.17.tar.gz
GZIP-CD php-5.2.17-fpm-0.5.14.diff.gz | patch-d php-5.2.17-p1
CD php-5.2.17/
./configure--prefix=${php52_dir}--with-config-file-path=${php52_dir}/etc--with-mysql=${mysql_dir}-- With-mysqli=${mysql_dir}/bin/mysql_config--with-iconv-dir=/usr/local--with-freetype-dir--with-jpeg-dir-- With-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml--disable-rpath--enable-discard-path-- Enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--with-curl-- With-curlwrappers--enable-mbregex--enable-fastcgi--enable-fpm--enable-force-cgi-redirect--enable-mbstring-- With-mcrypt--with-gd--enable-gd-native-ttf--with-openssl--with-mhash--enable-pcntl--enable-sockets--with-ldap- -WITH-LDAP-SASL--with-xmlrpc--enable-zip--enable-soap
Make zend_extra_libs= '-liconv '
Make Install
CD..
CP php.ini/usr/local/php52/etc/
CP php-fpm.conf/usr/local/php52/etc/


echo "/usr/local/mysql/lib/mysql" >>/etc/ld.so.conf.d/mysql_lib.conf
/sbin/ldconfig
echo "Php52 installed successfully!"
}



function Ins_php52-ext ()



{
CD packages/



Tar zxf memcache-2.2.5.tgz
CD memcache-2.2.5/
${php52_dir}/bin/phpize
./configure--with-php-config=${php52_dir}/bin/php-config
Make
Make install
Cd.. /



Tar jxf eaccelerator-0.9.6.1.tar.bz2
CD EACCELERATOR-0.9.6.1/
${php52_dir}/bin/phpize
./configure--enable-eaccelerator=shared--with-php-config=${php52_dir}/bin/php-config
Make
Make install
Cd.. /



Tar zxf pdo_mysql-1.0.2.tgz
CD PDO_MYSQL-1.0.2/
${php52_dir}/bin/phpize
./configure--with-php-config=${php52_dir}/bin/php-config--with-pdo-mysql=${mysql_dir}
Make
Make install
Cd.. /



Tar zxf ImageMagick.tar.gz
CD imagemagick-6.5.1-2/
./configure
Make
Make install
Cd.. /



Tar zxf imagick-2.3.0.tgz
CD imagick-2.3.0/
${php52_dir}/bin/phpize
./configure--with-php-config=${php52_dir}/bin/php-config
Make
Make install
Cd.. /
echo "php52 extension installed successfully!"
}



Case $ in
Init



Init
;;
Ins_mysql-server)



Ins_mysql-server



;;
Ins_mysql-client)
Ins_mysql-client
;;
Ins_nginx)
Ins_nginx
;;
INS_PHP52)
Ins_php52
;;
Ins_php52-ext)
Ins_php52-ext
;;
*)





echo "Usage:`basename $0` {init|ins_mysql-server|ins_mysql-client|ins_php52|ins_php52-ext|ins_mysql}"
;;
esac



A simple shell script that automatically installs LNMP


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.