CentOS7编译安装LAMP—php-fpm

inux的环境是:

[root@localhost ~]# lsb_release -a

LSB Version:     :core-4.1-amd64:core-4.1-noarch

Distributor ID: CentOS

Description:     CentOS Linux release 7.2.1511 (Core)

Release:  7.2.1511

Codename:      Core

安装了Deveolpment Tools

 

各软件版本:

apr-1.5.0

apr-util-1.5.3

httpd-2.4.10

mariadb-5.5.46-linux-x86_64

php-5.6.4

xcache-3.2.0

wordpress-4.3.1-zh_CN

 

 

 

编译安装apr

tar xf apr-1.5.0.tar.bz2

cd apr-1.5.0

./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

yum install -y pcre-devel

yum install -y openssl-devel

tar xf httpd-2.4.10.tar.bz2

cd httpd-2.4.10

 

./configure –prefix=/apps/http –with-apr=/apps/apr –with-apr-util=/apps/apr-util –enable-so –enable-ssl –enable-rewrite –with-zlib –with-pcre –enable-modules=most –enable-mpms-shared=all –with-mpm=prefork

make -j 4 && make install

注意:此处httpd编译的是prefork

配置:/apps/http/conf/httpd.conf

    # probably should define those extensions to indicate media types:

    #

    AddType application/x-compress .Z

    AddType application/x-gzip .gz .tgz

    AddType application/x-httpd-php .php

  

    <IfModule dir_module>

    DirectoryIndex index.php index.html

</IfModule>

建立文件:

cat /etc/profile.d/http.conf

PATH=/apps/http/bin:$PATH

 

添加man配置

[root@localhost ~]# vim /etc/man_db.conf

MANDATORY_MANPATH                       /apps/http/man

 

添加头文件

[root@localhost ~]# ll /usr/include/http.h

lrwxrwxrwx. 1 root root 19 10 12 04:33 /usr/include/http.h -> /apps/http/include/

 

使用httpd –k start命令启动httpd 查看80端口

 

 

安装mariadb

此处的mariadb是通用二进制包安装:

tar xf mariadb-5.5.46-linux-x86_64.tar.gz –C /apps/

cd /apps

ln –sv mariadb-5.5.46-linux-x86_64 mysql

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

mkdir -p /mysql/mydata

chown -R mysql.mysql /mysql/mydata/

cd /apps/mysql

chown -R root.mysql ./*

mkdir -p /etc/mysql/

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

 

 

vim /etc/mysql/my.cnf

[mysqld]字段编辑如下语句:

datadir = /mysql/mydata

skip_name_resolve = ON

innodb_file_per_table = ON

 

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

chkconfig –add mysqld

chkconfig –list mysqld

mv /etc/my.cnf /etc/my.cnf.bak

service mysqld  start

查看端口3306是否启动

vim /etc/profile.d/mysql.conf如下:

PATH=/apps/mysql/bin:$PATH

. /etc/profile.d/mysql.conf

 

编译php

tar xf php-5.6.4.tar.xz

cd php-5.6.4

yum install libxml2-devel

yum install bzip2-devel

yum install libmcrypt

yum install libmcrypt-devel   注意:该软件是epel源里的,需要epelyum

 

./configure –prefix=/apps/php –with-mysql=/apps/mysql –with-openssl –with-mysqli=/apps/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

make -j 4 && make install

 

注意:此处编译了php-fpm的属性,并且由于httpd编译的是prefork的,若果httpd编译为work或者event,则这里需要加以属性:–enable-maintainer-zts

编辑vim /apps/http/conf/httpd.conf:去掉下面模块的注释符号#

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

LoadModule dir_module modules/mod_dir.so

注释掉下面的模块:

#LoadModule php5_module        modules/libphp5.so

DocumentRoot下面添加一下语句:

DocumentRoot "/apps/http/htdocs"

ProxyRequests off

ProxyPassMatch  ^/(.*\.php)$  fcgi://127.0.0.1:9000/apps/http/htdocs/$1

确保下面的没有被注释掉:

 

<IfModule proxy_html_module>

Include conf/extra/proxy-html.conf

</IfModule>

 

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

chmod +x /etc/init.d/php-fpm

mv  /apps/php/etc/php-fpm.conf.default /apps/php/etc/php-fpm.conf

service php-fpm start

httpd -k restart

 

vim /apps/http/htdocs/index.php如下:

<?php

phpinfo();

?>

在浏览器中输入网址,是否是fastcgi模式:

blob.png

 

 

/apps/http/htdocs目录中:

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

 

mysql

MariaDB [(none)]> create database wpdb;

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

MariaDB [(none)]> flush privileges;

MariaDB [(none)]> quit

 

[root@localhost ~]# vim /apps/http/htdocs/index.php

<?php

$conn = mysql_connect('172.16.251.187','walker','walker');

if($conn)

echo "OK";

else

echo "Failure";

phpinfo();

?>

访问网页,看是否连接成功:

blob.png

如此可以使用wordpress。使用刚才创建的用户和数据可以初始化wordpress,在使用之前,需要更改wordpress目录的权限。否则无法写入数据:

chmod a+w wordpress

 

 

 

使用ab测试网站并发,ab工具是httpd-tools软件包里面的,如没有安装httpd-tools。在另外一台电脑使用命令:ab -c 20 -n 500 http://172.16.251.187/wordpress/wp-admin/ 

其中-c 20是并发量,-n 500是总的请求数。3次测试后,最后的数据是:

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

Time per request:       1749.168 [ms] (mean)

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

Transfer rate:          4.85 [Kbytes/sec] received

 

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0   17  29.4      1     231

Processing:   196 1695 241.8   1697    2421

Waiting:      193 1695 241.2   1696    2353

Total:        199 1713 243.3   1719    2422

 

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

  50%   1719

  66%   1799

  75%   1847

  80%   1875

  90%   1941

  95%   2006

  98%   2176

  99%   2236

 100%   2422 (longest request)  最大的网页打开时间是2.422

 

 

编译安装xcashe提升并发:

 

 

tar xf xcache-3.2.0.tar.bz2

cd xcache-3.2.0

vim INSTALL

/apps/php/bin/phpize

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

make -j 4 && make install

mkdir /etc/php.d

mv /etc/xcache.ini /etc/php.d/

service php-fpm restart

httpd -k restart

index.php网页里面查看是否有:

blob.png

 

现在在用ab测试:

Requests per second:    31.13 [#/sec] (mean)    每秒处理请求,打开提升了3

Time per request:       642.426 [ms] (mean)

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

Transfer rate:          13.19 [Kbytes/sec] received

 

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0   17  33.1      2     342

Processing:   101  610 114.4    605    1055

Waiting:      100  609 114.3    605    1055

Total:        102  627 113.8    622    1056

 

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

  50%    622

  66%    653

  75%    677

  80%    690

  90%    758

  95%    811

  98%    908

  99%    985

 100%   1056 (longest request)   打开网页的最长时间,提示你2倍多

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

(0)
上一篇 2016-12-21 17:06
下一篇 2016-12-21 17:15

相关推荐

  • Linux系统的终端类型

    Linux系统的终端类型    Linux系统的终端主要包括控制台终端、控制终端、串口终端、伪终端、虚拟终端。 1.  控制台终端(/dev/console)。    在Unix系统中,计算机显示器通常被称为控制台终端。Console与虚拟终端相关联,内核将信息送到控制台终端上(/dev/conso…

    Linux干货 2015-09-14
  • 马哥教育网络班21期+第5周课程练习

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; [root@centos ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf  root (hd0,0) kernel /vmlinuz-2.6.3…

    Linux干货 2016-07-29
  • N22-℡浮生.若夢 ╮第六周作业

    1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; cp /etc/rc.sysinit /tmp/rc.sysinit vim/tmp/rc.sysinit :%s@^[[:space:]]\+@#&@g 2、复制/boot/grub…

    Linux干货 2016-10-29
  • N25-第五周作业

    1、显示当前系统上root、fedora或user1用户的默认shell;   grep -E “^\(root|fedora|user1\)” /etc/passwd | cut -d: f7 2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如hello();  &nb…

    Linux干货 2017-02-15
  • 高可用keepalived+haproxy实现动静分离

    高可用keepalived+haproxy: 实验环境: clientIP为:172.18.254.149 VIRROUTEIP为:172.18.61.5 keepalived+haproxy机器1IP为172.18.61.1 keepalived+haproxy机器2IP为172.18.61.2 server1IP为172.18.61.3 server2I…

    2017-05-17
  • HAProxy七种调度方法的简单示意图

    看了三个月,中间因出差和其他事没有看估计也有十几天,刚把35天的视频看完。很多内容都记不住,待第一次看完后再回头看吧。 现在想,对内容进行简单的画图,把基本的体现出来,对记忆和回顾应该有帮助。

    Linux干货 2016-07-26