#一键安装lamp环境 #!/bin/bash #centos 6.5 lamp install scripts #apache 2.4.x版本,mysql5.5.x以上版本,php5.5.x以上版本 . /etc/init.d/functions function check_ok(){ if [ $? -eq 0 ] then continue else echo "please check error" exit 1 fi } function yum_update(){ echo "===update yum repos ,it will take serval mintinuse===" yum install wget -y path=/etc/yum.repos.d [ -d "$path" ] || mkdir -p $path/bak mv $path/CentOS-* $path/bak/ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo &>/dev/null if [ -f "$path/epel.repo" ] then rm -rf $path/eprl.repo fi wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo &>/dev/null yum clean all &>/dev/null yum makecache &>/dev/null check_ok action "yum repos update is ok" /bin/true } function yum_depend(){ yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel -y action "yum depend is all installed" /bin/true } function install_mysql(){ echo "mysql5.6.35 will be installing please wait mintinues " cd /usr/local/src groupadd mysql useradd -s /sbin/nologin -g mysql -M mysql mysqltar="mysql-5.6.35.tar.gz" namedir="mysql-5.6.35" [ -f "$mysqltar" ] && continue || wget https://cdn.mysql.com//archives/mysql-5.6/mysql-5.6.35.tar.gz [ -d "$namedir" ] && continue || tar -zxvf mysql-5.6.35.tar.gz cd $namedir installdir="/usr/local/mysql" [ -d "$installdir" ] && continue || mkdir -p $installdir pwd cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci check_ok make && make install check_ok
}
function mysqlset(){
echo "PATH=/usr/local/mysql/bin:$PATH">>/etc/profile
source /etc/profile
chown -R mysql:mysql /usr/local/mysql/
check_ok
cd /usr/local/mysql/scripts/
./mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
chenk_ok
[ -f "/etc/my.cnf" ] && rm -f /etc/my.cnf
cp -f /usr/local/src/mysql-5.6.35/support-files/my-default.cnf /etc/my.cnf
sed -i '/^[mysqld]$/a\user = mysql \nbasedir = /usr/local/mysql\ndatadir = /usr/local/mysql/data\nsocket = /tmp/mysql.sock' /etc/my.cnf
cp -f /usr/local/src/mysql-5.6.35/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed -i 's#^datadir=#datadir=/usr/local/mysql/data#' /etc/init.d/mysqld
sed -i 's#^basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
check_ok
}
function install_apache(){
echo "apache2.4.25 will be installed,please wait minitunes"
yum -y install expat-devel
check_ok
path="/usr/local/src/"
cd $path
apachetar="httpd-2.4.29.tar.gz"
aprtar="apr-1.6.3.tar.gz"
aprutiltar="apr-util-1.6.1.tar.gz"
pcretar="pcre-8.41.tar.gz"
[ ! -f "$apachetar" ] && wget https://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz || continue
check_ok
[ ! -f "$aprtar" ] && wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.3.tar.gz || continue
check_ok
[ ! -f "$aprutiltar" ] && wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz || continue
check_ok
[ ! -f "$pcretar" ] && wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz || continue
check_ok
tar -zxvf httpd-2.4.29.tar.gz
tar -zxvf apr-1.6.3.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
tar -zxvf pcre-8.41.tar.gz
check_ok
cd $path/apr-1.6.3
./configure --prefix=/usr/local/apr
make && make install
check_ok
cd $path/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
chenk_ok
make && make install
check_ok
cd $path/pcre-8.41
./configure --prefix=/usr/local/pcre
check_ok
make && make install
check_ok
cd $path/httpd-2.4.29
./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-mods-shared=most --enable-rewrite
check_ok
make && make install
check_ok
} function apacheset(){ cp /usr/local/apache2.4/bin/apachectl /etc/init.d/httpd chmod +x /etc/init.d/httpd sed -i '2 i #chkconfig: 2345 10 90' /etc/init.d/httpd sed -i '3 i #description: Activates/Deactivates Apache Web Server' /etc/init.d/httpd check_ok chkconfig httpd on
} function install_php(){ echo "php will be installed,please be wait" sleep 10 yum -y install zlib-devel libpng-devel curl libmcrypt-devel freetype-devel libxml2-devel openssl-devel bzip2-devel libjpeg-devel curl-devel gd check_ok cd /usr/local/src phptar="php-5.6.30.tar.gz" [ ! -f "$phptar" ] && wget http://cn2.php.net/distributions/php-5.6.30.tar.gz || continue tar -zxvf php-5.6.30.tar.gz mkdir -p /usr/local/php5 cd /usr/local/src/php-5.6.30 ./configure --prefix=/usr/local/php5/ --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc/ --with-mysql=/usr/local/mysql/ --with-pdo-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-icon-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif check_ok make && make install
}
function main(){
yum_update
yum_depend
install_mysql
mysqlset
install_apache
install_php
apacheset
}
main