标签:shell lamp apache php httpd mysql
#!/bin/bash read -p "the script will be installlamp,if you want to continue ,press yes :" press if [ $press == yes ];then echo"lamp(mysql-5.6.24,httpd-2.4.12,php-5.6.10) will be install in aminute..." sleep 10 check_ok(){ if [ ! $? == 0 ] then echo"error,check the error log." exit 1 fi } yum_install(){ if rpm -qa|grep -q "^$1" then echo "$1 is already installed !" else yum install -y $1 check_ok fi } check_service(){ s=`ps aux|grep $1|wc -l` if [ $s -gt 1 ] then echo "$1 is already installed!" elif [ -f /etc/init.d/$1 ] then /etc/init.d/$1 start check_ok else install_$1 fi } for i in wget vim-enhanced;do yum_install $i done ar=`/bin/arch` iptables-save > /root/myiptables.rule iptables -F service iptables save sed -i‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config setenforce 0 rpm -e epel-release wget -P /etc/yum.repos.d/http://mirrors.aliyun.com/repo/epel-6.repo yum clean all yum makecache check_ok install_mysqld(){ for i in libaio libaio-devel;do yum_install $i done check_ok cd /usr/local/src [ -f mysql-5.6.24-linux-glibc2.5-$ar.tar.gz] || wgethttp://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.24-linux-glibc2.5-$ar.tar.gz check_ok /bin/tar -zxvfmysql-5.6.24-linux-glibc2.5-$ar.tar.gz check_ok [ -d /usr/local/mysql ] && /bin/mv/usr/local/mysql /usr/local/mysql_bak /bin/mv mysql-5.6.24-linux-glibc2.5-$ar/usr/local/mysql check_ok id mysql &> /dev/null || useradd -r-s /sbin/nologin mysql cd /usr/local/mysql chown -R mysql:mysql . [ -d /data/mysql ] && /bin/mv/data/mysql /data/mysql_bak mkdir -p /data/mysql && chown -Rmysql:mysql /data/mysql ./scripts/mysql_install_db --user=mysql--datadir=/data/mysql/ check_ok chown -R root . /bin/cp support-files/my-default.cnf/etc/my.cnf check_ok sed -i ‘/^\[mysqld\]$/a\datadir =/data/mysql‘ /etc/my.cnf /bin/cp support-files/mysql.server/etc/init.d/mysqld sed -i ‘s#^datadir=#datadir=/data/mysql#‘/etc/init.d/mysqld chmod 755 /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on service mysqld start check_ok echo "exportPATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile source /etc/profile } #check_service mysqld install_httpd(){ for j in gcc pcre-devel openssl-devel;do yum_install $j done check_ok cd /usr/local/src [ -f apr-1.5.2.tar.gz ] ||wgethttp://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz check_ok [ -f apr-util-1.5.4.tar.gz ] ||wgethttp://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz check_ok [ -f httpd-2.4.12.tar.bz2 ] ||wgethttp://mirrors.cnnic.cn/apache//httpd/httpd-2.4.12.tar.bz2 check_ok tar zxvf apr-1.5.2.tar.gz check_ok tar zxvf apr-util-1.5.4.tar.gz check_ok tar jxvf httpd-2.4.12.tar.bz2 check_ok cd apr-1.5.2 ./configure --prefix=/usr/local/apr check_ok make && make install check_ok cd /usr/local/src/apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr/ check_ok make && make install check_ok cd /usr/local/src/httpd-2.4.12 ./configure --prefix=/usr/local/apache--enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util--enable-modules=most --enable-mpms-shared=all --with-mpm=event check_ok make && make install check_ok sed -i ‘/^#ServerNamewww.example.com:80$/a\ServerName localhost:80‘ /usr/local/apache/conf/httpd.conf check_ok cp /usr/local/apache/bin/apachectl/etc/init.d/httpd check_ok sed -i ‘/^#!\/bin\/sh$/a\# chkconfig: 35 7030‘ /etc/init.d/httpd sed -i ‘/^# chkconfig: 35 70 30$/a\#description: Apache‘ /etc/init.d/httpd check_ok chkconfig --level 35 httpd on service httpd start check_ok } install_php(){ for j in libxml2-devel bzip2 bzip2-devellibmcrypt-devel ;do yum_install $j done check_ok cd /usr/local/src [ -f php-5.6.10.tar.gz ] || wgethttp://cn2.php.net/distributions/php-5.6.10.tar.gz check_ok tar zxvf php-5.6.10.tar.gz check_ok cd php-5.6.10 ./configure --prefix=/usr/local/php--with-mysql=/usr/local/mysql --with-openssl--with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs--with-mcrypt --with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts check_ok make && make install check_ok /bin/cp php.ini-production /etc/php.ini check_ok } join_php(){ sed -i ‘/AddType .*.gz .tgz$/a\AddTypeapplication\/x-httpd-php .php‘ /usr/local/apache/conf/httpd.conf check_ok sed -i ‘s/DirectoryIndexindex.html/DirectoryIndex index.php index.html index.htm/‘/usr/local/apache/conf/httpd.conf check_ok cat > /usr/local/apache/htdocs/index.php<<EOF <?php phpinfo(); ?> EOF check_ok if /usr/local/php/bin/php -i |grep -iq‘date.timezone => no value‘ then sed -i ‘/;date.timezone =$/a\date.timezone ="Asia\/Chongqing"‘ /etc/php.ini fi /usr/local/apache/bin/apachectl restart check_ok } lamp() { echo "now will install mysql-5.6.24 ,please waite a minute ..." sleep 60 check_service mysqld echo "mysqld is complete !now willinstall httpd-2.4.12 , please waite a minute ..." sleep 60 check_service httpd echo "httpd is complete !now willinstall php-5.6.10 , please waite a minute ..." sleep 60 install_php check_ok echo "php is complete !now will joinphp , please waite a minute ..." sleep 60 join_php service httpd restart echo "LAMP done,Please use‘http://your ip/index.php‘ to access." } lamp mysql-5.6.24 httpd-2.4.12 php-5.6.10 else exit fi
标签:shell lamp apache php httpd mysql
原文地址:http://onelinux.blog.51cto.com/2179673/1669333