#6.16 Install apache
echo "Install apache ..."
cd $EXTRACT_PATH/httpd*
./configure --prefix=$INSTALL_PATH/apache \
--enable-mods-shared=all \
--enable-deflate \
--enable-speling \
--enable-cache \
--enable-file-cache \
--enable-disk-cache \
--enable-mem-cache \
--enable-so \
--enable-expires=shared \
--enable-rewrite=shared \
--enable-static-support \
--sysconfdir=/etc/httpd \
--with-apr=$INSTALL_PATH/apr \
--with-apr-util=$INSTALL_PATH/apr-util \
--with-pcre=$INSTALL_PATH/pcre \
--disable-userdir >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Apache Install Complete."
echo
#6.17 Install mysql
echo "Install mysql ..."
#6.17.1 Check Mysql user
id mysql >/dev/null 2>&1
MYSQL_USER="$(echo $?)"
if [[ $MYSQL_USER -ne 0 ]] ;then
groupadd mysql
useradd -g mysql mysql
[ $(echo $?) -ne 0 ] && exit 1
fi
#6.17.2 Install necessary dependice rpm package
rpm -ivh $RPM_PAHT/ncurses*.rpm >/dev/null 2>&1
#6.17.3 Install mysql server
cd $EXTRACT_PATH/mysql*
./configure --prefix=$INSTALL_PATH/mysql \
--enable-thread-safe-client \
--with-extra-charsets=all >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Mysql Install Complete."
echo
#6.18 Install php
echo "Install php"
cd $EXTRACT_PATH/php*
./configure --prefix=$INSTALL_PATH/php \
--with-config-file-path=$INSTALL_PATH/php/etc \
--with-apxs2=$INSTALL_PATH/apache/bin/apxs \
--with-mysql=$INSTALL_PATH/mysql \
--with-libxml-dir=$INSTALL_PATH/libxml2 \
--with-png-dir=$INSTALL_PATH/libpng \
--with-jpeg-dir=$INSTALL_PATH/jpeg \
--with-freetype-dir=$INSTALL_PATH/freetype \
--with-gd=$INSTALL_PATH/gd \
--with-zlib-dir=$INSTALL_PATH/zlib \
--with-mcrypt=$INSTALL_PATH/libmcrypt \
--with-mysqli=$INSTALL_PATH/mysql/bin/mysql_config \
--enable-soap \
--enable-mbstring=all \
--with-mssql=$INSTALL_PATH/freetds \
--enable-sockets >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Php Install Complete."
echo
##7. Configure LAMP Configuation Files
#7.1 Configure Apache Configuation Files
#7.1.1 Set apache configuation file
sed -i 203aServerName\ $HOSTNAME:80 /etc/httpd/httpd.conf
[ $(echo $?) -ne 0 ] && exit 1
#7.1.2 Make apache server can read ".php" file
sed -i 386aAddType\ application\/x-httpd-php\ \.php /etc/httpd/httpd.conf
[ $(echo $?) -ne 0 ] && exit 1
sed -i 386aAddType\ application\/x-httpd-php-source\ \.phps /etc/httpd/httpd.conf
[ $(echo $?) -ne 0 ] && exit 1
sed -i 386aAddType\ application\/x-httpd-php\ \.php\ \.phtml\ \.php3 /etc/httpd/httpd.conf
[ $(echo $?) -ne 0 ] && exit 1
#7.1.3 Set apache server start runing when system start-up
cp $INSTALL_PATH/apache/bin/apachectl /etc/init.d/httpd
sed -i -e 2a#\ chkconfig:\ 234\ 71\ 29 /etc/init.d/httpd -e 2a#\ description:\ Apache\ is\ a\ World\ Wide\ Web\ server. /etc/init.d/httpd
[ $(echo $?) -ne 0 ] && exit 1
chkconfig --add httpd >/dev/null 2>&1
#7.2.4 Set Envirment variable
sed -i "10s%$%&:$INSTALL_PATH/apache/bin%" /root/.bash_profile
source /root/.bash_profile
#7.2 Configure Mysql Configuation Files
#7.2.1 Set mysql configuation file
cp $EXTRACT_PATH/mysql*/support-files/my-medium.cnf /etc/my.cnf
#7.2.2 Init mysql dababase
$INSTALL_PATH/mysql/bin/mysql_install_db --user=mysql >/dev/null 2>&1
#7.2.3 Set privileges for mysql server file
chmod +x $INSTALL_PATH/mysql/bin/* >/dev/null 2>&1
chown -R root $INSTALL_PATH/mysql >/dev/null 2>&1
chown -R mysql $INSTALL_PATH/mysql/var >/dev/null 2>&1
chgrp -R mysql $INSTALL_PATH/mysql >/dev/null 2>&1
#7.2.4 Set mysql server password (default 123456)
$INSTALL_PATH/mysql/bin/mysqladmin -u root password 123456 >/dev/null 2>&1
#7.2.5 Set mysql server start runing when system start-up
cp $EXTRACT_PATH/mysql*/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld >/dev/null 2>&1
#7.2.6 Set Envirment variable
sed -i "10s%$%&:$INSTALL_PATH/mysql/bin%" /root/.bash_profile
source /root/.bash_profile
##8. Start LAMP Server
service httpd start
service mysqld start
##9. Clean Useless File Or Directory
rm -fr $EXTRACT_PATH