This script has been used on production servers for more than a year. It advocates simplicity and beauty. You only need one script to automatically configure LNMP on any network-Connected Server.
This script creates the packages directory under the script execution directory to store the software required by LNMP. After installation, you can delete the directory.
Usage:
1. Save the shell script content as nginx_php
2. Run the following command with the root permission:
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
Enter y for confirmation during script running.
The Shell script content is as follows:
#/bash# author:coralzd powered by www.freebsdsystem.org# written by coralzd 2011.05.05# version 0.1.3 build 20110505nginx_dir="/usr/local/nginx"php52_dir="/usr/local/php52"mysql_dir="/usr/local/mysql"function init(){LANG=Cyum -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-serversread -p "Now,will download nginxphp software...Y|y:" nginxphpcase "$nginxphp" inY|y)echo -n "starting download nginx_php ..."cat > list << "EOF" &&nginx-1.0.0.tar.gzphp-5.2.17.tar.gzphp-5.2.17-fpm-0.5.14.diff.gzlibiconv-1.13.1.tar.gzlibmcrypt-2.5.8.tar.gzmcrypt-2.6.8.tar.gzmemcache-2.2.5.tgzmhash-0.9.9.9.tar.gzmysql-5.1.52.tar.gzpcre-8.10.tar.gzeaccelerator-0.9.6.1.tar.bz2PDO_MYSQL-1.0.2.tgzlibunwind-0.99.tar.gzImageMagick.tar.gzimagick-2.3.0.tgzgoogle-perftools-1.6.tar.gzfcgi.confphp.ininginx.confphp-fpm.confEOFmkdir packagesfor i in `cat list`doif [ -s packages/$i ]; thenecho "$i [found]"elseecho "Error: $i not found!!!download now......"wget http://www.freebsdsystem.org/linux/nginx-php/$i -P packages/fidone;;*)echo -n "exit install script"exit 0;;esacgroupadd www && useradd www -s /sbin/nologin -g wwwgroupadd mysql && useradd mysql -s /sbin/nologin -g mysqlecho "www and mysql user && group create!"/bin/rm -rf listecho -e "All of installed sucussful!"}function is_version(){if [ `uname -m` == "x86_64" ];thentar zxf libunwind-0.99.tar.gztar zxvf libunwind-0.99.tar.gzcd libunwind-0.99/CFLAGS=-fPIC ./configuremake CFLAGS=-fPICmake CFLAGS=-fPIC installcd ../elseecho "your system is 32bit ,not install libunwind lib!"fi}function ins_nginx(){cd packagesis_versiontar zxf google-perftools-1.6.tar.gzcd google-perftools-1.6./configuremakemake installcd ..tar zxf pcre-8.10.tar.gzcd pcre-*./configuremakemake installcd ..tar zxf nginx-1.0.0.tar.gzcd nginx-1.0.0./configure --prefix=${nginx_dir} --with-google_perftools_module --user=www --group=www --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module
make && make installcd ..rm -rf /usr/local/nginx/conf/nginx.confecho "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.confcp 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.gzcd mysql-5.1.52CHOST="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 installcp support-*/mysql.server /etc/init.d/mysqldcd /usr/local/mysqlchown -R mysql:mysql .rm -rf sql-bench mysql-testecho "mysql server 5.1.52 installed successfully!"}function ins_mysql-client(){cd packages/tar zxf mysql-5.1.52.tar.gzcd mysql-5.1.52CHOST="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 installcd /usr/local/mysqlchown -R mysql:mysql .rm -rf sql-bench mysql-testecho "mysql client 5.1.52 installed successfully!"}function ins_php52(){cd packages/tar zxf libiconv-1.13.1.tar.gzcd libiconv-1.13.1/./configure --prefix=/usr/localmakemake installcd ../tar zxf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremakemake install/sbin/ldconfigcd libltdl/./configure --enable-ltdl-installmakemake installcd ../../tar zxf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremakemake installcd ../ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-configtar zxf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremakemake installcd ../tar zxf php-5.2.17.tar.gzgzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1cd 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 installcd ..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/ldconfigecho "php52 installed successfully!"}function ins_php52-ext(){cd packages/tar zxf memcache-2.2.5.tgzcd memcache-2.2.5/${php52_dir}/bin/phpize./configure --with-php-config=${php52_dir}/bin/php-configmakemake installcd ../tar jxf eaccelerator-0.9.6.1.tar.bz2cd eaccelerator-0.9.6.1/${php52_dir}/bin/phpize./configure --enable-eaccelerator=shared --with-php-config=${php52_dir}/bin/php-config
makemake installcd ../tar zxf PDO_MYSQL-1.0.2.tgzcd PDO_MYSQL-1.0.2/${php52_dir}/bin/phpize./configure --with-php-config=${php52_dir}/bin/php-config --with-pdo-mysql=${mysql_dir}
makemake installcd ../tar zxf ImageMagick.tar.gzcd ImageMagick-6.5.1-2/./configuremakemake installcd ../tar zxf imagick-2.3.0.tgzcd imagick-2.3.0/${php52_dir}/bin/phpize./configure --with-php-config=${php52_dir}/bin/php-config
makemake installcd ../echo "php52 extension installed successfully!"}case $1 ininit)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