Apache:服务器地址192.168.88.128

mysql:服务器地址192.168.88.140

php:服务器地址192.168.88.139

编译安装过程,服务器的先后顺序:  apache--->mysql--->php 或者 mysql--->apache--->php


第一步:编译安装Http2.4.18:    192.168.88.128

1.所需要的关联包,

    apr-1.5.1.tar.gz 

    apr-util-1.5.2.tar.bz2

    httpd-2.4.18.tar.bz2

下载地址:http://pan.baidu.com/s/1c0WTfTe

yum安装所需的rpm包及开发包组

    yum -y groupinstall "Server Platform Development" "Development tools"

    yum -y install pcre pcre-devel

2.编译安装apr:    

[root@www ~]# tar xf apr-1.5.1.tar.gz 

[root@www ~]# cd apr-1.5.1

[root@www apr-1.5.1]# ./configure --prefix=/usr/local/apr

[root@www apr-1.5.1]# make && make install    


3.编译安装apr-util:

[root@www ~]# tar xf apr-util-1.5.2.tar.bz2 

[root@www ~]# cd apr-util-1.5.2

[root@www apr-util-1.5.2]# ./configure --prefix=/usr//local/apr-util --with-apr=/usr/local/apr/

[root@www apr-util-1.5.2]# make && make install


4.编译安装http:

[root@www apr-1.5.1]# cd

[root@www ~]# tar xf httpd-2.4.18.tar.gz

[root@www ~]# cd httpd-2.4.18 

[root@www httpd-2.4.18]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --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

[root@www httpd-2.4.18]# make && make install

[root@www httpd-2.4.18]# cp ./build/rpm/httpd.init /etc/init.d/httpd24

[root@www httpd-2.4.18]# vim /etc/init.d/httpd24

    修改:httpd=${HTTPD-/usr/local/apache/bin/httpd}

          pidfile=${PIDFILE-/var/run/httpd24.pid}

          CONFFILE=/etc/httpd24/httpd.conf

[root@www httpd-2.4.18]# chkconfig --add httpd24

[root@www httpd-2.4.18]# chkconfig httpd24 on


[root@www httpd-2.4.18]# vim /etc/httpd24/httpd.conf 

    关闭中心主机:#DocumentRoot "/usr/local/apache/htdocs"

    添加:pidfile /var/run/httpd24.pid

    启用:ServerName www.daixiang.com:80

    修改:DirectoryIndex index.php index.html

    启用虚拟主机:Include /etc/httpd24/extra/httpd-vhosts.conf

    启用proxy代理功能模块: LoadModule proxy_module modules/mod_proxy.so

                           LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so


    添加两行使apach服务器能够处理以php的页面文件:

                         AddType application/x-httpd-php .php

                         AddType application/x-httpd-php-source .phps


[root@www ~]# vim /etc/httpd24/extra/httpd-vhosts.conf 

        配置虚拟主机:     

        <VirtualHost *:80>

            ServerAdmin web@a.com

            DocumentRoot "/www/a"

            ServerName www.a.com

            ServerAlias a.com

            ErrorLog "logs/a-error_log"

            CustomLog "logs/a-access_log" combined

            ProxyRequests off               ##关闭正向代理

            ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.88.139:9000/www/a/$1  ##把以 .php结尾的请求用fastcgi的协议传给php服务器执行 

                <Directory "/www/a">

                        options none

                        Require all granted    ##授权

                </Directory>

        </VirtualHost>


[root@www ~]# mkdir -pv /www/a

[root@www ~]# ln -sv /usr/local/apache/include /usr/include/httpd

[root@www ~]# vim /etc/profile.d/httpd24.sh

            添加二进制路径:export PATH=/usr/local/apache/bin:$PATH

[root@www ~]# source /etc/profile.d/httpd24.sh

[root@www ~]# vim /etc/man.config

            添加man文档路径:    MANPATH  /usr/local/apache/man


测试代码:

[root@www ~]# vim /www/a/index.php

<?php

        $conn = mysql_connect('192.168.88.140','root','daixiang');

        if ($conn)

                echo 'OK';

        else

                echo 'ERROR';

        mysql_close();

        phpinfo();

?>


###注意:php服务器和apache服务器中必须各放一份相同的测试代码文件 

###########################################################################################


第二步:二进制安装mysql:    192.168.88.140

[root@www mysql]# yum install libaio-devel

[root@www ~]# mkdir /data

[root@www ~]# groupadd -r mysql

[root@www ~]# useradd -r -s /sbin/nologin -g mysql mysql

[root@www ~]# tar xf mysql-5.5.47-linux2.6-x86_64.tar.gz -C /usr/local/

[root@www ~]# ln -sv /usr/local/mysql-5.5.47-linux2.6-x86_64 /usr/local/mysql

`/usr/local/mysql' -> `/usr/local/mysql-5.5.47-linux2.6-x86_64'

[root@www ~]# 

[root@www ~]# cd /usr/local/mysql

[root@www mysql]# chown -R root:mysql ./*

[root@www mysql]# ./scripts/mysql_install_db --datadir=/data --user=mysql

[root@www mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@www mysql]# chkconfig --add mysqld

[root@www mysql]# chkconfig mysqld on

[root@www mysql]# cp support-files/my-large.cnf /etc/my.cnf 

[root@www mysql]# vim /etc/my.cnf

    datadir = /data    #指定数据目录

    thread_concurrency = 2   #修改为当前服务器物理核心数的两倍

[root@www ~]# ln -sv /usr/local/mysql/include /usr/include/mysql

[root@www ~]# vim /etc/ld.so.conf.d/mysql.conf

    添加库文件路径:/usr/local/mysql/lib

[root@www ~]# ldconfig

[root@www ~]# vim /etc/man.config 

    添加man文档路径:MANPATH  /usr/local/mysql/man        ##导入man文档

[root@www ~]# vim /etc/profile.d/mysqld.sh

    添加二进制程序路径:export PATH=/usr/local/mysql/bin:$PATH   

[root@www ~]# source /etc/profile.d/mysqld.sh

[root@www ~]# service mysqld start

[root@www ~]# ss -tnl

LISTEN     0      50                          *:3306                       *:* 


为用户授权:

[root@www ~]# yum install mysql -y

[root@www ~]# mysql 

mysql> use mysql

mysql> grant all privileges on *.* to 'root'@'192.168.88.%' identified by 'daixiang';

mysql> flush privileges;


###########################################################################################


第三步:编译安装php,支持fcgi:    192.168.88.139

[root@www ~]# yum groupinstall "Desktop Platform Development" "Development tools" "Server Platform Development" -y

[root@www ~]# tar xf php-5.6.19.tar.bz2 

[root@www ~]# cd php-5.6.19

[root@www php-5.6.19]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-jpeg-dir --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-libxml-dir=/usr --with-bz2 --enable-xml --with-mcrypt --enable-sockets --with-freetype-dir --with-png-dir -enable-mbstring

    第一次错误:configure: error: Please reinstall the BZip2 distribution

        解决方法:yum install bzip2-devel

    第二次错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

        解决方法:yum install libmcrypt-devel     #epel源中有此包

[root@www php-5.6.19]# make && make install



[root@www php-5.6.19]# cp php.ini-production /etc/php.ini    ##php.ini-production用于生产环境,php.ini-development用于开发

[root@www php-5.6.19]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@www php-5.6.19]# chmod +x /etc/init.d/php-fpm 

[root@www php-5.6.19]# chkconfig --add php-fpm

[root@www php-5.6.19]# chkconfig php-fpm on

[root@www php-5.6.19]# cd /usr/local/php/etc/

[root@www etc]# cp php-fpm.conf.default ./php-fpm.conf

[root@www etc]# vim php-fpm.conf

    修改:pid = /usr/local/php/var/run/php-fpm.pid    

          listen = 192.168.88.139:9000        ##监听本地9000端口

            

            pm.max_children = 50        #最大子进程数

            pm.start_servers = 5       #默认启动进程数

            pm.min_spare_servers = 2    #最小空闲进程数

           pm.max_spare_servers = 6    #最大空闲进程数


[root@www ~]# service php-fpm start

Starting php-fpm  done  

[root@www ~]# ss -tnl 

LISTEN     0      128            192.168.88.139:9000                       *:*


测试代码:

[root@www ~]# vim /www/a/index.php   

<?php

        $conn = mysql_connect('192.168.88.140','root','daixiang');

        if ($conn)

                echo 'OK';

        else

                echo 'ERROR';

        mysql_close();

        phpinfo();

?>

###注意:php服务器和apache服务器中必须各放一份相同的测试代码文件

 

第四步:安装xcache扩展 :  192.168.88.139 

1.编译安装

[root@www ~]# tar xf xcache-3.2.0.tar.gz 

[root@www ~]# cd xcache-3.2.0

[root@www xcache-3.2.0]# /usr/local/php/bin/phpize  ##每次重新编译安装php的扩展,都需要先执行

Configuring for:

PHP Api Version:         20131106

Zend Module Api No:      20131226

Zend Extension Api No:   220131226

[root@www xcache-3.2.0]# ./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache

[root@www xcache-3.2.0]# make && make install

安装结束时出现:Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/


2.编辑ph.ini,整合php和xcache:

[root@www xcache-3.2.0]# mkdir /etc/php.d

[root@www xcache-3.2.0]# cp xcache.ini /etc/php.d/

[root@www xcache-3.2.0]# vim /etc/php.d/xcache.ini

找到extension开头的行,修改为如下:

extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so

##注意:如果xcache.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。

[root@www xcache-3.2.0]# service php-fpm restart


如果需要使用phpMyadmin数据库管理工具:

[root@www ~]# unzip phpMyAdmin-4.5.5.1-all-languages.zip

[root@www ~]# cd phpMyAdmin-4.5.5.1-all-languages/

[root@www phpMyAdmin-4.5.5.1-all-languages]# cp config.sample.inc.php ./config.inc.php

[root@www phpMyAdmin-4.5.5.1-all-languages]#vim config.inc.php

将下面的地址设置为mysql服务器的地址:

    $cfg['Servers'][$i]['host'] = '192.168.88.140';


注意:别忘了apache服务器和php服务器中各存放一份