lamp安装脚本

执行:

wget http://sourceforge.net/projects/sourcefile/files/lamp/lamp_install.sh/download && sh lamp_install.sh


lamp_install.sh的内容:

#!/bin/bash

#centos6.4:LAMP(httpd-2.4.6.tar.gz,mysql-5.6.10.tar.gz,php-5.5.4.tar.gz)

#date:2013.9.24

#email:[email protected]

#Make sure the user is root

if [ $EUID -ne 0 ]; then

echo "This script must be run as root" 1>&2

exit 1

fi

#===============================================================================

#DESCRIPTION:disable selinux.

#USAGE:disable_selinux

#===============================================================================

service iptables stop

if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

setenforce 0

fi

#===============================================================================

#uninstall apache php httpd mysql

#===============================================================================

rpm -qa | grep php

if [ $? -eq 0 ]; then

rpm -e php && rpm -e php-cli && rpm -e php-common && rpm -e php-mysql

fi


rpm -qa | grep mysql

if [ $? -eq 0 ]; then

rpm -e mysql-devel && rpm -e mysql

fi


rpm -qa | grep httpd

if [ $? -eq 0 ]; then

rpm -e httpd && rpm -e httpd-tools && rpm -e apr-util-ldap

fi

if [ -e /etc/httpd ]; then

rm -rf /etc/httpd

fi

#===============================================================================

#env

#===============================================================================

lamp_path=/usr/local/src/lamp

lamp_log=/root/lamp_install.log

ip=$(ifconfig eth0 | grep Bcast | awk -F ":" '{print $2}' | cut -d " " -f 1)

htdocs=/usr/local/apache/htdocs

lamp_down=/root/lamp_down

#===============================================================================

#download lamp packet

#===============================================================================

if [ ! -d $lamp_down ];then

mkdir $lamp_down

fi

wget http://sourceforge.net/projects/sourcefile/files/lamp/lamp_pack.tar.gz/download && tar zxf lamp_pack.tar.gz -C $lamp_down && rm -rf lamp_pack.tar.gz

#===============================================================================

#uncompress file

#===============================================================================

if [ ! -d $lamp_path ];then

mkdir $lamp_path

fi


cd


for i in $lamp_down/*.tar.gz

do

tar zxf $i -C $lamp_path

done


# get ready for lamp yum install the necessary relevance App

yum -y install gcc gcc-c++ wget make automake ntp autoconf kernel-devel ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel

#===============================================================================

#Apache install

#===============================================================================

echo "Apache install start!"


#install apr-1.4.6

cd $lamp_path/apr-1.4.6

./configure --prefix=/usr/local/apr

make && make install

sleep 5

#install apr-util-1.5.2

cd $lamp_path/apr-util-1.5.2

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make && make install

sleep 5

#install pcre-8.32

cd $lamp_path/pcre-8.32

./configure

make && make install

sleep 5

#install apache-2.4.6

cd $lamp_path/httpd-2.4.6

./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-so --enable-dav --enable-default=shared --enable-expries=shared --enable-headers=shared --enable-rewrite --enable-static-support --enable-ssl --enable-setenvif --with-mpm=prefork --enable-maintainer-mode --enable-mods-share=all --enable-cache

make && make install

sleep 5

cd

ln -s /usr/local/apache/bin/* /usr/local/bin/

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

sed -i '1a\#chkconfig: 35 85 15 \n#description:startup script for apache server' /etc/init.d/httpd

chkconfig --add httpd

chkconfig httpd on

sed -i '228s/Indexes//' /usr/local/apache/conf/httpd.conf

sed -i '235s/None/All/' /usr/local/apache/conf/httpd.conf

sed -i '248s/index.html/index.php index.html/' /usr/local/apache/conf/httpd.conf

sed -i '376a\AddType application/x-httpd-php .php' /usr/local/apache/conf/httpd.conf

sed -i '190a\ServerName localhost' /usr/local/apache/conf/httpd.conf


#test apache configure

httpd -t >> $lamp_log

echo "$(date +%c) Apache is Installed" >> $lamp_log

service httpd start && echo "$(date +%c) Apache is started Good!" >> $lamp_log

#===============================================================================

#mysql install

#===============================================================================

#remove old file


if [ -e /etc/my.cnf ] ; then

rm -rf /etc/my.cnf

fi


if [ -e /etc/init.d/mysqld ] ; then

rm -rf /etc/rc.d/init.d/mysqld

fi

#useradd

User=$(cat /etc/shadow | grep mysql | wc -l )

if [ $User -ne 1 ]; then

/usr/sbin/useradd -M -u 49 -s /sbin/nologin mysql

fi

#install cmake-2.8.6.tar.gz

cd $lamp_path/cmake-2.8.6

./bootstrap

gmake && gmake install

sleep 5

#install mysql-5.6.10.tar.gz

cd $lamp_path/mysql-5.6.10

cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306

make && make install

echo "$(date +%c) mysql is installed " >> $lamp_log

sleep 5

chown -R mysql:mysql /usr/local/mysql

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

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

chkconfig --add mysqld

chkconfig mysqld on

ln -s /usr/local/mysql/bin/* /usr/local/bin

service mysqld start && echo "$(date +%c) mysql service is started" >> $lamp_log

#===============================================================================

#php install

#===============================================================================

#ready for php

cd $lamp_path/libmcrypt-2.5.8

./configure --prefix=/usr

make && make install

sleep 3

cd $lamp_path/mhash-0.9.9.9

./configure --prefix=/usr

make && make install

sleep 3

cd $lamp_path/libiconv-1.14

./configure --prefix=/usr/local/libiconv

make && make install

sleep 3

/sbin/ldconfig

cd $lamp_path/mcrypt-2.6.8

./configure

make && make install

sleep 3

#install php-5.5.4

echo "$(date +%c) php-5.2.17 start install " >> $lamp_log

if [ -e /etc/php.ini]; then

rm -rf /etc/php.ini

fi

cd $lamp_path/php-5.5.4

./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --enable-sockets --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --enable-soap --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-apxs2=/usr/local/apache/bin/apxs --enable-xml --with-curl --enable-fpm --enable-mbstring --with-mcrypt --with-gd --with-openssl --with-mhash --enable-zip

make && make install

sleep 5

cp php.ini-development /usr/local/php/etc/php.ini

sed -i '692a\default_charset = "utf-8"' /usr/local/php/etc/php.ini

sed -i '210s/Off/On/' /usr/local/php/etc/php.ini

sed -i '922a\date.timezone = Asia/Shanghai' /usr/local/php/etc/php.ini

#phpinfo

cat >> $htdocs/phpinfo.php << EOF

<?php

phpinfo();

?>

EOF

/etc/init.d/httpd restart

/etc/init.d/mysqld restart

echo "##########warning#############" >> $lamp_log

echo "Go to http://$ip/phpinfo.php" >> $lamp_log

echo "##########end################" >> $lamp_log


你可能感兴趣的:(linux,shell,lamp)