231321 发表于 2016-3-21 10:10:48

lamp基于fcgi编译安装,支持xcache扩展

Apache:服务器地址192.168.88.128mysql:服务器地址192.168.88.140php:服务器地址192.168.88.139编译安装过程,服务器的先后顺序: apache--->mysql--->php 或者 mysql--->apache--->php
第一步:编译安装Http2.4.18:    192.168.88.1281.所需要的关联包,    apr-1.5.1.tar.gz     apr-util-1.5.2.tar.bz2    httpd-2.4.18.tar.bz2下载地址:http://pan.baidu.com/s/1c0WTfTeyum安装所需的rpm包及开发包组    yum -y groupinstall "Server Platform Development" "Development tools"    yum -y install pcre pcre-devel2.编译安装apr:    # tar xf apr-1.5.1.tar.gz # cd apr-1.5.1# ./configure --prefix=/usr/local/apr# make && make install   
3.编译安装apr-util:# tar xf apr-util-1.5.2.tar.bz2 # cd apr-util-1.5.2# ./configure --prefix=/usr//local/apr-util --with-apr=/usr/local/apr/# make && make install
4.编译安装http:# cd
# tar xf httpd-2.4.18.tar.gz
# cd 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
# make && make install
# cp ./build/rpm/httpd.init /etc/init.d/httpd24
# vim /etc/init.d/httpd24
    修改:httpd=${HTTPD-/usr/local/apache/bin/httpd}
          CONFFILE=/etc/httpd24/httpd.conf
# chkconfig --add httpd24
# chkconfig httpd24 on

# 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

# 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>

# mkdir -pv /www/a
# ln -sv /usr/local/apache/include /usr/include/httpd
# vim /etc/profile.d/httpd24.sh
            添加二进制路径:export PATH=/usr/local/apache/bin:$PATH
# source /etc/profile.d/httpd24.sh
# vim /etc/man.config
            添加man文档路径:    MANPATH/usr/local/apache/man


测试代码:
# 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
# yum install libaio-devel
# mkdir /data
# groupadd -r mysql
# useradd -r -s /sbin/nologin -g mysql mysql
# tar xf mysql-5.5.47-linux2.6-x86_64.tar.gz -C /usr/local/
# 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'
#
# cd /usr/local/mysql
# chown -R root:mysql ./*
# ./scripts/mysql_install_db --datadir=/data --user=mysql
# cp support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# cp support-files/my-large.cnf /etc/my.cnf
# vim /etc/my.cnf
    datadir = /data    #指定数据目录

    thread_concurrency = 2   #修改为当前服务器物理核心数的两倍
# ln -sv /usr/local/mysql/include /usr/include/mysql
# vim /etc/ld.so.conf.d/mysql.conf
    添加库文件路径:/usr/local/mysql/lib
# ldconfig
# vim /etc/man.config
    添加man文档路径:MANPATH/usr/local/mysql/man      ##导入man文档

# vim /etc/profile.d/mysqld.sh

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

# source /etc/profile.d/mysqld.sh
# service mysqld start
# ss -tnl
LISTEN   0      50                        *:3306                     *:*

为用户授权:
# yum install mysql -y
# 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
# yum groupinstall "Desktop Platform Development" "Development tools" "Server Platform Development" -y
# tar xf php-5.6.19.tar.bz2
# cd 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源中有此包

# make && make install


# cp php.ini-production /etc/php.ini    ##php.ini-production用于生产环境,php.ini-development用于开发环境
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
# cd /usr/local/php/etc/
# cp php-fpm.conf.default ./php-fpm.conf
# 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    #最大空闲进程数

# service php-fpm start
Starting php-fpmdone
# ss -tnl
LISTEN   0      128            192.168.88.139:9000                     *:*

测试代码:
# 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.编译安装
# tar xf xcache-3.2.0.tar.gz
# cd 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
# ./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache
# make && make install
安装结束时出现:Installing shared extensions:   /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

2.编辑ph.ini,整合php和xcache:
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d/
# 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指令行,要确保此新增的行排在第一位。
# service php-fpm restart

如果需要使用phpMyadmin数据库管理工具:
# unzip phpMyAdmin-4.5.5.1-all-languages.zip
# cd phpMyAdmin-4.5.5.1-all-languages/
# cp config.sample.inc.php ./config.inc.php
#vim config.inc.php
将下面的地址设置为mysql服务器的地址:
    $cfg['Servers'][$i]['host'] = '192.168.88.140';


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



页: [1]
查看完整版本: lamp基于fcgi编译安装,支持xcache扩展