CentOS6.8编译安装—- php-fpm

安装环境:

[root@station11 ~]# lsb_release -a

Distributor ID: CentOS

Description:     CentOS release 6.8 (Final)

Release:  6.8

Codename:      Final

 

Development tools

Server Platform Development

软件版本:

apr-1.5.0.tar.bz2

apr-util-1.5.3.tar.bz2

httpd-2.4.10.tar.bz2

mariadb-5.5.46-linux-x86_64

php-5.6.4.tar.xz

xcache-3.2.0.tar.bz2

wordpress-4.3.1-zh_CN.zip

 

编译安装apr

mkdir /apps

tar xf apr-1.5.0.tar.bz2

cd apr

./configure –prefix=/apps/apr

make -j 4 && make install

 

编译安装apr-util

tar xf apr-util-1.5.3.tar.bz2

cd apr-util-1.5.3

./configure –prefix=/apps/apr-util –with-apr=/apps/apr

make -j 4 && make install

 

编译安装httpd

[root@station11 ~]# tar  xf httpd-2.4.10.tar.bz2

[root@station11 ~]# cd httpd-2.4.10

yum install pcre-devel -y

./configure –prefix=/apps/apache2.4 –sysconfdir=/etc/httpd2.4 –libexecdir=/apps/apache2.4/lib –enable-so –enable-ssl –enable-cgi –enable-rewrite –with-zlib –with-pcre –with-apr=/apps/apr –with-apr-util=/apps/apr-util  –enable-modules=most –enable-mpms-shared=all –with-mpm=prefork  #可以用./configure –help 看你需要编译的模块

make -j 4 && make install

 

–prefix=/apps/apache2.4           #安装位置

–sysconfdir=/etc/httpd2.4           #配置档位置

–libexecdir=/apps/apache2.4/lib #库文件存放位置

–enable-so                         #支持DSO动态装载模块

–enable-ssl      #支持SSL/TLS,可实现https协议访问,需要安装openssl-devel

–enable-cgi               #支持CGI脚本

–enable-rewrite             #支持URL伪静态重写

–with-zlib                        #使用指定的zlib压缩库,不指定路径会自动寻找

–with-pcre                        #使用指定的pcre库,增强的正则表达式分析工具;不指定路径会自动寻找 需已安装pcre-devel

–with-apr=/usr/local/apr           #指定依赖apr程序安装位置

–with-apr-util=/usr/local/apr-util #指定依赖apr-util程序安装位置

–enable-modules=most          #支持动态启用模块;all:所有,most:常用

–enable-mpms-shared=all            #编译并共享模块

–with-mpm=prefork                    #默认启用模块{prefork|worker|event}

 

编辑vim  /etc/profile.d/http.conf如下:

PATH=/apps/http/bin:$PATH

.  /etc/profile.d/http.conf

头文件:

ln -sv /apps/http/include/ /usr/include/http

帮助文件:

vim /etc/man.config,添加一行

MANPATH /apps/http/man

 

httpd -k start

iptables –F

setenforce 0

查看80端口是否启动:

[root@station11 httpd-2.4.10]# ss –ntl

blob.png

用浏览器查看:

blob.png

 

编译安装mariadb-server ,使用通用二进制格式安装;

tar xf mariadb-5.5.46.tar.gz -C /apps/

cd /usr/local/

ln -sv /apps/mariadb-5.5.46  mysql

useradd -r -M -s /sbin/nologin mysql

cd mysql/

chown -R  root.mysql ./*

mkdir -pv /mysql/data

chown -R mysql.mysql /mysql/data/

mkdir /etc/mysql

cp support-files/my-large.cnf /etc/mysql/my.cnf

 

vim /etc/mysql/my.cnf

[mysqld]字段添加:

datadir = /mysql/data

skip_name_resolve = ON

innodb_file_per_table = ON

 

cp support-files/mysql.server /etc/init.d/mysqld

chkconfig –add mysqld

chkconfig –list mysqld

 

./scripts/mysql_install_db –user=mysql –datadir=/mysql/data/  注意:这个要执行在启动服务之前,否则服务启动不了

 

service mysqld start

bin/mysql_secure_installation   #初始化数据库

查看3306端口是否启动

blob.png

 

vim /etc/profile.d/mysql.conf

PATH=/usr/loacl/mysql/bin:$PATH

 

ln -sv /apps/mariadb-5.5.46-linux-x86_64/include/ /usr/include/mysql

 

vim /etc/ld.so.conf.d/http.conf

/usr/local/mysql/lib

ldconfig

ldconfig –p | grep mysql查看库是否加载上

 

vim /etc/man.config

MANPATH /usr/local/mysql/man

 

 

编译php

tar xf php-5.6.4.tar.xz

cd php-5.6.4

yum install -y libxml2-devel

yum install bzip2-devel

yum install -y libmcrypt-devel   #epel源的软件,安装前要配置yumepel

./configure –prefix=/apps/php –with-mysql=/usr/local/mysql –with-openssl –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-mbstring –with-png-dir –with-jpeg-dir –with-freetype-dir –with-zlib –with-libxml-dir=/usr –enable-xml –enable-sockets –with-apxs2=/apps/http/bin/apxs –with-mcrypt  –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-bz2 –enable-fpm  ###编译了fpm,且在编译httpd的时候编译的是prefork,如果编译httpd选择的是work或者event,这里需要编译–enable-maintainer-zts

make -j 4 && make install

 

cp php.ini-production /etc/php.ini

 

vim /apps/http/conf/httpd.conf

#

    AddType application/x-compress .Z

    AddType application/x-gzip .gz .tgz

    AddType application/x-httpd-php .php

    AddType application/x-httpd-source .phps

添加上面标红的两行

#

<IfModule dir_module>

    DirectoryIndex index.php index.html  ###添加index.php

</IfModule>

 

<IfModule proxy_html_module>

Include conf/extra/proxy-html.conf     ##确保没有被注释掉

</IfModule>

 

DocumentRoot "/apps/http/htdocs"

ProxyRequests off

ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/apps/http/htdocs/$1   ##添加该两行

 

#LoadModule php5_module        modules/libphp5.so  注释掉该行

LoadModule proxy_module modules/mod_proxy.so

#LoadModule proxy_connect_module modules/mod_proxy_connect.so

#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so             ##确保红色的没有被注释掉

LoadModule proxy_http_module modules/mod_proxy_http.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

LoadModule proxy_scgi_module modules/mod_proxy_scgi.so

 

cp php.ini-production /etc/php.ini

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chkconfig –add php-fpm

chkconfig –list php-fpm

[root@station11 php-5.6.4]# service php-fpm start

Starting php-fpm  done

httpd -k restart

 

vim /apps/http/htdocs/index.php

<?php

phpinfo();

?>

 

在浏览器上查看

blob.png

启用的是FastCGI

 

进入数据库:

MariaDB [(none)]> create database wpdb;

MariaDB [(none)]> grant all privileges on wpdb.* to wpuser@'%' identified by "walker";

MariaDB [(none)]> flush privileges;

MariaDB [(none)]> quit

 

编辑[root@station11 ~]# vim /apps/http/htdocs/index.php

<?php

$conn = mysql_connect('172.16.251.11','wpuser','walker');

if($conn)

        echo "OK";

else

        echo "Failure";

phpinfo();

?>

 

用浏览器查看:

blob.png

链接数据库成功

 

unzip /root/wordpress-4.3.1-zh_CN.zip -d .

chmod a+w wordpress

 

http://172.16.251.11/wordpress初始化完成后:

blob.png

使用ab命令进行压力测试:

Requests per second:    10.74 [#/sec] (mean)

Time per request:       1861.955 [ms] (mean)

Time per request:       93.098 [ms] (mean, across all concurrent requests)

Transfer rate:          4.53 [Kbytes/sec] received

 

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    3  12.7      1     129

Processing:   249 1817 266.1   1805    2718

Waiting:      249 1817 265.8   1803    2718

Total:        254 1820 267.3   1808    2719

 

Percentage of the requests served within a certain time (ms)

  50%   1808

  66%   1900

  75%   1966

  80%   2003

  90%   2131

  95%   2226

  98%   2374

  99%   2452

 100%   2719 (longest request)

 

 

编译安装xcache提升并发等级:

tar xf xcache-3.2.0.tar.bz2

cd xcache-3.2.0

/apps/php/bin/phpize

./configure –enable-xcache –with-php-config=/apps/php/bin/php-config

make -j 4 && make install

mkdir /etc/php.d

cp xcache.ini /etc/php.d/

service php-fpm restart

查看:

http://172.16.251.11/index.php

blob.png

blob.png

出现上面的就说明xcache载入成功,现在再用ab做压力测试:

[root@localhost xcache-3.2.0]# ab -c 20 -n 500 http://172.16.251.11/wordpress/wp-admin/

Requests per second:    32.74 [#/sec] (mean)

Time per request:       610.851 [ms] (mean)

Time per request:       30.543 [ms] (mean, across all concurrent requests)

Transfer rate:          13.81 [Kbytes/sec] received

 

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    2   6.9      1      94

Processing:   112  598 113.9    588    1156

Waiting:      111  598 113.8    587    1156

Total:        122  600 112.8    591    1157

 

Percentage of the requests served within a certain time (ms)

  50%    591

  66%    622

  75%    644

  80%    660

  90%    712

  95%    777

  98%    914

  99%   1034

 100%   1157 (longest request)

着色区域更没有xcache相比有很大的提升。

 

原创文章,作者:王更生,如若转载,请注明出处:http://www.178linux.com/64411

联系我们

400-080-6560

在线咨询

工作时间:周一至周五,9:30-18:30,节假日同时也值班

QR code