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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lamp基于fcgi编译安装,支持xcache扩展相关的知识,希望对你有一定的参考价值。

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:    

[[email protected] ~]# tar xf apr-1.5.1.tar.gz 

[[email protected] ~]# cd apr-1.5.1

[[email protected] apr-1.5.1]# ./configure --prefix=/usr/local/apr

[[email protected] apr-1.5.1]# make && make install    


3.编译安装apr-util:

[[email protected] ~]# tar xf apr-util-1.5.2.tar.bz2 

[[email protected] ~]# cd apr-util-1.5.2

[[email protected] apr-util-1.5.2]# ./configure --prefix=/usr//local/apr-util --with-apr=/usr/local/apr/

[[email protected] apr-util-1.5.2]# make && make install


4.编译安装http:

[[email protected] apr-1.5.1]# cd

[[email protected] ~]# tar xf httpd-2.4.18.tar.gz

[[email protected] ~]# cd httpd-2.4.18 

[[email protected] 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

[[email protected] httpd-2.4.18]# make && make install

[[email protected] httpd-2.4.18]# cp ./build/rpm/httpd.init /etc/init.d/httpd24

[[email protected] httpd-2.4.18]# vim /etc/init.d/httpd24

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

          CONFFILE=/etc/httpd24/httpd.conf

[[email protected] httpd-2.4.18]# chkconfig --add httpd24

[[email protected] httpd-2.4.18]# chkconfig httpd24 on


[[email protected] 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


[[email protected] ~]# vim /etc/httpd24/extra/httpd-vhosts.conf 

        配置虚拟主机:     

        <VirtualHost *:80>

            ServerAdmin [email protected]

            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>


[[email protected] ~]# mkdir -pv /www/a

[[email protected] ~]# ln -sv /usr/local/apache/include /usr/include/httpd

[[email protected] ~]# vim /etc/profile.d/httpd24.sh

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

[[email protected] ~]# source /etc/profile.d/httpd24.sh

[[email protected] ~]# vim /etc/man.config

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


测试代码:

[[email protected] ~]# 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

[[email protected] mysql]# yum install libaio-devel

[[email protected] ~]# mkdir /data

[[email protected] ~]# groupadd -r mysql

[[email protected] ~]# useradd -r -s /sbin/nologin -g mysql mysql

[[email protected] ~]# tar xf mysql-5.5.47-linux2.6-x86_64.tar.gz -C /usr/local/

[[email protected] ~]# 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‘

[[email protected] ~]# 

[[email protected] ~]# cd /usr/local/mysql

[[email protected] mysql]# chown -R root:mysql ./*

[[email protected] mysql]# ./scripts/mysql_install_db --datadir=/data --user=mysql

[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[[email protected] mysql]# chkconfig --add mysqld

[[email protected] mysql]# chkconfig mysqld on

[[email protected] mysql]# cp support-files/my-large.cnf /etc/my.cnf 

[[email protected] mysql]# vim /etc/my.cnf

    datadir = /data    #指定数据目录

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

[[email protected] ~]# ln -sv /usr/local/mysql/include /usr/include/mysql

[[email protected] ~]# vim /etc/ld.so.conf.d/mysql.conf

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

[[email protected] ~]# ldconfig

[[email protected] ~]# vim /etc/man.config 

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

[[email protected] ~]# vim /etc/profile.d/mysqld.sh

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

[[email protected] ~]# source /etc/profile.d/mysqld.sh

[[email protected] ~]# service mysqld start

[[email protected] ~]# ss -tnl

LISTEN     0      50                          *:3306                       *:* 


为用户授权:

[[email protected] ~]# yum install mysql -y

[[email protected] ~]# 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

[[email protected] ~]# yum groupinstall "Desktop Platform Development" "Development tools" "Server Platform Development" -y

[[email protected] ~]# tar xf php-5.6.19.tar.bz2 

[[email protected] ~]# cd php-5.6.19

[[email protected] 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源中有此包

[[email protected] php-5.6.19]# make && make install



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

[[email protected] php-5.6.19]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[[email protected] php-5.6.19]# chmod +x /etc/init.d/php-fpm 

[[email protected] php-5.6.19]# chkconfig --add php-fpm

[[email protected] php-5.6.19]# chkconfig php-fpm on

[[email protected] php-5.6.19]# cd /usr/local/php/etc/

[[email protected] etc]# cp php-fpm.conf.default ./php-fpm.conf

[[email protected] 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    #最大空闲进程数


[[email protected] ~]# service php-fpm start

Starting php-fpm  done  

[[email protected] ~]# ss -tnl 

LISTEN     0      128            192.168.88.139:9000                       *:*


测试代码:

[[email protected] ~]# 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.编译安装

[[email protected] ~]# tar xf xcache-3.2.0.tar.gz 

[[email protected] ~]# cd xcache-3.2.0

[[email protected] 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

[[email protected] xcache-3.2.0]# ./configure --with-php-config=/usr/local/php/bin/php-config --enable-xcache

[[email protected] 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:

[[email protected] xcache-3.2.0]# mkdir /etc/php.d

[[email protected] xcache-3.2.0]# cp xcache.ini /etc/php.d/

[[email protected] 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指令行,要确保此新增的行排在第一位。

[[email protected] xcache-3.2.0]# service php-fpm restart


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

[[email protected] ~]# unzip phpMyAdmin-4.5.5.1-all-languages.zip

[[email protected] ~]# cd phpMyAdmin-4.5.5.1-all-languages/

[[email protected] phpMyAdmin-4.5.5.1-all-languages]# cp config.sample.inc.php ./config.inc.php

[[email protected] phpMyAdmin-4.5.5.1-all-languages]#vim config.inc.php

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

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


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

 

      



本文出自 “linux运维” 博客,请务必保留此出处http://9162199.blog.51cto.com/9152199/1752738

以上是关于lamp基于fcgi编译安装,支持xcache扩展的主要内容,如果未能解决你的问题,请参考以下文章

CentOS6基于源码编译安装LAMP实现WordPress功能和xcache功能

lamp编译安装

构建LAMP平台(使用xcache-2.0给php加速)

在centos6.5上编译安装LAMP

Centos 6.9 编译安装 LAMP + xcache

CentOS6编译LAMP基于FPM模式的应用wordpress