Chinaunix首页 | 论坛 | 博客
  • 博客访问: 611245
  • 博文数量: 244
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-27 09:53
个人简介

记录学习,记录成长

文章分类

全部博文(244)

我的朋友

分类: LINUX

2015-08-23 06:14:49

配置apache-2.4.4与fpm方式的php-5.4.13
1. 编译安装Apache2.4.16
编译MPM为动态模块
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --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
2.  编译安装MYSQL5.6.26
2.1  下载之/usr/local下
 wget /> 2.2  编译安装 (部分功能因为以前做过一遍了,这里省略了)
tar xf mysql-5.6.26-linux-glibc2.5-i686.tar.gz 
[root@www local]# ln -sv mysql-5.6.26-linux-glibc2.5-i686 mysql
`mysql' -> `mysql-5.6.26-linux-glibc2.5-i686'
[root@www mysql]# chown -R mysql.mysql .
[root@www mysql]# scripts/mysql_install_db --user=mysql --datadir=/mysqldata/data/
生成my.cnf文件,不需要复制到/etc中去以后可以直接使用它
而support-files/中也没了my.large.cnf等文件了,只有一个my.default.cnf文件
[root@www support-files]# cp my-default.cnf /etc/my.cnf
将其中的datadir=/mysqldata/data/启用
启动脚本
[root@www support-files]# cp mysql.server /etc/init.d/mysqld
cp: overwrite `/etc/init.d/mysqld'? y
保险起见更改属主
[root@www mysql]# chown -R root .
启动服务
[root@www mysql]# service mysqld start
Starting MySQL...... SUCCESS! 
然后就可以使用mysql命令了(将MYSQL的环境变量写入/etc/profile.d/mysql.sh在执行即可,以前做了一次,所以此次省了)
[root@www mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 
3.  编译安装PHP5.5.28
3.1  编译
[root@www lamp]# tar xf php-5.5.28.tar.gz 
[root@www php-5.5.28 ]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --enable-fpm --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
[root@www php-5.5.28]# make && make install
这种方式的编译会在PHP安装目录下生成php-fpm的二进制程序,而且还提供了一个默认的配置文件;
[root@www php-5.5.28]# ll sapi/
config.m4           init.d.php-fpm.in   php-fpm             php-fpm.conf.in     status.html.in
CREDITS             .libs/              php-fpm.8           php-fpm.service     tests/
fpm/                LICENSE             php-fpm.8.in        php-fpm.service.in  
init.d.php-fpm      Makefile.frag       php-fpm.conf        status.html        
为php提供配置文件:
[root@www php-5.5.28 ]# cp php.ini-production /etc/php.ini


3.2  接下来就是配置fpm
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
[root@www php-5.5.28]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@www php-5.5.28]# chmod +x /etc/rc.d/init.d/php-fpm 
[root@www php-5.5.28]# chkconfig --add php-fpm
[root@www php-5.5.28]# chkconfig --list php-fpm
php-fpm         0:off   1:off   2:on    3:on    4:on    5:on    6:off


为php-fpm提供配置文件:(默认提供的有php-fpm.conf.default)
[root@www php-5.5.28]# chkconfig --add php-fpm
[root@www php-5.5.28]# chkconfig --list php-fpm
php-fpm         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@www etc]# cp php-fpm.conf.default php-fpm.conf
编辑php-fpm的配置文件:
vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件:
pm.max_children = 50 #最大子进程数
pm.start_servers = 2 #启动服务时就启动的进程数
pm.min_spare_servers = 2 #最小空闲进程数
pm.max_spare_servers = 5 #最大空闲进程数
pid = /usr/local/php/var/run/php-fpm.pid #定义pid文件的存放位置,可以不改因为/etc/rc.d/init.d/php-fpm会在/usr/local/php/var/run下寻找pid文件,不改方便,也可以改为在/etc/run下不过这样的话也要修改/etc/rc.d/init.d/php-fpm脚本
接下来就可以启动php-fpm了:
[root@www etc]# service php-fpm start
Starting php-fpm  done
[root@www etc]# netstat -ntlp | grep php-fpm
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      5658/php-fpm 
注意:为fast-cgi方式工作是PHP会自己启动PHP服务(监听众多进程,默认监听127.0.0.1:9000而且会启动多个空闲进程这个可以编辑php-fpm配置文件来定义修改),那么Apache与PHP交互时,如果Apache和PHP在同一台主机上那么监听127.0.0.1:9000是没问题的,如果不在同一台主机上那么就必须指定监听IP地址,这时候Apache相当于客户机,PHP相当于服务器,客户机通过两者连接的套接字来想服务器发起请求,服务器接受请求处理并将结果发送给客户机;


4.  配置PHP能使用虚拟主机
4.1 此时的PHP不再是Apache的模块了,要想让Apache通过fast-cgi的方式与PHP的fpm结合起来工作还需要配置Apache的配置文件启动对应的模块
在httpd2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载,编辑Apache的配置文件:
启用两个模块:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
启用虚拟主机功能:
禁用DocumentRoot "/usr/local/apache/htdocs"
启用Include /etc/httpd/extra/httpd-vhosts.conf
4.2  因为开启了虚拟主机,所以还要配置虚拟主机支持fcgi,只需在虚拟主机的配置段中添加
ProxyRequests Off #关闭Apache的正向代理功能
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
#当用户向Apache请求.php文件(Apache服务企业自身并没有)时,Apache将请求PHP服务器将结果缓存到本地在发送给用户,如用户请求
/本机主机/images/a.jpg将反向代理到PHP主机IP/自己定义的DocumentRoot/images/a.php
如:
<VirtualHost *:80>
    DocumentRoot "/var/www/a"
    ServerName /> ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/a/$1
    <Directory "/var/www/a">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>
然后编辑Apache的配置文件修改支持.php文件
<IfModule dir_module>
    DirectoryIndex .php index.html
</IfModule>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps


4.3  测试语法重启服务
[root@www etc]# httpd -t
Syntax OK
[root@www etc]# service httpd restart
Stopping httpd: [  OK  ]
Starting httpd: [  OK  ]
4.4  测试
[root@www ~]# ll /var/www/a
-rw-r--r-- 1 root root 26 Aug 22 02:08 index.html
[root@www ~]# elinks --dump />                                 works
[root@www ~]# vim /var/www/a/index.html 
<h1>  works</h1>
<?php
phpinfo()
?>
[root@www ~]# mv /var/www/a/index.html /var/www/a/index.php
[root@www ~]# elinks --dump /index.php | less
                                works


   [1]PHP logo
   PHP Version 5.5.28
   System          Linux 2.6.32-431.el6.i686 #1 SMP Fri Nov 22
                   00:26:36 UTC 2013 i686
   Build Date      Aug 22 2015 14:00:24
                   './configure' '--prefix=/usr/local/php'
                   '--with-mysql=/usr/local/mysql' '--with-openssl'
                   '--with-mysqli=/usr/local/mysql/bin/mysql_config'
   Configure       '--enable-mbstring' '--with-freetype-dir'
   Command         '--with-jpeg-dir' '--with-png-dir' '--with-zlib'
                   '--with-libxml-dir=/usr' '--enable-xml' '--enable-sockets'
                   '--enable-fpm' '--with-mcrypt'
                   '--with-config-file-path=/etc'
                   '--with-config-file-scan-dir=/etc/php.d' '--with-bz2'
   Server API      FPM/FastCGI

阅读(2864) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~