| 
	Lamp(linux+apache+mysql+php)源码包最新版编译安装步骤 
	本次基于CentOS Minimal系统搭建 
	
		#!/bin/sh
		########################## Written By Qitan ####################################
		################## BLOG: http://blog.catjia.com #################################
		#################### EMAIL: qqing_lai@hotmail.com ##############################
		########################## DATE: 2011-11-09 ####################################
		 
		PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
		export PATH
		 
		dir="/usr/local"
		hostname="www.7tan.info"
		mycnf="my-innodb-heavy-4G.cnf"
		 
		# Check if user is root
		if [ $(id -u) != "0" ]; then
		    echo "Error: You must be root to run this script, please use root to setup operation system"
		    exit 1
		fi
		 
		#################################### Install LAMP… ###########################
		 
		# Download Files…
		 
		function func() {
		if [ -s $file ]; then
		    printf "n"
		    echo "$file Found."
		else
		    printf "n"
		    echo "$file not found, download now…"
		    wget -c $url
		    if [ -s $file ]; then
		    echo "$file already download."
		    printf "n"
		    else
		    echo -e "33[7m"
		    echo "$file cannot download, please download manually and rerun this script." >> /root/qq_lamp.log
		    echo -e "33[0m"
		    exit 0
		    fi
		fi
		}
		 
		function file_down() {
		    local file=httpd-2.2.21.tar.bz2 url=http://labs.renren.com/apache-mirror//httpd/httpd-2.2.21.tar.bz2
		    func
		    local file=cmake-2.8.6.tar.gz url=http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz
		    func
		    local file=mysql-5.5.16.tar.gz url=http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.16.tar.gz/from/http://mirror.services.wisc.edu/mysql/
		    func
		    local file=php-5.3.8.tar.bz2 url=http://cn2.php.net/get/php-5.3.8.tar.bz2/from/this/mirror
		    func
		    local file=phpMyAdmin-3.4.7-all-languages.tar.bz2 url=http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.7/phpMyAdmin-3.4.7-all-languages.tar.bz2
		    func
		    local file=xcache-1.3.2.tar.gz url=http://xcache.lighttpd.net/pub/Releases/1.3.2/xcache-1.3.2.tar.gz
		    func
		    local file=ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz url='http://blog.catjia.com/wp-content/uploads/2011/12/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz'
		    func
		    local file=rpmforge-release-0.5.2-2.el6.rf.i686.rpm url=http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
		    func
		}
		 
		# function file_down()
		file_down
		 
		    # Add additional resource/rpm
		rpm –import http://apt.sw.be/RPM-GPG-KEY.dag.txt
		rpm -K rpmforge-release-0.5.2-2.el6.rf.i686.rpm
		rpm -i rpmforge-release-0.5.2-2.el6.rf.i686.rpm
		 
		sleep 1
		 
		yum -y install wget ftp ntp kernel kernel-devel make gcc gcc-c++ autoconf automake vim ntsysv crontab* man ImageMagick-devel rar unrar unzip ncurses-devel zlib* flex* libxml* libmcrypt* mhash* libcurl-devel libtool libtool-ltdl-devel* bison bison-devel libjpeg* gd gd-devel openssl* cronolog bzip2-devel libpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel >> ntpdate time.nist.gov >> yum -y update
		 
		sleep 3
		 
		# Install AMP…
		 
		# Install phpMyAdmin
		    alias cp='cp' >> tar -jxvf phpMyAdmin-3.4.7-all-languages.tar.bz2 >> cp -r phpMyAdmin-3.4.7-all-languages /data/www/wwwroot/eyo/phpMyAdmin >> source /root/.bashrc
		cat > /data/www/wwwroot/eyo/phpMyAdmin/config.inc.php <<EOF
		<?php
		 /* This is needed for cookie based authentication to encrypt password in
		 * cookie
		 */
		$cfg['blowfish_secret'] = 'qitan99'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
		 
		/*
		 * Servers configuration
		 */
		 
		$i = 0;
		 
		/*
		 * First server
		 */
		$i++;
		/* Authentication type */
		$cfg['Servers'][$i]['auth_type'] = 'cookie';
		/* Server parameters */
		$cfg['Servers'][$i]['host'] = 'localhost';
		$cfg['Servers'][$i]['connect_type'] = 'tcp';
		$cfg['Servers'][$i]['compress'] = false;
		/* Select mysqli if your server has it */
		$cfg['Servers'][$i]['extension'] = 'mysql';
		$cfg['Servers'][$i]['AllowNoPassword'] = false;
		 
		$cfg['UploadDir'] = '';
		$cfg['SaveDir'] = '';
		 
		?>
		EOF
		 
		# Install Cmake and MySQL
		 
		printf "Start install cmake…n"
		    tar -zxvf cmake-2.8.6.tar.gz >> cd cmake-2.8.6 >> ./configure >> gmake >> make install >> make clean
		 
		# 创建数据库安装目录
		    groupadd mysql >> useradd mysql -g mysql -s /sbin/nologin -d /data/mysql/data/ >> chown mysql.mysql -R /data/mysql
		    cd .. >> tar -zxvf mysql-5.5.16.tar.gz >> cd mysql-5.5.16 >> cmake -DCMAKE_INSTALL_PREFIX=$dir/mysql -DMYSQL_DATADIR=/data/mysql/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DWITH_DEBUG=0 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 >> make >> make install >> make clean
		    cp -r support-files/$mycnf /etc/my.cnf >> sed -i '47 askip-grant-tables' /etc/my.cnf >> chmod +x scripts/mysql_install_db >> ./scripts/mysql_install_db –user=mysql –basedir=$dir/mysql –datadir=/data/mysql/data
		    cp -r support-files/mysql.server /etc/rc.d/init.d/mysqld >> sed -i '46,47s/^/#/' /etc/rc.d/init.d/mysqld >> sed -i '46 abasedir='$dir'/mysql/' /etc/rc.d/init.d/mysqld >> sed -i '48 adatadir=/data/mysql/data/' /etc/rc.d/init.d/mysqld >> chmod +x /etc/rc.d/init.d/mysqld >> chkconfig –levels 345 mysqld on >> ln -sf $dir/mysql/bin/* /usr/local/bin/ >> ln -sf $dir/mysql/bin/* /usr/bin/
		    /etc/init.d/mysqld start
		    mysql -n <<EOF
		drop database test;
		use mysql;
		delete from user where user='';
		update user set password=password('$rpass') where user='root';
		grant all privileges on *.* to root@"%" identified by '$rpass';
		create database eyo;
		grant all privileges on eyo.* to eyoadmin@localhost identified by '$passwd';
		grant all privileges on eyo.* to eyoadmin@"%" identified by '$passwd';
		flush privileges;
		quit
		EOF
		    sed -i '/skip-grant-tables/d' /etc/my.cnf
		    /etc/init.d/mysqld restart    
		 
		sleep 3
		 
		# Install Apache
		 
		# 创建网页文件目录
		    groupadd www >> useradd www -g www -s /sbin/nologin -d /data/www >> chown www.www /data/www/wwwroot >> chmod 777 /data/www/wwwroot
		    cd ../ >> tar -jxvf httpd-2.2.21.tar.bz2 >> cd httpd-2.2.21 >> ./configure –prefix=$dir/apache2 –with-ssl=/usr/ –enable-ssl –enable-so –enable-mime-magic –enable-cache –enable-mem-cache –with-included-apr –enable-deflate=shared –enable-expires=shared –enable-rewrite=shared –enable-static-support >> make >> make install >> make clean >> echo "$dir/apache2/bin/apachectl start" >> /etc/rc.d/rc.local
		 
		# Install PHP
		printf "Start install PHP…n"
		    cd ../ >> tar -jxvf php-5.3.8.tar.bz2 >> cd php-5.3.8 >> ./configure –prefix=$dir/php –with-apxs2=$dir/apache2/bin/apxs –with-config-file-path=$dir/php/etc –with-mysql=$dir/mysql –with-libxml-dir –with-jpeg-dir=/usr/lib/ –with-gd –enable-gd-native-ttf –with-png-dir –with-bz2 –with-freetype-dir –with-iconv –with-zlib-dir –with-openssl=/usr/ –with-mcrypt –enable-soap –enable-magic-quotes –enable-ftp –enable-mbstring –enable-exif –disable-cgi –with-pear –enable-zip –with-mhash –with-openssl –enable-inline-optimization –disable-ipv6 –disable-cli –with-mysqli=$dir/mysql/bin/mysql_config –enable-bcmath  –with-curl >> make >> make install >> make clean
		    mkdir $dir/php/etc >> cp -r php.ini-production $dir/php/etc/php.ini >> sed -i 's/^;date.timezone =.*/>ndate.timezone = Asia/Chongqing/' $dir/php/etc/php.ini >> ln -sf $dir/php/bin/* /usr/local/bin/ >> ln -sf $dir/php/bin/* /usr/bin/
		    
		# Install Xcache
		    cd .. >> tar -zxvf xcache-1.3.2.tar.gz >> cd xcache-1.3.2 >> $dir/php/bin/phpize >> ./configure –with-php-config=$dir/php/bin/php-config –enable-xcache –enable-xcache-optimizer –enable-xcache-coverager >> make >> make install >> make clean
		    cat >> $dir/php/etc/php.ini <<EOF
		;add the following code at the end of file php.ini
		[xcache-common]
		zend_extension      = $dir/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so
		 
		[xcache.admin]
		xcache.admin.user   = "admin"
		;生成密码: echo -n "passwd"| md5sum
		xcache.admin.pass   = "f50dff779a142c7e0987755a247109f7"
		 
		[xcache]
		; Change xcache.size to tune the size of the opcode cache
		xcache.size         = 24M
		xcache.shm_scheme   = "mmap"
		xcache.count        = 4
		xcache.slots        = 8K
		xcache.ttl          = 0
		xcache.gc_interval  = 0
		 
		; Change xcache.var_size to adjust the size of variable cache
		xcache.var_size     = 8M
		xcache.var_count    = 1
		xcache.var_slots    = 8K
		xcache.var_ttl      = 0
		xcache.var_maxttl   = 0
		xcache.var_gc_interval =     300
		xcache.test         = Off
		xcache.readonly_protection = On
		xcache.mmap_path    = "/tmp/xcache"
		xcache.coredump_directory =   ""
		xcache.cacher       = On
		xcache.stat         = On
		xcache.optimizer    = Off
		 
		[xcache.coverager]
		xcache.coverager    = On
		xcache.coveragedump_directory = ""
		EOF
		 
		# If ZendGuardLoader have download manually, install zend optimizer    
		# Install Zend Optimizer
		if [ -s ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz ]; then
		    cd ../ >> tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz >> cp -r ZendGuardLoader-php-5.3-linux-glibc23-i386 $dir/php/lib/php/extensions/
		    cat >> $dir/php/etc/php.ini <<EOF
		zend_extension    = $dir/php/lib/php/extensions/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so
		zend_loader.enable=1
		zend_loader.disable_licensing=0
		EOF
		 
		fi
		 
		# Combined Apche and PHP
		 
		    # Modify file httpd.conf    
		    sed -i 's/#ServerName www.example.com:80/ServerName localhost/' $dir/apache2/conf/httpd.conf
		    sed -i 's/ServerAdmin you@example.com/ServerAdmin qitan@goego.net/g' $dir/apache2/conf/httpd.conf
		    sed -i 's/AddType application/x-gzip .gz .tgz.*/>n    AddType application/x-httpd-php .php/' $dir/apache2/conf/httpd.conf
		    sed -i 's/DirectoryIndex index.html/DirectoryIndex index.html index.htm index.php/' $dir/apache2/conf/httpd.conf
		    sed -i '122 a    Allow from all' $dir/apache2/conf/httpd.conf
		    cat >> $dir/apache2/conf/httpd.conf <<EOF
		Include conf/extra/httpd-mpm.conf
		Include conf/extra/httpd-info.conf
		Include conf/extra/httpd-vhosts.conf
		Include conf/extra/httpd-default.conf
		 
		<IfModule mod_expires>
		ExpiresActive On
		ExpiresDefault A60
		ExpiresByType image/x-icon A2592000
		ExpiresByType application/x-javascript A2592000
		ExpiresByType text/css A2592000
		ExpiresByType image/gif A604800
		ExpiresByType image/png A604800
		ExpiresByType image/jpeg A604800
		ExpiresByType text/plain A604800
		ExpiresByType application/x-shockwave-flash A604800
		ExpiresByType video/x-flv A604800
		ExpiresByType application/pdf A604800
		ExpiresByType text/html A60
		</IfModule>
		 
		<IfModule mod_deflate.c>
		SetOutputFilter DEFLATE
		AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript
		</IfModule>
		EOF
		    # Setup vhost
		    cd $dir/apache2/conf/extra >> mv httpd-vhosts.conf httpd-vhosts.conf.bak
		    cat > httpd-vhosts.conf <<EOF
		NameVirtualHost *:80
		 
		<VirtualHost *:80>
		    DocumentRoot "/data/www/wwwroot/eyo"
		    ServerName $hostname
		    ErrorLog "/data/www/logs/$hostname.error.log"
		#    CustomLog "|/usr/sbin/cronolog /data/www/logs/$hostname.access.log.%Y%m%d" combined
		    CustomLog "/data/www/logs/$hostname-access_log" combined
		<Directory "/data/www/wwwroot/eyo">
		#    Options None
		#    AllowOverride None
		    Options FollowSymLinks
		    AllowOverride All
		    Order allow,deny
		    Allow from all
		</Directory>
		<location /server-status>
		    SetHandler server-status
		    Order Deny,Allow
		    Deny from all
		    Allow from 127.0.0.1
		</location>
		</VirtualHost>
		EOF
		 
		    mv httpd-default.conf httpd-default.conf.bak
		    cat > httpd-default.conf <<EOF
		Timeout 60
		KeepAlive On
		MaxKeepAliveRequests 500
		KeepAliveTimeout 15
		UseCanonicalName Off
		AccessFileName .htaccess
		ServerTokens Prod
		ServerSignature Off
		HostnameLookups Off
		EOF
		 
		    mv httpd-info.conf httpd-info.conf.bak
		    cat > httpd-info.conf <<EOF
		<Location /server-status>
		    SetHandler server-status
		    Order deny,allow
		    Deny from all
		    Allow from 127.0.0.1
		</Location>
		<Location /server-info>
		    SetHandler server-info
		    Order deny,allow
		    Deny from all
		    Allow from .example.com
		</Location>
		 
		ExtendedStatus On
		EOF
		 
		    mv httpd-mpm.conf httpd-mpm.conf.bak 
		    cat > httpd-mpm.conf <<EOF
		<IfModule !mpm_netware_module>
		    PidFile "logs/httpd.pid"
		</IfModule>
		<IfModule !mpm_winnt_module>
		<IfModule !mpm_netware_module>
		LockFile "logs/accept.lock"
		</IfModule>
		</IfModule>
		<IfModule mpm_prefork_module>
		    ServerLimit           1000
		    StartServers          10
		    MinSpareServers       10
		    MaxSpareServers      20
		    MaxClients          1000
		    MaxRequestsPerChild   5000
		</IfModule>
		<IfModule mpm_worker_module>
		    StartServers          4
		    MaxClients          300
		    MinSpareThreads      25
		    MaxSpareThreads      75
		    ThreadsPerChild      25
		    MaxRequestsPerChild   0
		</IfModule>
		<IfModule mpm_beos_module>
		    StartThreads            10
		    MaxClients              50
		    MaxRequestsPerThread 10000
		</IfModule>
		<IfModule mpm_netware_module>
		    ThreadStackSize      65536
		    StartThreads           250
		    MinSpareThreads         25
		    MaxSpareThreads        250
		    MaxThreads            1000
		    MaxRequestsPerChild      0
		    MaxMemFree             100
		</IfModule>
		<IfModule mpm_mpmt_os2_module>
		    StartServers           2
		    MinSpareThreads        5
		    MaxSpareThreads       10
		    MaxRequestsPerChild    0
		</IfModule>
		<IfModule mpm_winnt_module>
		    ThreadsPerChild      150
		    MaxRequestsPerChild    0
		</IfModule>
		EOF
		    # Vhost Directory and basic setup
		    mkdir /data/www/wwwroot/eyo >> chmod 777 /data/www/wwwroot/eyo
		    cat > /data/www/wwwroot/eyo/index.html <<EOF
		<html>
		<head>
		<title>LAMP Install Success.</title>
		</head>
		<body>
		<p>########################## Written By Qitan ####################################</p>
		<p>####################### BLOG: http://blog.catjia.com ################################</p>
		<p>####################### EMAIL: qqing_lai@hotmail.com ##############################</p>
		<p>########################## DATE: 2011-11-09 ###################################</p>
		<p>################# LAMP Have Successfully Installed., enjoy it! ############################</p>
		</body>
		</html>
		EOF
		    cat > /data/www/wwwroot/eyo/phpinfo.php <<EOF
		<html>
		<head>
		<title>LAMP Install Success.</title>
		</head>
		<body>
		<p>########################## Written By Qitan ####################################</p>
		<p>####################### BLOG: http://blog.catjia.com ################################</p>
		<p>####################### EMAIL: qqing_lai@hotmail.com ##############################</p>
		<p>########################## DATE: 2011-11-09 ###################################</p>
		<p>################# LAMP Have Successfully Installed., enjoy it! ############################</p>
		</body>
		</html>
		 
		<?php
		    phpinfo();
		?>
		EOF
		    $dir/apache2/bin/apachectl start 
 
 
 (责任编辑:IT)
 |