#!/bin/bash
#by 2015-7-25--LIJQ
#directiof for use: source packages and scripts in the same directory and in the root directory file
dir=/mnt/soft/
Script_dir=/root/autolamp
If [$UID-ne 0]; Then
Echo-e "\033[32monly for root to install this lamp\033[0m"
Exit 3
Fi
Echo-e "\033[32mcreate soft dowload dir....\033[0m"
if [!-D $DIR];then
Mkdir-p $DIR;
Fi
Echo-e "\033[32minstal Some dependent packages,please wait for ... \033\0m"
Yum install gcc gcc-c++ make cmake ncurses-devel bison perl lrzsz epel-release pcre-devel openssl-devel-y;
Yum install wget unzip libxml2-devel libmcrypt-devel bzip2-devel libxml2-devel openssl-devel bzip2 bzip2-devel-y
;
Apr_file=apr-1.5.2.tar.gz
Apr= ' echo $APR _file | Sed ' s/\.tar\.gz//g '
Apr_utils=apr-util-1.5.2.tar.gz
Apr_util= ' echo $APR _utils | Sed ' s/\.tar\.gz//g '
Apache_file=httpd-2.4.16.tar.gz
Apache= ' echo $APACHE _file | Sed ' s/\.tar\.gz//g '
apr_dir=/usr/local/apr/
aprutil_dir=/usr/local/apr-util/
apache_dir=/usr/local/apache/
function Httpd_install ()
{if [-F $APR _file-o-F $APR _utils-o-F $APACHE _file];then
CP $APR _file $APR _utils $APACHE _file $DIR-A
Else
CD $DIR;
Wget-c http://archive.apache.org/dist/apr/$APR _file;
Wget-c http://archive.apache.org/dist/apr/$APR _utils;
Wget-c http://www.apache.org/dist/httpd/$APACHE _file;
Fi
CD $DIR
Tar xzvf $APR _file;
CD $APR;. /configure--prefix= $APR _dir && make && make install;
If [$?-eq 0]; Then
ECHO-E "\033[32mthis Apr is install successfully...\033[0m"
Else
ECHO-E "\033[32mthis Apr is install failed,please check....\033[0m"
Exit
Fi
CD $DIR;
Tar xzvf $APR _utils;
CD $APR _util;
./configure--prefix= $APRUTIL _dir--with-apr= $APR _dir &&make && make install;
If [$?-eq 0];then
Echo-e "\033[32mthis apr-util is install successfully....\033[0m"
Else
Echo-e "\033[32mthis Arp in install failed, please check....\033[0m"
Exit
Fi
CD $DIR;
Tar xzvf $APACHE _file; CD $APACHE;
./configure--prefix= $APACHE _dir--enable-so--enable-ssl--enable-cgi--enable-rewrite--with-zlib--with-pcre-
-with-apr= $APR _dir--with-apr-util= $APRUTIL _dir--enable-modules=most--enable-mpms-shared=all--with-mpm=event && Make &
& Make Install
If [$?-eq 0]; Then
ECHO-E "\033[32mthe Apache is install successful. \033[0m "
$APACHE _dir/bin/apachectl Restart;
Else
ECHO-E "\033[32mthe Apache is install failed,please check....\033[0m"
Exit
Fi
}
Sleep 3
Mysql_file= ' mysql-5.5.44.tar.gz '
Mysql= ' echo $MYSQL _file | Sed ' s/\.tar\.gz//g '
datadir=/data/mysql3306
basedir=/data/app/mysql3306
Mysql_status= ' ps-ef |grep mysqld_safe |awk ' nr==1 {print $9} ' |sed ' s#\/data\/app\/mysql3306\/bin\/# #g '
function Mysql_install ()
{CD $SCRIPT _dir;
If [-F ' $MYSQL _file "];then
CP ${mysql_file} $DIR-A;
Sleep 2
Else
CD $DIR;
Wget-c http://download.softagency.net/MySQL/Downloads/MySQL-5.5/$MYSQL _file;
Fi
CD $DIR;
Tar xzvf $MYSQL _file;cd $MYSQL; mkdir-p {$DATADIR, $DATADIR};
CMake \-dcmake_install_prefix= $BASEDIR \-dmysql_datadir= $DATADIR \-dwith_myisam_storage_engine=1 \-dwith_innobase
_storage_engine=1 \-dwith_memory_storage_engine=1 \-dwith_readline=1 \-dmysql_tcp_port=3306 \-DENABLED_LOCAL_ Infile=1 \-d
with_partition_storage_engine=1 \-dextra_charsets=all \-ddefault_charset=utf8 \-DDEFAULT_COLLATION=utf8_general_ CI \-dwit
h_debug=0 \-dmysql_user=mysql \-dmysql_unix_addr= $DATADIR/mysql3306.sock && make && make install
If [$?-eq 0]; Then
Echo-e "\033[32mthe MySQL is install successful. \033[0m "
Else
Echo-e "\033[32mthis MySQL is install failed.....\033[0m"
Exit 2
Fi
Useradd MySQL;
Chown-r Mysql.mysql $DATADIR;
Chown-r Mysql:mysql $BASEDIR;
Cp-a support-files/my-large.cnf $DATADIR/my.cnf;
Chown-r mysql.mysql $DATADIR/my.cnf;
Cp-a $BASEDIR/support-files/mysql.server/etc/init.d/mysqld;
# sed-i '/mysql3306/i datadir =/data/mysql3306\nbasedir =/data/app/mysql3306 '/data/mysql3306/my.cnf;
Sed-i "26a\datadir = $DATADIR \nbasedir = $BASEDIR" $DATADIR/my.cnf;
CD $BASEDIR;. /scripts/mysql_install_db--basedir= $BASEDIR--datadir= $DATADIR--user=mysql;
echo "Export path=" \ $PATH ": ${basedir}/bin/" >>/root/.bash_profile && Source/root/.bash_profile & &/etc/init.d/mysqld Res
Tart;pkill mysql;/etc/init.d/mysqld start;/etc/init.d/mysqld Restart;
Sleep 5
if [${mysql_status} = ' Mysqld_safe '];then
Echo-e "\033[32mthe Mysql was installed successfully....\033[0m"
Else
Echo-e "\033[31mthe Mysql is installed failed,please check...\033[0m"
Exit
Fi
Sleep 3
}
php_files=php-5.4.42.tar.bz2
Php= ' echo $PHP _files | Sed ' s/\.tar\.bz2//g '
php_dir=/usr/local/php
function Php_install ()
{CD $SCRIPT _dir;
If [-F $PHP _files];then
CP $PHP _files $DIR-A;
Else
CD $DIR;
wget http://mirrors.sohu.com/php/$PHP _files;
Fi
CD $DIR;
If [-D $BASEDIR]; Then
Tar xjvf $PHP _files; CD $PHP;. /configure--prefix= $PHP _dir--with-mysql= $BASEDIR--with-openssl--with-mysqli= $B
Asedir/bin/mysql_config--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib-- With-libxml-di
R=/USR--enable-xml--enable-sockets--enable-fpm--with-mcrypt--with-bz2--with-config-file-path=/etc/php/php.ini- -wit
h-config-file-scan-dir=/etc/php/php.d/--with-apxs2=${apache_dir}bin/apxs && make && make install
Else
Echo-e "\033[32mplease Install this mysql....\033[0m"
Fi
If [$?-eq 0]; Then
Echo-e "\033[32mthe PHP is install successful. \033[0m "
Else
echo "The PHP is install failed,,,, please quit"
Exit
Fi
}
ip= ' ifconfig eth0 |grep bcast |awk ' {print $} ' |sed ' s/addr://g '
function Php_apache ()
{
ECHO-E "\033[32mit would configure the Apache and php\033[0m"
CP ${apache_dir}conf/httpd.conf ${apache_dir}conf/httpd.conf.bak
echo "AddType application/x-httpd-php. php" >> ${apache_dir}conf/httpd.conf
Sed-i ' S/directoryindex index.html/directoryindex index.php index.html/g ' ${apache_dir}conf/httpd.conf
If [$?-eq 0];then
Echo-e "\033[32mit ' s successfully, would test the PHP ... \033[0m"
RM-RF ${apache_dir}htdocs/*;
Cat >${apache_dir}htdocs/index.php <<eof
<?php
Phpinfo ();
?>
Eof
If [$?-eq 0];then
#启动apache服务
${apache_dir}bin/apachectl Restart;
${apache_dir}bin/apachectl Restart;
Echo-e "\033[32myou can access http://${ip}/index.php\033[0m"
Fi
Else
Echo-e "\033[31mthe PHP is installed failed,please check...\033[0m"
Exit
Fi
}
Discuz_file=discuz_x3.1_sc_utf8.zip
Discuz=discuz_x3.1_sc_utf8
password=123456
function Discuz_install ()
{CD $SCRIPT _dir;
If [-F $Discuz _file];then
CP $Discuz _file $DIR-A;
Sleep 2
Else
CD $DIR;
Wget-c http://download.comsenz.com/DiscuzX/3.1/$Discuz _file;
Fi
CD $DIR;
RM-RF ${apache_dir}htdocs/* && unzip $Discuz _file-d ${apache_dir}htdocs/;
CD ${apache_dir}htdocs/&& mv upload/*. && chmod-r o+w data/config/uc_server/uc_client/;
If [$?-eq 0];then
Echo-e ' \033[32mthis discuz is files configure ok....\033[0m '
#设置数据库密码和创建数据库
$BASEDIR/bin/mysqladmin-uroot Password $PASSWORD &&
Mysql-uroot-h 127.0.0.1-p$password-e "CREATE Database discuz;" &&
#授权discuz用户
Mysql-uroot-h 127.0.0.1-P$PASSWORD-E "Grant all on * * to [e-mail protected] ' ${ip} ' identified by ' $PASSWORD '; flush pri V
Ileges; "
If [$?-eq 0];then
ECHO-E "\033[32mthis discuz database Configure is success.....\033[0m"
Else
ECHO-E "\033[32mthis discuz database Configure is failed. Please check: \033[0m "
Fi
#重启apache服务和mysql
${apache_dir}bin/apachectl restart&&/etc/init.d/mysqld Restart;
If [$?-eq 0];then
ECHO-E "\033[32mthe Apache and Mysql Start success!\033[0m"
Else
ECHO-E "\033[31mthis Discuz Configure is failed. Please check.\033[0m "
Fi
Else
Echo-e "\033[32mthe MySQL and Apache is failed....please check.\033[0m"
Echo-e "\033[32mthis discuz is install success.......\033[32m"
Exit 2
Fi
}
ps3= "Please select your install menu:"
Select I in "httpd" "MySQL" "php" "Php+apache" "Discuz" "Quit" "All_auto"
Do
Case $i in
HTTPD)
Httpd_install
;;
MySQL)
Mysql_install
;;
PHP)
Php_install
;;
Php+apache)
Php_apache
;;
Discuz)
Discuz_install
;;
All_auto)
Httpd_install;
Mysql_install;
Php_install;
Php_apache;
Discuz_install
;;
Quit)
Exit
;;
* )
echo "Usage: $ {httpd|mysql|php|php+apache|discuz|all_auto|quit}"
Esac
Done
This article is from the "Fluffy Duck" blog, please be sure to keep this source http://woshitieren.blog.51cto.com/2466034/1678525
Installing the Lamp+discuz Script