lamp(2)

php配置文件:

/etc/php.ini, /etc/php.d/*.ini 

ini:

[foo]:Section Header

directive = value

注释符:#, ;

php.ini的核心配置选项文档:

http://php.net/manual/zh/ini.core.php 

php.ini配置选项列表:

http://php.net/manual/zh/ini.list.php 

php-fpm : fastcgi process manager

安装配置:

centos 7

yum install php-fpm

Unit file:/usr/lib/systemd/system/php-fpm.service

配置文件:/etc/php-fpm.conf, /etc/php-fpm.d/*.conf

主程序:/usr/sbin/php-fpm

配置:

路径 : /etc/php-fpm.conf

[global]
pid = /run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm/error.log
log_level = notice
daemonize = no
[pool_id]
listen = 127.0.0.1:9000  #监听端口
listen.backlog = -1
listen.allowed_clients = 127.0.0.1  #允许访问的ip地址
user = apache
group = apache
pm = dynamic     #定义processor管理机制:static, dynamic
pm.max_children      #最大子进程数量;连接池的最大容量;
pm.start_servers         #服务启动时所启动的子进程数量;
pm.min_spare_servers
pm.max_spare_servers
rlimit_files = 1024
rlimit_core = 0
pm.status_path = /status   #状态信息
ping.path = /ping
ping.response = pong
php_value[session.save_path] = /var/lib/php/session     #session的存储位置

配置示例:

vim /etc/httpd/conf.d/fcgi.conf
<VirtualHost *:80>
        ServerName www.xixi.com
        DocumentRoot "/vhosts/www"
        <Directory "/vhosts/www">
                Options None
                AllowOverride None
                Require all granted
        </Directory>
        ProxyRequests Off
        ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/vhosts/www/$1
        ProxyPassMatch ^/(ping|status)/?$ fcgi://127.0.0.1:9000/$1
        DirectoryIndex index.php
</VirtualHost>
vim /etc/php-fpm.d/www.conf

blob.png

blob.png

status输出:

pool:                 www     #连接池名称

process manager:      dynamic  #进程管理器类型

start time:           14/Oct/2016:11:16:24 +0000   #启动日期时间 

start since:          147  # 运行时长

accepted conn:        9  # 连接池已经处理过的请求数

listen queue:         0  # 请求队列长度

max listen queue:     0 # 请求队列的最大长度

listen queue len:     128 # socket等待队列的长度

idle processes:       4  # 空闲进程数量

active processes:     1 # 活跃的进程数量

total processes:      5 # 连接池中的总进程数量

max active processes:  2 # 连接池中最大的活跃进程数量

max children reached:  0 # 达到连接池中最大进程数量限制的上限的次数

slow requests:        0 :启用了slow-log时,记录慢请求的数量

blob.png

其它格式的输出:

/status?json

/status?xml

/status?html

/status?full

full格式的输出:

blob.png

可以通过 & 符号组合输出信息

blob.png

注意:部署需要用到session的应用时,其session的默认存储位置 ,确保此目录存在,且运行用户有写入权限;




fcgi协议反代:

ProxyRequests Off

ProxyPass 

ProxyPassMatch ^(URL_PATTERN)$  fcgi://fcgi_server:port/PATH/TO/DIR/$1

php配置文件:/etc/php.ini, /etc/php.d/*.ini 

fpm配置文件:/etc/php-fpm.conf, /etc/php-fpm.d/*.conf

编译安装amp:

(1) 系统环境:CentOS 6, 7

httpd依赖于apr和apr-util

apache portable runtime 

(2) 开发环境;

Development Tools, Server Platform Development

(3) 各程序的版本:

httpd: 2.2, 2.4

php:5.x

mysql:5.1, 5.5, 5.6, 5.7, 5.8,

mariadb: 5.x, 10.x

(4) httpd+php 

modules: –with-apxs=

prefork:libphp5.so

worker, event:libphp5-zts.so

fpm:

5.3.3-, 手动打上fpm patch;

5.3.3+:自带了fpm, 编译时只需要使用–fpm选项;

过程:

安装MySQL:

预制的二进制程序包:

os vendor:mariadb-devel或mysql-devel;

项目官方:

二进制格式程序包:展包即用;

源代码:编译安装;

通用二进制格式包的安装步骤:

# groupadd -r mysql

# useradd -g mysql -r mysql

# tar xf mariadb-VERSION-linux-x86_64.tar.gz -C /usr/local 

# cd /usr/local

# ln -sv mariadb-VERSION-linux-x86_64 mysql

# cd mysql

# chown -R root:mysql ./*

# mkdir /mydata/data -pv

# chown mysql:mysql /mydata/data

# scripts/mysql_install_db –user=mysql –datadir=/mydata/data

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

修改配置:

[mysqld]

datadir = /mydata/data

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

# chmod +x /etc/rc.d/init.d/mysqld

# chkconfig –add mysqld

# service mysqld start

安装httpd-2.4

# yum groupinstall "Development Tools" "Server Platform Development" 

# yum install pcre-devel openssl-devel libevent-devel  apr-devel apr-util-devel

# ./configure –prefix=/usr/local/apache2 –sysconfdir=/etc/httpd –enable-so –enable-ssl –enable-cgi –enable-rewrite –enable-modules=most –enable-mpms-shared=all –with-mpm=prefork –with-pcre –with-zlib –with-apr=/usr –with-apr-util=/usr

# make -j #

# make install

# apachectl start

安装php5:

# yum install gd-devel freetype-devel libmcrypt-devel libxml2-devel

./configure –prefix=/usr/local/php –with-mysql  –with-openssl –with-mysqli=/usr/bin/mysql_config –enable-mbstring –enable-xml –enable-sockets –with-freetype-dir –with-gd –with-libxml-dir=/usr –with-zlib –with-jpeg-dir –with-png-dir –with-mcrypt –with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/etc/php.ini –with-config-file-scan-dir=/etc/php.d/

# make -j #

# make install

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

# mkdir /etc/php.d/

注意:如果httpd使用线程模型MPM,需要额外的–enable-maintainer-zts选项;

注意:如果要以fpm方式运行php,需要编译时移除–with-apxs选项,额外添加–enable-fpm选项;

注意:如果是独立安装的mysql-server, 假设安装在/usr/local/mysql目录下,则需要使用类似如下的.configure命令:

./configure –prefix=/usr/local/php –with-mysql=/usr/local/mysql  –with-openssl –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-mbstring –enable-xml –enable-sockets –with-freetype-dir –with-gd –with-libxml-dir=/usr –with-zlib –with-jpeg-dir –with-png-dir –with-mcrypt –with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/etc/php.ini –with-config-file-scan-dir=/etc/php.d/

整合php至httpd上:

httpd.conf配置文件中:

AddType application/x-httpd-php .php 

DirectoryIndex index.php index.html 

类似文章