web安装脚本

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/sbin/bash
export PATH=$PATH:/bin:/sbin:/usr/sbin
#检查是否root用户执行
if [[ "$(whoami)" != "root" ]]; then
	echo "please run this script as root" >&2
	exit 1
fi

. /etc/init.d/functions

touche /tmp/install_lamp.log

#安装apache
Install_apache(){
	if [[ `rpm -qa httpd |wc -l` != 0 ]]; then
		rpm -e httpd-2.2.15-39.el6.centos.x86_64.rpm
	fi

	for (( i = 0; i < 4; i++ )); do
		yum -y install lrzsz gcc gcc-c++ pcre pcre-devel openssl \
		openssl-devel zlib zlib-devel ncurses-devel gd gd-devel
	done

	[ -d /opt/tools/ ] && cd /opt/tools/  || exit

	#安装apr
	tar xfz apr-1.5.2.tar.gz
	cd apr-1.5.2
	./configure --prefix=/usr/local/apr
	make && make install

	i=$(echo $?)
	if [[ ${i} != 0 ]]; then
		echo 'install apr is fail' >> /tmp/install_lamp.log
		exit
	elif [[ ${i} == 0 ]]; then
		echo "install apr is succ" >> /tmp/install_lamp.log
	fi

	cd ..

	#安装apr-util
	tar xfz apr-util-1.5.4.tar.gz
	cd apr-util-1.5.4
	./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
	make && make install

	i=$(echo $?)
	if [[ ${i} != 0 ]]; then
		echo 'install apr-util is fail' >> /tmp/install_lamp.log
		exit
	elif [[ ${i} == 0 ]]; then
		echo "install apr-util is succ" >> /tmp/install_lamp.log
	fi

	cd ..

	#安装apache
	tar xfz httpd-2.4.12.tar.gz
	cd httpd-2.4.12
	./configure --prefix=/usr/local/apache2.4.12 \
	--enable-deflate \
	--enable-so \
	--enable-ssl \
	--enable-proxy-fcgi \
	--enable-rewrite \
	--with-zlib \
	--with-pcre \
	--with-apr=/usr/local/apr \
	--with-apr-util=/usr/local/apr-util \
	--enable-modules=most \
	--enable-mpms-shared=all \
	--with-mpm=event \
	--enable-expires \
	--enable-headers

	make && make install

	i=$(echo $?)
	if [[ ${i} != 0 ]]; then
		echo 'install apache is fail' >> /tmp/install_lamp.log
		exit
	elif [[ ${i} == 0 ]]; then
		echo "install apache is succ" >> /tmp/install_lamp.log
	fi

	cd ..

	ln -s /usr/local/apache2.4.12 /usr/local/apache
}

#安装mysql
Install_Mysql(){
	for (( i = 0; i < 4; i++ )); do
		yum -y install pcre-devel gcc-c++ gcc ncurses-devel \
		bison libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng \
		libpng-devel freetype freetype-devel zlib zlib-devel glibc \
		glibc-devel glib2 glib2-devel flex bzip2* curl* openssl-devel openssl
	done

	cd /opt/tools/

	#安装cmake
	tar xfz cmake-3.2.2.tar.gz
	cd cmake-3.2.2
	./bootstrap && \
	gmake && make install

	i=$(echo $?)
	if [[ ${i} != 0 ]]; then
		echo 'install camake is fail' >> /tmp/install_lamp.log
		exit
	elif [[ ${i} == 0 ]]; then
		echo "install camake is succ" >> /tmp/install_lamp.log
	fi

	cd ..

	#安装mysql
	mkdir /mydata/data -p
	groupadd -r mysql
	useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
	tar xfz mysql-5.5.43.tar.gz
	cd mysql-5.5.43

	/usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.43 \
	-DMYSQL_DATADIR=/mydata/data \
	-DSYSCONFDIR=/etc \
	-DWITH_INNOBASE_STORAGE_ENGINE=1 \
	-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
	-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
	-DWITH_FEDERATED_STORAGE_ENGINE=1 \
	-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
	-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
	-DWITH_FAST_MUTEXES=1 \
	-DENABLED_LOCAL_INFILE=1 \
	-DWITH_EMBEDDED_SERVER=1 \
	-DWITH_DEBUG=0 \
	-DWITH_READLINE=1 \
	-DWITH_SSL=bundled \
	-DWITH_ZLIB=system \
	-DWITH_LIBWRAP=0 \
	-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
	-DDEFAULT_CHARSET=utf8 \
	-DDEFAULT_COLLATION=utf8_general_ci \
	-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
	-DENABLED_LOCAL_INFILE=ON
	
	make && make install

	i=$(echo $?)
	if [[ ${i} != 0 ]]; then
		echo 'install mysql is fail' >> /tmp/install_lamp.log
		exit
	elif [[ ${i} == 0 ]]; then
		echo "install mysql is succ" >> /tmp/install_lamp.log
	fi

	ln -s /usr/local/mysql-5.5.43 /usr/local/mysql
	cd /usr/local/mysql 
	chown -R mysql:mysql .
	scripts/mysql_install_db --user=mysql --datadir=/mydata/data
	\cp /etc/my.cnf /etc/my.cnf.bak
	cd /usr/local/mysql
	\cp support-files/my-large.cnf  /etc/my.cnf
	sed -i '/thread_concurrency = 8/a datadir = /mydata/data' /etc/my.cnf
	sed -i '/datadir = \/mydata\/data/a log-slow-queries = \/mydata\/data\/slow.log' /etc/my.cnf
	sed -i '/log-slow-queries = \/mydata\/data\/slow.log/a \/mydata\/data\/error.log' /etc/my.cnf

cat >> /etc/my.cnf << EOF

[mysqld_safe]
log-error = /mydata/data/mysql_3306.err
pid-file = /mydata/data/mysqld.pid
EOF

	#安装mysql的man
	cd /usr/local/mysql
	cp support-files/mysql.server  /etc/rc.d/init.d/mysqld
	echo "MANPATH  /usr/local/mysql/man" >>/etc/man.config
	ln -sv /usr/local/mysql/include  /usr/include/mysql
	echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
	ldconfig
	echo 'PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile
	source /etc/profile
	/etc/init.d/mysqld start
	/usr/local/mysql/bin/mysql --version && \
	echo -e  "\e[31m mysql install is OK\e[0m"
	
	#删除无用用户与测试库
	echo -e "delete from mysql.user where user='';" | mysql
	echo -e "delete from mysql.user where host='::1';" | mysql	
	echo -e "drop database test;" | mysql

}

#安装php
Install_Php(){
	for (( i = 0; i < 4; i++ )); do
		yum -y install gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel \
		libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel \
		glib2 glib2-devel flex bzip2* curl curl-devel libmcrypt libmcrypt-devel mhash mhash-devel \
		mcrypt libevent libevent-devel openssl openssl-devel
	done

	cd /opt/tools

	tar xfz php-5.6.8.tar.gz
	cd php-5.6.8
	
	./configure \
	--prefix=/usr/local/php-5.5.42 \
	--with-mysql=mysqlnd \
	--with-pdo-mysql=mysqlnd \
	--with-mysqli=mysqlnd \
	--with-openssl \
	--enable-fpm \
	--enable-sockets \
	--enable-sysvshm  \
	--enable-mbstring \
	--with-freetype-dir \
	--with-jpeg-dir \
	--with-png-dir \
	--with-zlib-dir \
	--with-libxml-dir=/usr \
	--enable-xml \
	--with-config-file-path=/etc \
	--with-config-file-scan-dir=/etc/php.d \
	--with-bz2 \
	--with-curl \
	--with-gd

	make && make install

	i=$(echo $?)
	if [[ ${i} != 0 ]]; then
		echo 'install php is fail' >> /tmp/install_lamp.log
		exit
	elif [[ ${i} == 0 ]]; then
		echo "install php is succ" >> /tmp/install_lamp.log
	fi
	ln -s /usr/local/php-5.5.42 /usr/local/php

	cp php.ini-production /etc/php.ini

	cp sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm
	chmod +x /etc/rc.d/init.d/php-fpm
	chkconfig --add php-fpm
	chkconfig php-fpm on
	
	cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
}


Install_apache
Install_Mysql
Install_Php