#!/bin/bash
#auto Install LAMP
#by Csy 2015-11-07
#Httpd Define PATH variable
A_files=apr-1.5.2.tar.gz
a_files_dir=apr-1.5.2
a_url=http://mirrors.cnnic.cn/apache//apr/
A_prefix=/usr/local/apr
Au_files=apr-util-1.5.4.tar.gz
au_files_dir=apr-util-1.5.4
au_url=http://mirrors.cnnic.cn/apache//apr/
Au_prefix=/usr/local/apr-util
Pc_files=pcre-8.37.tar.gz
pc_files_dir=pcre-8.37
pc_url=http://nchc.dl.sourceforge.net/project/pcre/pcre/8.37/
Pc_prefix=/usr/local/pcre
H_files=httpd-2.4.17.tar.gz
h_files_dir=httpd-2.4.17
h_url=http://mirror.bit.edu.cn/apache//httpd/
h_prefix=/usr/local/apache2/
#Mysql Define PATH variable
M_files=mysql-5.6.27.tar.gz
m_files_dir=mysql-5.6.27
m_url=http://mirrors.linuxeye.com/lnmp/src/
m_prefix=/usr/local/mysql/
#PHP Define PATH variable
P_files=php-5.6.14.tar.gz
p_files_dir=php-5.6.14
p_url=http://cn2.php.net/distributions/
p_prefix=/usr/local/php5/
Echo-e "\033[34m-------------------------\033[0m"
Echo-e "\033[35mready to set up LAMP source environment\n
Wait for 5 seconds, please select menu\033[0m "
Sleep 5
If [-Z "$"];then
ECHO-E "\033[36mplease Select Install Menu follow:\033[0m"
Echo-e "\033[32m1) compile and install Apache server \033[1m"
echo "2) compile and install MySQL server"
echo "3) Compile and install PHP server"
echo "4) Configure index.php and start lamp service"
Echo-e "\033[31musage: {/bin/sh $1|2|3|4|help}\033[0m"
Exit
Fi
if [["$"-eq "Help"]];then
Echo-e "\033[36mplease Select Install Menu follow:\033[0m"
Echo-e "\033[32m1) compile and install Apache server \033[1m"
echo "2) compile and install MySQL server"
echo "3) Compile and install PHP server"
echo "4) Configure index.php and start lamp service"
Echo-e "\033[31musage: {/bin/sh $1|2|3|4|help}\033[0m"
Exit
Fi
##################################
#Install httpd Web Server
if [["$"-eq "1"]];then
Wget-c $A _url/$A _files && tar-zxvf $A _files && cd $A _files_dir &&/configure--prefix= $A _prefix
If [$?-eq 0];then
make && make install
Echo-e "\033[32m the $A _files_dir install ok!\033[0m"
Else
Echo-e "\033[32m the $A _files_dir install error,please check...\033[0m"
Exit 0
Fi
Wget-c $AU _url/$AU _files && tar-zxvf $AU _files && cd $AU _files_dir &&/configure--prefix= $AU _p refix-with-apr= $A _prefix
If [$?-eq 0];then
make && make install
Echo-e "\033[32m the $AU _files_dir install ok!\033[0m"
Else
Echo-e "\033[32m the $AU _files_dir install error,please check...\033[0m"
Exit 0
Fi
Wget-c $PC _url/$PC _files && tar-zxvf $PC _files && cd $PC _files_dir &&/configure--prefix= $PC _p Refix
If [$?-eq 0];then
make && make install
Echo-e "\033[32m the $PC _files_dir install ok!\033[0m"
Else
Echo-e "\033[32m the $PC _files_dir install error,please check...\033[0m"
Exit 0
Fi
Wget-c $H _url/$H _files && tar-zxvf $H _files && cd $H _files_dir &&/configure--prefix= $H _prefix --with-apr= $A _prefix--with-apr-util= $AU _prefix--with-pcre= $PC _prefix--enable-so--enable-rewrite
If [$?-eq 0];then
Make && make install
CP $H _PREFIX/BIN/APACHECTL/ETC/INIT.D/HTTPD
echo "# chkconfig:2345" >>/etc/init.d/httpd && chkconfig--add httpd && chkconfig--level 35 httpd on &&/etc/init.d/httpd restart
Echo-e "\033[32m----------------------------------\033[0m"
Echo-e "\033[32m the $H _files_dir Server install Success! \033[0m "
Else
Echo-e "\033[32m the $H _files_dir make or make install Errop,please check....\033[0m"
Exit 0
Fi
Fi
#Install MySQL DB server
if [["$"-eq "2"]];then
Yum-y install make CMake gcc-c++ bison ncurses ncurses-devel
Wget-c $M _url/$M _files && tar-zxvf $M _files && cd $M _files_dir && cmake./\
-dcmake_install_prefix=/usr/local/mysql \
-dmysql_datadir=/usr/local/mysql/data \
-DSYSCONFDIR=/ETC \
-dwith_myisam_storage_engine=1 \
-dwith_innobase_storage_engine=1 \
-dwith_memory_storage_engine=1 \
-dmysql_unix_addr=/tmp/mysqld.sock \
-dmysql_tcp_port=3306 \
-denabled_local_infile=1 \
-dwith_partition_storage_engine=1 \
-dextra_charsets=all \
-ddefault_charset=utf8 \
-ddefault_collation=utf8_general_ci
If [$?-eq 0];then
Make-j8 && make Install
Groupadd MySQL
Useradd-g mysql-s/sbin/noghion MySQL
CD $M _prefix
Chown-r Mysql.mysql.
scripts/mysql_install_db--basedir= $M _prefix--datadir= $PREFIX/data--user=mysql
Chown-r Mysql.mysql./data
CP Support-files/mysql.server/etc/init.d/mysqld
Bin/mysqld_safe--user=mysql
Ln-s $M _prefix/bin/mysql/usr/bin/mysql
chmod +x/etc/init.d/mysqld
Rm-rf/etc/my.cnf
Cat >/etc/my.cnf <<eof
[Mysqld]
Datadir=/usr/local/mysql/data
Socket=/tmp/mysqld.sock
User=mysql
# Disabling Symbolic-links is recommended to prevent assorted security risks
Symbolic-links=0
[Mysqld_safe]
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid
Eof
/etc/init.d/mysqld restart
Echo-e "\n\033[32m-----------------------------------------------\033[0m"
Echo-e "\033[32mthe $M _files_dir Server Install Success!\033[0m"
Else
Echo-e "\033[32mthe $M _files_dir make or make install Error,please Check ..."
Exit 0
Fi
Fi
#Install PHP Server
if [["$"-eq "3"]];then
Yum Install Libxml2-devel-y
Wget-c $P _url/$P _files && tar-zxvf $P _files && cd $P _files_dir &&./configure--prefix= $P _prefix --with-config-file-path=/usr/local/php/etc--with-apxs2= $H _prefix/bin/apxs--with-mysql= $M _prefix/
If [$?-eq 0];then
Make && make test && make install
Echo-e "\n\033[32m-----------------------------------------------\033[0m"
Echo-e "\033[32mthe $P _files_dir Server Install Success!\033[0m"
Else
Echo-e "\033[32mthe $P _files_dir make or make install Error,please Check ..."
Exit 0
Fi
Fi
####################################
if [["$"-eq "4"]];then
Sed-i '/directoryindex/s/index.html/index.php index.html/g ' $H _prefix/conf/httpd.conf
$H _prefix/bin/apachectl Restart
echo "AddType application/x-httpd-php. php" >> $H _prefix/conf/httpd.conf
ip= ' ifconfig eth0|grep "bcast" |awk ' {print $} ' |cut-d:-f2 '
echo "You can access/HTTP $IP/"
Cat > $H _prefix/htdocs/index.php <<eof
<?php
Phpinfo ();
?>
Eof
Fi
This article is from "Life is insight, not live" blog, please be sure to keep this source http://linuxshengyu.blog.51cto.com/8810066/1710753
Using shell scripts to build the source lamp environment