#!/bin/bash#subject  : One-click Installation Lamp (apache + mysql + php) #Date :2016-06-08# definition software Download directory: softdir= '/usr/local/src ' #定义编译函数: Function make () { if [ ' echo $? ' -eq 0 ];then make else exit fi}# Define the installation function: Function make_ins () { if [ ' echo $? ' -eq 0 ];then make install else exit &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;FI} #第一部分: Configuration of the system infrastructure: #判断当前用户是否为root:if [ ' whoami ' = ' Root " ];then echo "Root" else echo "Please use root privileges " exitfi# determine if the current network is unblocked: net= ' ping -c 4 www.qq.com |grep received |awk ' {print $6} ' |sed -e ' s/ %//' if [ $NET -ge 2 ];then echo "Please check your network" exitfi# configuration ps Environment:if [ -z ' egrep -i ps1 /etc/profile |awk ' {print $1} ' ]; then echo ' ps1= ' \[\e[33;1m\][\[email protected]\[\e[ 31;1m\]\h \t \# \w]\\$\[\e[m\] " >> /etc/profile source /etc/profilefi# to see if the system encoding is EN _us. utf-8lang= ' grep -i lang /etc/sysconfig/i18n |awk -f ' ' ' {print $2} ' if [ $lang != ' en_US. UTF-8 ' ];then sed -i " s/$lang/en_us. utf-8/" i18nfi# do this machine hosts analysis: eth= ' egrep -i device /etc/sysconfig/network-scripts/ ifcfg-eth0 |awk -f ' = ' ' {print $2} ' if [ -z ' Egrep -i $ (echo $HOSTNAME) /etc/hosts |awk ' {print $2} ' ];then echo $ (ip ad |grep "global $ETH" |awk -F "/" ' {print $1} ' |awk ' {print $2} ' && echo $ HOSTNAME) >> /etc/hostsfi# off selinux:sed -i ' s/selinux=enforcing/selinux=disabled/' /etc/selinux/config# Turn off reverse parsing:sed -i ' s/^ #UseDNS yes/usedns no/' /etc/selinux/ config# Restart sshd service: service sshd restart# system tuning to increase the number of system files and the number of processes to 65535cat <<eof > > /etc/security/limits.conf* soft nproc 65535* soft nproc 65535* soft nofile 65535* hard nofile 65535eof# or use sed to insert into the specified line #sed -i "49i* soft nproc 65535\n* soft nproc 65535\n* soft nofile 65535\n* hard nofile 65535 " /etc/security/limits.confsed -i ' s/^root/#root/' /etc/security/limits.d/90- nproc.conf sed -i ' s/1024/65535/' /etc/security/limits.d/90-nproc.conf sed -i "6i* hard nporc 65535 " /etc/security/limits.d/90-nproc.conf #安装系统扩展源:/http dl.fedoraproject.org/pub/epelif [ ' awk ' {print $3} ' /etc/redhat-release |awk -F '. ' ' {print $1} ' -eq 6 ];then rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/ epel-release-6-8.noarch.rpm elif [ ' awk ' { print $4} ' /etc/redhat-release |awk -F '. ' ' {print $1} ' -eq 7 ];then rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/ epel-release-7-5.noarch.rpm fi# Installing the LANMP Dependent Component pack: yum install -y lrzsz gcc gcc-c++ perl perl-devel bzip2 bzip2-devel make man vim tree unzip wget lua-devel lua-static patch libxml2 libxml2-devel libxslt liBxslt-devel gd gd-devel ntp screen sysstat rsync lsof gettext gettext-devel autoconf automake libtool git openssl openssl-devel curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel perl-data-dumper# Upgrade System:yum update -y #第二部分: Install lamp#========================== ======mysql installation configuration #================================cd $SoftDir && wget -q http://mirrors.sohu.com/mysql/mysql-5.6/mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz# Decompression:tar zxf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz# Mobile Decompression Directory seriously named Mysql:mv mysql-5.6.30-linux-glibc2.5-x86_64 /usr /local/mysql# Add mysql System User:if [ -z ' grep mysql /etc/passwd ' ] ;then useradd -s /sbin/nologin mysqlfi# Creating mysql Initialize Data directory:if [ ! -d "/data/mysql " ] ;then mkdir -p /data/mysqlfi #将mysql Initialize directory owner and group modified to mysql:chown -r mysql.mysql /data/mysql/#初始化cd $MysqlS & & ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql #备份系统默认的my .cnf File: Mv /etc/my.cnf{,.bak} #复制mysql main profile to etc directory seriously ill named my.cnf \cp support-files/ my-default.cnf /etc/my.cnf# Copy the mysql startup script to the/etc/init.d directory: \cp support-files/ mysql.server /etc/init.d/mysqld# Give start 755 permission: chmod 755 /etc/init.d/mysqld# Modify my.cnf The file is configured as follows: cat << eof > /etc/my.cnf[mysqld]pid-file=/data/mysql/mysql.pidlog-error=/ Var/log/mysql.logdatadir = /data/mysqlbasedir = /usr/local/mysqlcharacter-set-server= Utf8port = 3306socket = /tmp/mysql.sockkey_buffer_size = 256mmax_allowed_packet = 1mtable_open_cache = 256sort_buffer_size = 1mread_buffer_size = 1mread_rnd_buffer_size = 4mmyisam_sort_buffer_size = 64mthread_cache_size = 8query_cache_size = 16mthread _concurrency = 8binlog_format=mixedserver-id = 1slow-query-log = 1slow-query-log-file = /data/mysql/mysql-slow.loglog-bin = mysql-binlog-bin-index = mysql-bin.indexsymbolic-links = 0skip-name-resolve[client]port = 3306socket = /tmp/mysql.sockdefault-character-set=utf8[mysqldump]quickmax_allowed_packet = 16m#[mysqld_safe ][mysql]no-auto-rehash[myisamchk]key_buffer_size = 128msort_buffer_size = 128mread_buffer = 2mwrite_buffer = 2m[mysqlhotcopy]interactive-timeouteof# Start Mysql:service mysqld startif [ ' echo $? ' -eq 0 ] ;then echo "Mysql stArted "else exitfi# set mysqld to random start: Chkconfig --add mysqld && chkconfig mysqld on#================================apr , apr-util , libmcrypt and pcre ================================cd $SoftDirwget -q http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz# decompression: tar zxf apr-1.5.2.tar.gz# into the Extract directory:cd apr-1.5.2 && ./configure --prefix=/usr/local/apr# Compiling and installing Make && make_ inscd $SoftDirwget -q http://mirrors.noc.im/apache//apr/apr-util-1.5.4.tar.gztar zxf apr-util-1.5.4.tar.gzcd ./apr-util-1.5.4 && ./configure --prefix=/usr/local/ apr-util --with-apr=/usr/local/apr# compiling and installing make && make_inscd $SoftDir wget -q ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gztar zxf Libmcrypt-2.5.7.tar.gzcd libmcrypt-2.5.7 && ./configure --prefix=/usr/local/libmcrypt #编译及安装MAKE & & MAKE_INScd $SoftDirwget &NBSP;-Q&NBSP;HTTP://EXIM.MIRROR.FR/PCRE/PCRE-8.37.TAR.GZTAR&NBSP;ZXF pcre-8.37.tar.gzcd pcre-8.37 && ./configure --prefix=/usr/local/pcre #编译及安装MAKE && MAKE_INScd $SoftDirwget -q http://zlib.net/ zlib-1.2.8.tar.gztar zxf zlib-1.2.8.tar.gzcd zlib-1.2.8 && ./configure - -prefix=/usr/local/zlib# Compiling and installing:make && make_ins#================================apache The installation configuration ================================cd $SoftDir && wget -q http:// mirrors.sohu.com/apache/httpd-2.4.18.tar.gz# decompression apache:tar zxf httpd-2.4.18.tar.gz# into the Extract directory:cd httpd-2.4.18# Configuration Compilation parameters:./configure --prefix=/usr/local/apache2 -enable-so -- Enable-mods-shared=all --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre=/usr/local/pcre/ --with-apr=/usr/local/ apr --with-apr-util=/usr/local/apr-util --with-z=/usr/local/zlib #编译简装:make && MAKE_INS#================================php Installation Configuration ================================cd $SoftDir && wget -q http://mirrors.sohu.com/php/php-5.5.30.tar.gz# Decompression:tar -zxf php-5.5.30.tar.gzcd php-5.5.30 && ./configure --prefix=/usr/local/php -- With-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql =/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir -- with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt=/usr/local/libmcrypt --enable-soap - -enable-gd-native-ttf --Enable-mbstring --enable-sockets --enable-exif --disable-ipv6 --with-pear --with-curl --with-openssl --with-mysqli --enable-mysqlnd --with-gettext --enable-bcmath --enable-sockets #编译及安装MAKE && MAKE_INS sed -i ' s/directoryindex index.html/directoryindex index.html index.php/' /usr/local/ apache2/conf/httpd.confsed -i ' s/^ #ServerName www.example.com:80/servername localhost:80/' /usr/local/apache2/conf/httpd.confsed -i "392i addtype application/x-httpd-php . php " /usr/local/apache2/conf/httpd.conf# Open the firewall on port 80 iptables -i input 2 -p tcp --dport 80 -j accept && service iptables save# Test apache Is the configuration wrong/usr/local/apache2/bin/apachectl -tif [ ' echo $? ' -ne 0 ];then exitfi#================================ xcache installation configuration ================================cd $SoftDir && wget -q http:/ /xcache.lighttpd.net/pub/releases/3.2.0/xcache-3.2.0.tar.gz# Decompression: tar zxf xcache-3.2.0.tar.gz # Go to unzip directory, clear phpizecd xcache-3.2.0 && /usr/local/php/bin/phpize --clean# execute phpize, Production xcache configuration file:/usr/local/php/bin/phpize #配置编译参数:./configure --enable-xcache -- with-php-config=/usr/local/php/bin/php-config #编译及安装MAKE && make_ins# Copy the php.ini-production from the PHP source package to the /usr/local/php/etc directory and rename it to php.ini \cp /usr/local/src/ php-5.5.30/php.ini-production /usr/local/php/etc/php.ini# Add the XCache library file to the php.ini file echo " Extemsiobn_dir= '/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/' " >> /usr/local/ php/etc/php.ini echo "Extension=xcache.so" >> /usr/local/php/etc/php.ini# Start apache:/usr/local/apache2/bin/apachectl -k restart# Rename Apache Default Home Index.html:mv /usr/local/apache2/htdocs/index.html{,.bak} #新建php探针测试页面, test Apache parsing php:echo "<?php echo phpinfo (); ?>" > /usr/local/apache2/htdocs/ index.php# add apache to the system environment variable:cd /etc/profile.d/touch httpd.shecho "export PATH= $PAHT :/usr/local/apache2/bin " > /etc/profile/httpd.shsource /etc/profile/httpd.sh
This article is from the "Boyhack" blog, make sure to keep this source http://461205160.blog.51cto.com/274918/1789326
Lamp One-click installation script