先上效果图:
然后是脚本内容:
#!/bin/bash
#LAMP install
#By liupengfang ----2015-07-21----
echo -e "\033[35m--欢迎使用LAMP自动安装脚本--\033[0m"
sleep 3
cd /lamp
echo -e "\033[35m--Apache安装--\033[0m"
echo -e "\033[35m文件解压……\033[0m"
tar vxf httpd-2.2.29.tar.bz2 &>/dev/null
echo -e "\033[35m文件解压完成!开始预编译……\033[0m"
cd /lamp/httpd-2.2.29
./configure --prefix=/usr/local/apache2 &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[35m预编译成功!\033[0m"
else
echo -e "\033[35m预编译失败!\033[0m"
exit 17
fi
echo -e "\033[35mApache正在安装……\033[0m"
make &>/dev/null && make install &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[35mApache安装成功!\033[0m"
else
echo -e "\033[35mApache安装失败!\033[0m"
exit 17
fi
echo -e "\033[35m--Mysql安装--\033[0m"
echo -e "\033[35m开始解压……\033[0m"
cd /lamp/ ; tar vxf mysql-5.1.63.tar.gz &>/dev/null
echo -e "\033[35m解压完成!开始预编译……\033[0m"
cd /lamp/mysql-5.1.63 ; ./configure --prefix=/usr/local/mysql &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[35m预编译成功!\033[0m"
else
echo -e "\033[35m预编译失败!\033[0m"
exit 17
fi
echo -e "\033[35m开始安装Mysql……\033[0m"
make &>/dev/null && make install &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[35mMysql安装成功!\033[0m"
else
echo -e "\033[35mMysql安装失败!\033[0m"
exit 17
fi
echo -e "\033[35m--PHP安装--\033[0m"
yum install libxml2 libxml2-devel -y &>/dev/null
echo -e "\033[35m开始解压……\033[0m"
cd /lamp/ ; tar vxf php-5.3.29.tar.bz2 &>/dev/null
echo -e "\033[35m解压完成!开始预编译……\033[0m"
cd /lamp/php-5.3.29
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[35m预编译成功!\033[0m"
else
echo -e "\033[35m预编译失败!\033[0m"
exit 17
fi
echo -e "\033[35m开始安装PHP……\033[0m"
make &>/dev/null && make install &>/dev/null
if [ $? -eq 0 ];then
echo -e "\033[35mMysql安装成功!\033[0m"
else
echo -e "\033[35mMysql安装失败!\033[0m"
exit 17
fi
echo -e "\033[35m----Apache+PHP整合中……-----\033[0m"
sleep 3
ADDTYPE=/usr/local/apache2/conf/httpd.conf
sed -i 's/AddType application\/x-gzip .gz .tgz/& \n AddType application\/x-httpd-php .php/' $ADDTYPE
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/' $ADDTYPE
echo -e "\033[35m----编写PHP测试页面……-----\033[0m"
sleep 2
cd /usr/local/apache2/htdocs/
echo '<?php' >> index.php
echo 'phpinfo();' >> index.php
echo '?>' >> index.php
echo -e "\033[35m----请访问PHP测试页面-----\033[0m"
echo -e "\033[35m----Mysql配置-----\033[0m"
sleep 2
useradd mysql
rm -rf /etc/my.cnf
cp /lamp/mysql-5.1.63/support-files/my-medium.cnf /etc/my.cnf
cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
mkdir /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql
MY_CNF=/etc/my.cnf
sed -i 's/myisam_sort_buffer_size = 8M/& \ndatadir = \/usr\/local\/mysql\/data\//' $MY_CNF
echo -e "\033[35m正在初始化mysql……\033[0m"
/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/ &>/dev/null
echo -e "\033[35m关闭防火墙……\033[0m"
service iptables stop &>/dev/null
echo -e "\033[35m关闭selinux……\033[0m"
setenforce 0 &>/dev/null
echo -e "\033[35m正在开启httpd服务……\033[0m"
/usr/local/apache2/bin/apachectl start &>/dev/null
echo -e "\033[35m正在开启mysqld服务……\033[0m"
service mysqld start &>/dev/null
echo -e "\033[35m----LAMP环境搭建完成-----\033[0m"
后记:该脚本需要三个软件包:httpd-2.2.29.tar.bz2 mysql-5.1.63.tar.gz php-5.3.29.tar.bz2 ,使用时在根目录创建一个/lamp目录,把该脚本文件与三个软件包放在lamp目录下,运行脚本即可一键完成安装。
因系统环境各有差异,环境搭建中可能还需要安装其他依赖包,此处仅供参考哦!