A goal is a dream with a deadline. Much effort, much prosperity.

环境:CentOS release 6.5  2.6.32-431.el6.x86_64

 #!/bin/bash
 #--
 #下为软件版本号、安装路径、数据存放路径、密码、URL等,如有不同、则自行修改变量即可
 #释:ylb为依赖包1/
 #释:path为路径1/
 #释:mysqlcatalog为MySQL的安装路径
 #释:mysqldata为MySQL的数据存放位置
 #释:environment为PHP的环境1为开发版样例文件2为生产版样例文件
 http='httpd-2.2.31'
 mysql='mysql-5.7.2-m12'
 php='php-5.3.28'
 libmcrypt='libmcrypt-2.5.8'
 mhash='mhash-0.9.9.9'
 mcrypt='mcrypt-2.6.8'
 cmake='cmake-2.8.12'
 ZendGuardLoader='ZendGuardLoader-php-5.3-linux-glibc23-x86_64'
 ylb1='zlib-devel libxml2-devel ncurses-devel'
 ylb2='php php-cli php-ldap php-common php-mysql httpd mysql-server'
 path1='/usr/src'
 path2='/usr/local'
 mysqlcatalog='/usr/local/mysql/'
 mysqldata='/usr/local/mysql/data'
 mysqlrootpasswd='
 environment1='php.ini-development'
 environment2='php.ini-production'
 epel='https://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm'
 repo='http://mirrors.aliyun.com/repo/Centos-6.repo'

 aliyum() {
  -i  -t  www.baidu.com
  ]
 then
     mv /etc/yum.repos.d/* /tmp
     wget $epel
     yum -y localinstall epel*.rpm
     wget -O /etc/yum.repos.d/CentOS-Base.repo $repo
     yum clean all
     yum makecache
 else
     echo "Network is not connected"
 fi
 }
 #Install depend
 rpm -q $ylb2 | awk '{print $1}' > b.txt
 sed -i '/^package/d' b.txt
 for i in $(cat b.txt)
 do
     rpm -e $i --nodeps > /dev/null
 done

 yum -y install $ylb1 > /dev/null
 if [ ! $? -eq 0 ]
 then
     aliyum
     yum -y install $ylb1 > /dev/null
 fi
 #Install httpd
 tar xf $http.tar.gz -C $path1
 cd $path1/$http
 ./configure --prefix=$path2/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi && make && make install
 echo $? >> /root/debug.txt
 echo "install apache time" >> /root/debug.txt
 cd ~
 ln -s $path2/httpd/bin/* /usr/local/bin/
 cp $path2/httpd/bin/apachectl /etc/init.d/httpd
 sed -i '1a# chkconfig:35 20 80\n# description:web' /etc/init.d/httpd
 chkconfig --add httpd
 chkconfig httpd on
 chkconfig --list httpd
 sed -i '98aServerName www.wjl.com:80' $path2/httpd/conf/httpd.conf
 service httpd start
 netstat -anpt | grep :80 >> /root/debug.txt
 #Install MySql
 tar xf $cmake.tar.gz -C $path1
 cd $path1/$cmake
 ./configure && gmake && gmake install
 groupadd mysql
 useradd -M -s /sbin/nologin -g mysql mysql
 cd ~
 tar xf $mysql.tar.gz -C $path1
 cd $path1/$mysql
 cmake -DCMAKE_INSTALL_PREFIX=$path2/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc && make && make install
 echo $? >> /root/debug.txt
 echo "install mysql time" >> /root/debug.txt
 cp support-files/my-default.cnf /etc/my.cnf
 cp support-files/mysql.server /etc/init.d/mysqld
 chmod +x /etc/init.d/mysqld
 chkconfig --add mysqld
 chkconfig --list mysqld
 echo "PATH=$PATH:$path2/mysql/bin" >> /etc/profile
 source /etc/profile
 chown -R mysql:mysql $path2/mysql/
 $path2/mysql/scripts/mysql_install_db --basedir=$mysqlcatalog --datadir=$mysqldata --user=mysql
 service mysqld start
 netstat -anpt | grep :3306 >> /root/debug.txt
 cd ~
 mysqladmin -u root password $mysqlrootpasswd
 #Install PHP
 tar xf $libmcrypt.tar.gz -C $path1
 cd $path1/$libmcrypt
 ./configure
 make && make install
 ln -s $path2/lib/libmcrypt.* /usr/lib/
 cd ~
 tar xf $mhash.tar.gz -C $path1
 cd $path1/$mhash
 ./configure
 make && make install
 ln -s $path2/lib/libmhash* /usr/lib/
 cd ~
 tar xf $mcrypt.tar.gz -C $path1
 cd $path1/$mcrypt
 export LD_LIBRARY_PATH=$path2/lib:$ LD_LIBRARY_PATH
 ./configure
 make && make install
 cd ~
 tar xf $php.tar.gz -C $path1
 cd $path1/$php
 ./configure --prefix=$path2/php5 --with-mcrypt --with-apxs2=$path2/httpd/bin/apxs --with-mysql=$path2/mysql --with-config-file-path=$path2/php5 --enable-mbstring && make && make install
 if [ ! $? -eq 0 ]
 then
     yum -y install libtool*
     ./configure --prefix=$path2/php5 --with-mcrypt --with-apxs2=$path2/httpd/bin/apxs --with-mysql=$path2/mysql --with-config-file-path=$path2/php5 --enable-mbstring && make && make install
 fi
 echo $? >> /root/debug.txt
 echo "install php time" >> /root/debug.txt
 cp $path1/$php/$environment1 $path2/php5/php.ini
 grep -v "^;" /usr/local/php5/php.ini  | grep -v "^$"
 sed -i "/default_charset/s#.*\(default_charset\).*#\1 = "utf-8"#g" $path2/php5/php.ini
 sed -i "/file_uploads/s#\(file_uploads\).*#\1 = On#g" $path2/php5/php.ini
 sed -i "/upload_max_filesize/s#.*\(upload_max_filesize\).*#\1 = 2M#g" $path2/php5/php.ini
 sed -i "/max_file_uploads/s#\(max_file_uploads\).*#\1 = 20#g" $path2/php5/php.ini
 sed -i "/post_max_size/s#.*\(post_max_size\).*#\1 = 8M#g" $path2/php5/php.ini
 sed -i "/short_open_tag/s#.*\(short_open_tag\).*#\1 = On#g" $path2/php5/php.ini
 cd ~
 tar xf $ZendGuardLoader.tar.gz -C $path1
 cd $path1/$ZendGuardLoader/php-5.3.x/
 cp ZendGuardLoader.so $path2/php5/lib/php/
 sed -i "1azend_extension=${path2}/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1" $path2/php5/php.ini
 sed -i "/LoadModule php5_module/s#.*\(LoadModule php5_module\).*#\1 modules\/libphp5.so#g" $path2/httpd/conf/httpd.conf
 sed -i "55a AddType application\/x-httpd-php \.php \.phtml" $path2/httpd/conf/httpd.conf
 sed -i "/DirectoryIndex/s#.*\(DirectoryIndex\).*#\1 index.php index.html index.htm#g" $path2/httpd/conf/httpd.conf
 cat << END >> $path2/httpd/htdocs/test1.php
 <?php
 phpinfo ();
 ?>
 END
 cat << END >> $path2/httpd/htdocs/test2.php
 <?php
 \$link=mysql_connect('localhost','root','$mysqlrootpasswd')
 ;
 if(\$link) echo "Connect Successfully!";
 else echo "Connect Faild!";
 mysql_close();
 ?>
 END
 echo "已执行完毕、成功与否请查看/root/debug.txt内容,非0为安装失败"
 echo "1、检查软件版本号是否相同"
 echo "2、查看为非0的下的提示报错位置进行修改"
 echo "测试PHP是否正常工作:http://localhost/test1"
 echo "测试PHP能否连接MySQL:http://localhost/test2"
05-18 11:35