One-click installation of the LAMP environment using Shell scripts

Source: Internet
Author: User
Tags mcrypt
LAMP refers to the web servers built in Linux (operating system), Apache (HTTP server), MySQL (database software), and PHP. This website architecture is currently a popular and common Web architecture. It has advantages such as LAMP cross-platform and high performance. It is the preferred platform for many enterprises and companies to build WEB Services. 1) System Environment Introduction Centos5.864-bit Apache: httpd-2.4.4.

LAMP refers to the web servers built in Linux (operating system), Apache (HTTP server), MySQL (database software), and PHP. This website architecture is currently a popular and common Web architecture. It has advantages such as LAMP cross-platform and high performance. It is the preferred platform for many enterprises and companies to build WEB Services.

1) System Environment Introduction
Centos 5.8 64-bit
Apache: httpd-2.4.4.tar.gz
PHP: php-5.4.17.tar.gz
Mysql: mysql-5.6.12.tar.gz

2) installation script

#! /Bin/bashPATH =/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin: /binexportPATH # The INFO function defines the color of the output font. echo-e indicates the special meaning of the string, $1 indicates the font color number, and $2 indicates the waiting time for the program to run, $3 indicates the echo output content. FunctionINFO () {echo-e "\ e [$1; 49; 1 m: $3 \ 033 [39; 49; 0 m "sleep" $2 "echo" "} # non-root users cannot execute this script if [" $ UID "! = 0]; thenecho "" INFO 35 "0" "Must be root ro run this script. "exit1fi # USAGE function defines script USAGE and can be called repeatedly. basename is actually the Script Name, and \ n indicates line feed. FunctionUSAGE () {INFO 35 "0.1" "Please see the script of the usage:" basename = $ (basename "$0 ") INFO \ 36 "0" \ "$ (echo-e" Usage: \ n. /$ basename (apache | mysql | php) install \ n. /$ basenameapache (start | stop | restart) \ n. /$ basenamemysql (start | stop | restart) \ n ")"} # Install the YUM_INSTALL function dependency package, which can be called repeatedly, $ @ indicates that all parameters are enclosed by double quotation marks "$1", "$2 ", $ * indicates that all these parameters are enclosed in double quotes "$1 $2" functionYUM_INSTALL () {fora in $ @; doINFO 32 1 "Install depend on the [$ a]" Yum-y install $ a | exit1if [$ a = "libXpm-devel"]; thenln-s/usr/lib/x86_64-linux-gnu/libXpm. so/usr/lib/libXpm. so # elif [$ a = "libsasl2-dev"]; then # cp/usr/lib/x86_64-linux-gnu/libldap */usr/lib/fidone} # INSTALL Function Definition installer, it can be called repeatedly. Three dependency packages must be installed before the apache program is installed, and cmake must be used for compiling mysql. $1 indicates the program to be installed, $2 indicates that yum installs the corresponding dependent package, $3 indicates the directory after the program is decompressed, and $4 indicates the program source code package. FunctionINSTALL () {YUM_INSTALL "$2" & cd $ SOURCE_PATH [-d $3] & rm-r $3; INFO 31 4 "Unpack the $4 installation package ...... "tarzxvf $4; cd $3; pwd; INFO 32 4" Configure the $1 ...... "if [$1 = apache]; thencp-rf .. apr-1.4.8 srclib/aprcp-rf .. apr-util-1.5.2 srclib/apr-util. /configure $5 | exit1elif [$1 = mysql]; thencmake $5 | exit1elif [$1 = openssl]; then. /config $5 | exit1elif [$1 = libpng]; th Encpscripts/makefile. linux makefileelif [$1 = javassrc.v6b.tar.gz]; thencp/usr/share/libtool/config. guess. /cp/usr/share/libtool/config. sub. /. /configure $5 | exit1mkdir-p/usr/local/env/jpeg/binmkdir-p/usr/local/env/jpeg/libmkdir-p/usr/local/env/jpeg/ includemkdir-p/usr/local/env/jpeg/man/man1else. /configure $5 | exit1fiINFO 36 3 "Compile $1 ...... "make | exit1 & INFO 34 4" Install $1 ...... "; ma Keinstall & INFO 33 4 "$1 installation is successful ...... "if [$1 = mysql]; thenecho $ INSTALL_PATH/mysql/lib/mysql>/etc/ld. so. conf/sbin/ldconfig & INFO 33 4 "Add $1 library file to ld. so. conf ...... "fiif [$1 = libiconv]; thenecho"/usr/local/env/libiconv/lib ">/etc/ld. so. conf/sbin/ldconfig & INFO 33 4 "Add $1 library file to ld. so. conf ...... "fiif [$1 = libxml2]; thenecho"/usr/local/env/libxml2/lib ">/Etc/ld. so. conf/sbin/ldconfig & INFO 33 4 "Add $1 library file to ld. so. conf ...... "fiif [$1 = libmcrypt]; thenecho"/usr/local/env/libmcrypt/lib ">/etc/ld. so. conf/sbin/ldconfig & INFO 33 4 "Add $1 library file to ld. so. conf ...... "fiif [$1 = mhash]; thenecho"/usr/local/lib ">/etc/ld. so. confecho "/usr/local/lib64">/etc/ld. so. conf/sbin/ldconfig & INFO 33 4 "Add $1 library file to ld. so. conf .... .. "Fiif [$1 = gettext]; thenecho"/usr/local/env/gettext/lib ">/etc/ld. so. conf/sbin/ldconfig & INFO 33 4 "Add $1 library file to ld. so. conf ...... "fiif [$1 = gd]; thensed-I '27 a void (* data ); '/usr/local/env/gd/include/gd_io.hecho "/usr/local/env/gd/lib">/etc/ld. so. conf/sbin/ldconfig & INFO 33 4 "Add $1 library file to ld. so. conf ...... "fiif [$1 = freetype]; thenecho"/usr/local/env/freetype/lib "> /Etc/ld. so. conf/sbin/ldconfig & INFO 33 4 "Add $1 library file to ld. so. conf ...... "fiif [$1 = export src.v6b.tar.gz]; thenecho"/usr/local/env/jpeg/lib ">/etc/ld. so. conf/sbin/ldconfig & INFO 33 4 "Add jpeg library file to ld. so. conf ...... "fi} # SERVICE function definition program starts, closes, and restarts. FunctionSERVICE () {if [$1 = apache-a $2 = start]; then $ INSTALL_PATH/$1/bin/apachectl-k start & \ INFO 33 "2.5" "Apache startup success ...... "exitelif [$1 = apache-a $2 = stop]; then $ INSTALL_PATH/$1/bin/apachectl-k stop & \ INFO 31 "2.5" "Apache has stopped ...... "exitelif [$1 = apache-a $2 = restart]; then $ INSTALL_PATH/$1/bin/apachectl-k stop; sleep2INFO 31 "2.5" "Apache has stopped ...... "$ INSTAL Rochelle path/$1/bin/apachectl-k start & \ INFO 34 "2.5" "Apache has restarted ...... "exitelif [$1 = mysql-a $2 = start]; then/bin/bash $ INSTALL_PATH/$1/bin/mysqld_safe -- defaults-file = $ INSTALL_PATH/$1/my. cnf 2> & 1>/dev/null & INFO 33 "2.5" "Mysql startup success ...... "echo-e" $ (netstat-ntpl | grep "/: 3306") "exitelif [$1 = mysql-a $2 = stop]; thenkill $ (netstat-ntpl | awk '/: 3306/{print $ NF}' | awk-F'/''{pri Nt $1} ') & \ INFO 31 "2.5" "Mysql has stopped ...... "exitelif [$1 = mysql-a $2 = restart]; thenkill $ (netstat-ntpl | awk '/::: 3306/{print $ NF} '| awk-F'/''{print $1 }') & \ INFO 31 "3" "Mysql has stopped ...... "/bin/bash $ INSTALL_PATH/$1/bin/mysqld_safe -- defaults-file = $ INSTALL_PATH/$1/my. cnf 2> & 1>/dev/null & INFO 34 "2.5" "Mysql has restarted ...... "exitfi} # The CONFIG_MYSQL function is used to define the mysql configuration. FunctionCONFIG_MYSQL () {INFO 32 3 "Configure the mysql ...... "groupsmysql | groupadd mysql & idmysql | useradd-g mysql mysqlcd $ INSTALL_PATH/mysql; pwd. /scripts/mysql_install_db \ -- user = mysql \ -- basedir = $ INSTALL_PATH/mysql/\ -- datadir = $ INSTALL_PATH/mysql/data/\ -- defaults-file = $ INSTALL_PATH/mysql/ my. cnfecho ""; sleep3cp $ (dirname $ SOURCE_PATH)/conf/my. cnf. /INFO 35 2 "Mysql configuration is complete ...... "} # The CONFIG_HTTPD function is used to configure apache. FunctionCONFIG_HTTPD () {INFO 32 3 "Configure the apache ......" echo-e"
 "> $ INSTALL_PATH/apache/htdocs/phpinfo. phpsed-I's/^ \\\\ AddType application \/x-gzip. gz. tgz $/& \ n \\\\ AddType application \/x-httpd-php. php/'\ $ INSTALL_PATH/apache/conf/httpd. confsed-I's/^ # ServerName www.example.com: 80 $/& \ nServerName 127.0.0.1: 80/'$ INSTALL_PATH/apache/conf/httpd. confINFO 35 2 "Apache configuration is complete ...... "} # The CONFIG_PHP function is used to configure php. FunctionCONFIG_PHP () {INFO 32 3 "Configure the php ...... "cp $ SOURCE_PATH/$1/php. ini-development $ INSTALL_PATH/php5/etc/php. iniINFO 35 2 "Php configuration is complete ...... "} # INSTALL_BRANCH Function Definition program installation, $ {TAR_NAME [@]} is an array written in shell scripts, that is, all elements are taken, that is, all packages in TAR_NAME, SERVER_NAME indicates the package name, And COMPILE_DIR indicates the package name + version, that is, the decompressed directory name. FunctionINSTALL_BRANCH () {fori in $ {TAR_NAME [@]}; doSERVER_NAME = $ (echo $ I | awk-F "-[0-9]" '{print $1 }') COMPILE_DIR = $ (echo $ I | awk-F ".tar.gz" '{print $1}') if [$1 = $ SERVER_NAME-a $1 = apr]; thenINSTALL apr "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/apr" elif [$1 = $ SERVER_NAME-a $1 = apr-util ]; thenINSTALL apr-util "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/apr-util -- with-apr =/usr/local/env/ apr "el If [$1 = $ SERVER_NAME-a $1 = pcre]; thenINSTALL pcre "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/pcre" elif [$1 = $ SERVER_NAME-a $1 = httpd]; thenINSTALL apache "$ HTTP_YUM" "$ COMPILE_DIR" "$ I" "$ HTTP_PARAMETERS" CONFIG_HTTPDelif [$1 = $ SERVER_NAME-a $1 = mysql]; thenINSTALL mysql "$ MYSQL_YUM" "$ COMPILE_DIR" "$ I" "$ MYSQL_PARAMETERS" CONFIG_MYSQLelif [$1 = $ SERVER_NAME-a $1 = libiconv]; thenINSTALL Libiconv "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/libiconv" elif [$1 = $ SERVER_NAME-a $1 = libxml2]; thenINSTALL libxml2 "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/libxml2 -- with-iconv =/usr/local/env/libiconv" elif [$1 = $ SERVER_NAME-a $1 = curl]; thenINSTALL curl "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/curl -- enable-utf8" elif [$1 = $ SERVER_NAME-a $1 = libmcrypt ]; thenINSTALL li Bmcrypt "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/libmcrypt" elif [$1 = $ SERVER_NAME-a $1 = mhash]; thenINSTALL mhash "$ COMPILE_DIR" "$ I" "elif [$1 = $ SERVER_NAME-a $1 = mcrypt]; thenINSTALL mcrypt "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/mcrypt \ -- with-libmcrypt-prefix =/usr/local/env/mlibcrypt \ -- with-libiconv-prefix =/usr/local/env/libiconv "elif [$1 = $ SERVER_NAME-a $1 = gettext]; ThenINSTALL gettext "" $ COMPILE_DIR "" $ I "" -- prefix =/usr/local/env/gettext \ -- with-libiconv-prefix =/usr/local/env/libiconv \ -- with-libxml2-prefix =/usr/local/env/libxml2 "elif [$1 = $ SERVER_NAME-a $1 = freetype]; thenINSTALL freetype "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/freetype" elif [$1 = $ SERVER_NAME-a $1 = jpegsrc.v6b.tar.gz]; thenCOMPILE_DIR = "jpeg-6b" INSTALL composer src.v6b.tar.gz "" $ COM PILE_DIR "" $ I "" -- prefix =/usr/local/env/jpeg -- enable-shared -- enable-static "elif [$1 = $ SERVER_NAME-a $1 = libpng ]; thenINSTALL libpng "" $ COMPILE_DIR "" $ I "" elif [$1 = $ SERVER_NAME-a $1 = gd]; thenINSTALL gd "$ COMPILE_DIR" "$ I" "-- prefix =/usr/local/env/gd -- with-png =/usr \ -- with-freetype =/usr/ local/env/freetype \ -- with-jpeg =/usr/local/env/jpeg -- with-fontconfig =/usr -- with-xpm =/usr "elif [$1 = $ SE RVER_NAME-a $1 = openssl]; thenINSTALL openssl "$ COMPILE_DIR" "$ I" "-fPIC -- prefix =/usr/local/env/openssl shared" elif [$1 = $ SERVER_NAME-a $1 = php]; thenINSTALL php5 "$ PHP5_YUM" "$ COMPILE_DIR" "$ I" "$ PHP5_PARAMETERS" CONFIG_PHP "$ COMPILE_DIR" breakelsecontinuefidone} # The MOD_CASE function selects the installer using the KASE definition. FunctionMOD_CASE () {if [[$1 = ~ Apache | mysql | php] & [[$2 = ~ Install | start | stop | restart]; thenINFO 32 "1.5" Input the correct, according to the option to perform related operations ...... "echo" "if [$2 = install]; thencase" $1 $2 "in" apache install ") INFO 35 "2.5" "Start to $1 the $2 ...... "INSTALL_BRANCH aprINSTALL_BRANCH apr-utilINSTALL_BRANCH pcreINSTALL_BRANCH httpd;" mysql install ") INFO 35" 2.5 "" Start to $1 the $2 ...... "INSTALL_BRANCH mysql;" php install ") IN FO 35 "2.5" "Start to $1 the $2 ...... "exportLD_LIBRARY_PATH =/lib/:/usr/local/lib: /usr/local/lamp/mysql/libINSTALL_BRANCH implements libxml2INSTALL_BRANCH implements mhashINSTALL_BRANCH mcryptINSTALL_BRANCH gettextINSTALL_BRANCH implements INSTALL_BRANCH libpngINSTALL_BRANCH gdINSTALL_BRANCH openssl # INSTALL_BRANCH Tpd & INSTALL_BRANCH mysql & INSTALL_BRANCH phpINSTALL_BRANCH php; esacelseSERVICE $1 $2 fielseINFO 31 1 "Input error, please try again! "INPUTfi} # LAMP installation directory INSTALL_PATH ="/usr/local/lamp "# source code package storage directory SOURCE_PATH =" $ (cd $ (dirname $0); pwd) /install_tar "character source code package character tar_name1_(httpd-2.4.tar.gz mysql-5.6.12.tar.gz php-5.4.17.tar.gz apr-1.4.8.tar.gz apr-util-1.5.2.tar.gz pcre-8.10.tar.gz freetype-2.4.0.tar.gz libxml2-2.7.2.tar.gz mhash-0.9.9.9.tar.gz mcrypt-2.6.8.tar.gz gd-2.0.35.tar.gz libiconv-1.14.tar.gz # Apache, Mysql, PHP yum install dependency package HTTP_YUM = "build-essential libapr1 libapr1-dev libaprutil1 libaprutil1-dev gettext-devel" plugin = "cmake libncurses5 libncurses5-dev bison" plugin = "libxml2 libxml2-devel openssl liblib- devel bzip2 libXpm- devel libmcrypt-devel "# HTTP_PARAMETERS =" \ -- prefix = $ INSTALL_PATH/Apache \ -- enable-module = so \ -- enable-module = rewrite \ -- enable-shard = rewrite \ -- enable-shared = max \ -- with-apr =/usr/local/env/apr \ -- with-apr-util =/usr/local/env/apr-util \ -- with-pcre =/usr/local/env/pcre \ -- with-encoded-apr \ "# mysql compilation parameter MYSQL_PARAMETERS =" \-DCMAKE_INSTALL_PREFIX = $ INSTALL_PATH/mysql \- DYSQL_TCP_PORT = 3306 \-DMYSQL_DATADIR = $ INSTALL_PATH/mysql/data \-DMYSQL_UNIX_ADDR = $ INSTALL_PAHT/mysql. sock \-keys = 1 \-keys = 1 \-DDEFAULT_CHARSET = utf8 \-DDEFAULT_COLLATION = utf8_general_ci \-DEXTRA_CHARSETS = all \-DWITH_DEBUG = 0 \ "# PHP compilation parameter PHP5_PARAMETERS =" \ -- prefix = $ INSTALL_PATH/php5 \ -- with-config-file-path = $ INSTALL_PATH/php5/etc \ -- with-mysql = $ INSTALL_PATH/mysql \ -- with-apxs2 = $ INSTALL_PATH /apache/bin/apxs \ -- with-mysqli = $ INSTALL_PATH/mysql/bin/mysql_config \ -- with-iconv =/usr/local/env/libiconv \ -- with-jpeg- dir =/usr/local/env/jpeg \ -- with-png-dir =/usr \ -- with-libxml-dir =/usr/local/env/libxml2 \ --- pdo-mysql \ -- with-zlib \ -- with-curl =/usr/local/env/curl \ -- with-curlwrappers \ -- with-mcrypt =/usr/local/env/ libmcrypt \ -- with-gd =/usr/local/env/gd \ -- with-openssl =/usr/local/env/openssl \ -- with-mhash =/usr \ -- -xmlrpc \ -- with-xpm-dir \ -- with-freetype-dir =/usr/local/env/freetype \ -- with-zlib-dir \ -- with-ldap \ -- -ldap-sasl \ -- with-pcre-regex \ -- with-gettext =/usr/local/env/gettext \ -- with-ncurses \ -- enable-shared \ -- enable-xml \ -- enable-safe-mode \ -- enable-track-vars \ -- enable-magic-quotes \ -- enable-bcmath \ -- enable-sysvsem \ -- enable-sysshm \ -- enable- inline-optimization \ -- enable-mbregex \ -- enable-mbstring \ -- enable-gd-native-ttf \ -- enable-pcntl \ -- enable-sockets \ -- enable-zip \ -- enable -soap \ -- enable-discard-path \ -- enable-force-cgi-redirect \ -- enable-pdo \ -- enable-calendar \ -- enable-exif \ -- enable-zend-multibyte \ "# -- disable-rpath # script call help program if [$ # = 2] thenINFO 33" 1.5 "" please wait ...... "echo" "MOD_CASE" $1 "" $2 "elseUSAGEexit1fi


3) script usage

# Download the installation script and source package wget https://sourceforge.net/projects/opensourcefile/files/Install_Centos_LAMP_v.0.1.zip/download--no-check-certificateunzip Install_Centos_LAMP_v.0.1.zipchmod + x Install_Centos_LAMP_v.0.1.sh # view the script usage, you can install apache, mysql, php, start, close and restart apache and mysql through this script .. /Install_Centos_LAMP_v.0.1.sh: Please see the script of the usage: Usage :. /Install_Centos_LAMP_v.0.1.sh (apache | mysql | php) install. /Install_Centos_LAMP_v.0.1.sh apache (start | stop | restart ). /Install_Centos_LAMP_v.0.1.sh mysql (start | stop | restart)


This script applies functions in Shell programming, such as functions, arrays, process control, variables, and font brightening. It is helpful to those who want to learn WEB and Shell programming, finally, I would like to thank my classmates for their support. This article from the "simple dream catcher" blog, please be sure to keep this source http://sfzhang88.blog.51cto.com/4995876/1281640


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.