单机lamp环境一键安装部署


#!/bin/bash

#author by martin 2015-07-22

#auto install lamp


H_FILE=httpd-2.2.31.tar.gz

H_DIR=httpd-2.2.31


M_FILE=mysql-5.1.72.tar.gz

M_DIR=mysql-5.1.72


P_FILE=php-5.4.22.tar.gz

P_DIR=php-5.4.22


if [ -z $1 ];then

        echo -e "\033[32m please select install menu follow \033[0m"

        echo "1)编译安装apache"


        echo "2)编译安装mysql"

        echo "3)编译安装php"

        echo "4)整合lamp环境"

        echo -e "\033[32m Usage:{/bib/sh $0 1|2|3|4}\033[0m"

        exit

fi





#apache auto install

echo -e "\033[32m prepare apache env \033[0m"


if [ $1 -eq 1 ];then


yum install apr apr-util apr-devel apr-util-devel   -y

cd /usr/src

wget  http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gz

tar xf $H_FILE

cd $H_DIR

./configure --prefix=/usr/local/apache2/ --enable-rewrite  --enable-so --with-mpm=worker \

--enable-expires  --enable-deflate  --enable-headers

make && make install

if [ $? -eq 0 ];then

        echo "apache install successful"

fi


fi


#mysql auto install

echo -e "\033[32m prepare mysql \033[0m" 



if [ $1 -eq 2 ];then

groupadd mysql

useradd -s /sbin/nologin -g mysql -M mysql

cd /usr/src


wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72.tar.gz

tar xf $M_FILE

cd $M_DIR

./configure --prefix=/usr/local/mysql --enable-assembler  --with-mysqld-user=mysql \

--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --localstatedir=/usr/local/mysql/data

fi


if [ $? -eq 0 ];then

        make &&make install

fi

if [ $? -eq 0 ];then

        echo -e "\033[32mmysql install succefull\033[0m"


        /bin/cp support-files/my-small.cnf /etc/my.cnf

        /bin/cp support-files/mysql.server /etc/init.d/mysqld

        chmod +x /etc/init.d/mysqld


        cd /usr/local/mysql/


mkdir data

chown mysql.mysql /usr/local/mysql/

./bin/mysql_install_db --user=mysql



fi


#php auto install

echo -e "\033[32m prepare php \033[0m"


if [ $1 -eq 3 ];then

cd /usr/src

wget http://mirrors.sohu.com/php/php-5.4.22.tar.gz

tar xf $P_FILE

cd $P_DIR

./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs \

--with-mysql=/usr/local/mysql/     --enable-sockets

if [ $? -eq 0  ];then

        echo -e "\033[32m php install successful\033[0m"

fi

make&&make install

/bin/cp /usr/src/php-5.4.22/php.ini-production /usr/local/php5/lib/php.ini

fi



#lamp整合 auto install

echo -e "\033[32m prepare lamp整合 \033[0m"

if [ $1 -eq 4 ];then

        sed -i 's#DirectoryIndex index.html#DirectoryIndex index.php index.html#g'   /usr/local/apache2/conf/httpd.conf

        echo "AddType     application/x-httpd-php .php" >>/usr/local/apache2/conf/httpd.conf

cat > /usr/local/apache2/htdocs/index.php<<EOF

<?php

phpinfo();

?>

EOF


fi


你可能感兴趣的:(apache,mysql,PHP,lamp)