#!/bin/bash
#write by zhang_pc
#at 2015.07.24
#apache2.4 php.5.4 mysql5.5
APR_FILES=apr-1.5.2.tar.gz
APR_DIR=apr-1.5.2
ARP_PRE=/usr/local/apr
APR_URL=http://mirror.bit.edu.cn/apache/apr/apr-1.5.2.tar.gz
APR_U_FILES=apr-util-1.5.4.tar.gz
APR_U_DIR=apr-util-1.5.4
APR_U_PRE=/usr/local/apr-util
APR_U_URL=http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
A_FILES=httpd-2.4.16.tar.gz
A_DIR=httpd-2.4.16
A_PRE=/usr/local/apache
A_URL=http://mirrors.sohu.com/apache/httpd-2.4.16.tar.gz
M_FILES=mysql-5.5.44.tar.gz
M_DIR=mysql-5.5.44
M_PRE=/usr/local/mysql
M_URL=http://download.softagency.net/MySQL/Downloads/MySQL-5.5/mysql-5.5.44.tar.gz
P_FILES=php-5.4.22.tar.gz
P_DIR=php-5.4.22
P_PRE=/usr/local/php
P_URL=http://mirrors.sohu.com/php/php-5.4.22.tar.gz
function apache() {
tar -zxvf $APR_FILES;cd $APR_DIR;./configure --prefix=$APR_PRE
if [ $? -ne 0 ];then exit;fi
make
if [ $? -ne 0 ];then exit;fi
make install
if [ $? -ne 0 ];then exit;fi
cd ..
tar -zxvf $APR_U_FILES;cd $APR_U_DIR;./configure --prefix=$APR_U_PRE --with-apr=$APR_PRE && make && make install
cd ..
yum install pcre-devel openssl-devel -y
tar -zxvf $A_FILES;cd $A_DIR
./configure --prefix=$A_PRE --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-arp=$APR_PRE --with-apr-util=$APR_U_PRE --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make -j2 && make install -j2
if [ $? -eq 0 ];then
echo "the apache is successful"
else
echo "the apache is failed"
exit
fi
}
function mysql() {
yum install gcc-c++ cmake ncurses-devel bison perl -y
useradd -s /sbin/nologin mysql
mkdir -p /data/mysql
chown -R mysql.mysql /data/mysql
tar -zxvf $M_FILES;cd $M_DIR
cmake -DCMAKE_INSTALL_PREFIX=$M_PRE -DMYSQL_DATADIR=/data/mysql -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 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_USER=mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock
make -j2 && make install -j2
if [ $? -eq 0 ];then
echo "the mysql is successful"
else
echo "the mysql is failed"
exit
fi
}
function php() {
yum install libxml2-devel libmcrypt-devel bzip2-devel libxml2-devel openssl-devel bzip2 bzip2-devel -y
tar -zxvf $P_FILES;cd $P_DIR
./configure --prefix=$P_PRE --with-config-file-path=$P_PRE/etc --with-apxs2=$A_PRE/bin/apxs --with-mysql=$M_PRE
make -j2 && make install
if [ $? -eq 0 ];then
echo "the php is successful"
else
echo "the php is failed"
exit
fi
}
function lamp() {
sed -i "s/#ServerName www.example.com:80/ServerName www.example.com:80/g" /usr/local/apache/conf/httpd.conf
sed -i "s/DirectoryIndex index.html/DirectoryIndex index.php index.html/g" /usr/local/apache/conf/httpd.conf
sed -i ‘310a AddType application/x-httpd-php .php‘ /usr/local/apache/conf/httpd.conf
/usr/local/apache/bin/apachectl start
/bin/cp ./$M_DIR/support-files/my-medium.cnf /etc/my.cnf
/bin/cp ./$M_DIR/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
sed -i ‘38a datadir=/data/mysql‘ /etc/my.cnf
sed -i ‘38a basedir=/usr/local/mysql‘ /etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
/etc/init.d/mysqld start
chkconfig --add mysqld
echo "PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
source /etc/profile
}
if [ -z $1 ];then
echo -e "\033[32m please select you count\033[1m"
echo -e "\033[32m 1 安装apache\033[1m"
echo -e "\033[32m 2 安装mysql\033[1m"
echo -e "\033[32m 3 安装php\033[1m"
echo -e "\033[32m 4 lamp整合并启动服务\033[0m"
exit
elif [ $1 -eq 1 ];then
wget $APR_URL && wget $APR_U_URL && wget $A_URL && apache
elif [ $1 -eq 2 ];then
wget $M_URL && mysql
elif [ $1 -eq 3 ];then
wget $P_URL && php
elif [ $1 -eq 4 ];then
lamp
else
exit
fi