#!/bin/bash
#
# **********************************************************
# * filename: lamp_install.sh *
# * discription: lamp install *
# * version: centos6.7 apr-1.5.2 apr-util-1.5.4 *
# * httpd-2.4.6 mysql-5.5.32 php-5.6.15 *
# * date: 2016/09/07 *
# * author: wangbo *
# * mail: [email protected] *
function init()
{
#shutdown SELINUX
setenforce 0;
#stop iptables
/etc/init.d/iptables stop;
echo "***********************************";
echo "*init finished! *";
}
#check root user ,net
function base_check()
#check user root
if [ `whoami` = "root" ]
then
echo "***********************************";
echo "*root user *";
else
echo "***************************************";
echo "*change to root,please input password *";
su - root -s /bin/bash /usr/local/src/lamp_install.sh;
#exit 1;
fi
echo "*is root user! *";
#the count of lose package
lpcount = ping -c 4 www.baidu.com | grep received | awk '{print $6}' | sed -e 's/%//g';
#check net
if [ $lpcount -gt 2 ]
echo "*Please check your network *";
exit 1;
echo "*network is ok! *";
function package_check()
echo "###";
function apr_install()
cd /usr/local/src;
tar xzf apr-1.5.2.tar.gz;
cd apr-1.5.2;
./configure \
--prefix=/usr/local/apr
if [ $? -ne 0 ]
echo "*apr configure failed,stop... *";
make && make install;
then
echo "*php make failed , stop... *";
exit 1;
echo "*apr installed successfully! *";
function apr_util_install()
tar xzf apr-util-1.5.4.tar.gz;
cd apr-util-1.5.4;
--with-apr=/usr/local/apr \
--prefix=/usr/local/apr-util
echo "*apr-util configure failed,stop...*";
echo "*apr-util make failed , stop... *";
echo "*apr-util installed successfully! *";
function httpd_install()
yum -y install pcre pcre-devel openssl openssl-devel zlib-devel;
cd /usr/local/src/;
tar xzf httpd-2.4.16.tar.gz;
cd httpd-2.4.16;
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-rewrite \
--enable-ssl \
--enable-cgi \
--enable-cgid \
--enable-modules=most \
--enable-mods-shared=most \
--enable-mpms-shared=all \
--with-apr-util=/usr/local/apr-util
echo "********************************"
echo "*httpd configure failed,stop...*";
then
echo "***************************";
echo "*php make failed , stop...*";
if [$? -ne 0 ]
echo "**************************"
echo "*httpd make filed,stop...*";
sed -i '/^ServerRoot/a PidFile "/var/run/httpd.pid"' /etc/httpd/httpd.conf;
cp /usr/local/src/httpd /etc/init.d/httpd;
chmod +x /etc/init.d/httpd;
export PATH=$PATH:/usr/local/apache/bin;
chkconfig --add httpd;
chkconfig --level 35 httpd on;
echo "*******************************"
echo "*httpd installed successfully!*";
function mysql_install()
tar xzf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/;
cd /usr/local;
ln -sv mysql-5.5.32-linux2.6-x86_64 mysql;
groupadd -r -g 306 mysql;
useradd -g 306 -r -u 306 mysql;
echo "************************************";
echo "*create user or group faild,stop...*";
cd /usr/local/mysql;
chown -R mysql.mysql .;
chown -R mysql data;
chmod o-rx data;
scripts/mysql_install_db --user=mysql;
chown -R root /usr/local/mysql/*
chown -R mysql.mysql /usr/local/mysql/data
cp support-files/mysql.server /etc/init.d/mysqld;
cp support-files/my-large.cnf /etc/my.cnf;
export PATH=$PATH:/usr/local/mysql/bin;
sed -i '$a MANPATH /usr/local/mysql/man' /etc/man.config;
touch /etc/ld.so.conf.d/mysql.conf;
sed -i '$a /usr/local/mysql/lib' /etc/ld.so.conf.d/mysql.conf;
ln -sv /usr/local/mysql/include /usr/include/mysql;
echo "*******************************";
echo "*mysql installed successfully!*";
function php_install()
yum -y install libxml2 libxml2-devel bzip2 bzip2-devel;
echo "********************************************";
echo "*dependency package installed faild,stop...*";
rpm -ivh libmcrypt-2.5.8-4.el5.centos.x86_64.rpm libmcrypt-devel-2.5.8-4.el5.centos.x86_64.rpm
echo "********************************************"
tar xf php-5.6.15.tar.bz2;
cd php-5.6.15;
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-openssl \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--enable-maintainer-zts
echo "******************************";
echo "*php configure failed,stop...*";
echo "****************************";
echo "*php make failed , stop... *";
cp php.ini-production /etc/php.ini;
sed -i '392a AddType application/x-httpd-php .php' /etc/httpd/httpd.conf;
sed -i '393a AddType application/x-httpd-php-source .phps' /etc/httpd/httpd.conf;
sed -i 's/index.html$/& index.php/' /etc/httpd/httpd.conf;
echo "*****************************";
echo "*php installed successfully!*";
function show_main_menu()
echo "********************************";
echo "* the program of lamp install *";
echo "********************************";
echo "* 1、一键安装 *";
echo "* 2、逐个安装 *";
function show_second_menu()
#请按照apr->apr-util->http->mysql->php顺序安装
echo "*******************************";
echo "* please choose the program *";
echo "* 1、初始化 *";
echo "* 2、基础检查 *";
echo "* 3、安装包检查 *";
echo "* 4、安装 apr *";
echo "* 5、安装 apr-util *";
echo "* 6、安装 httpd *";
echo "* 7、安装mysql *";
echo "* 8、安装php *";
function all_install()
apr_install;
apr_util_install;
httpd_install;
mysql_install;
php_install;
function tmp()
show_second_menu;
choose_install;
function choose_install()
echo -e ">>\c";
read num;
if [ $num -eq "1" ]
init;
tmp;
elif [ $num -eq "2" ]
base_check;
elif [ $num -eq "3" ]
package_check;
elif [ $num -eq "4" ]
apr_install;
elif [ $num -eq "5" ]
apr_util_install;
elif [ $num -eq "6" ]
httpd_install;
elif [ $num -eq "7" ]
mysql_install;
elif [ $num -eq "8" ]
php_install;
function lamp_install()
show_main_menu;
echo -e ">>\c";
read num 2&>1 > /dev/null;
all_install;
lamp_install;