【Do家】php-fpm&nginx下从源码安装部署php及配置注意事项_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > 【Do家】php-fpm&nginx下从源码安装部署php及配置注意事项

【Do家】php-fpm&nginx下从源码安装部署php及配置注意事项

 2021/5/10 17:06:49  can_do  程序员俱乐部  我要评论(0)
  • 摘要:1、源码安装安装三步曲:前提:需要打补丁【php-5.2.17.tar.gz】获取方式:链接:https://pan.baidu.com/s/1kpZyyOK_AHPqkAIF71RdWg提取码:cndo【php-5.2.17.patch】获取方式:链接:https://pan.baidu.com/s/1Tlg-dPDQieonsESx-ICbfQ提取码:cndo【php-5.2.17-fpm-0.5.14.diff.gz】获取方式:链接:https://pan.baidu
  • 标签:注意事项 PHP 源码 安装 配置 Nginx 事项
1、源码安装
安装三步曲:

前提:需要打补丁

【php-5.2.17.tar.gz】获取方式:
链接:https://pan.baidu.com/s/1kpZyyOK_AHPqkAIF71RdWg
提取码:cndo

【php-5.2.17.patch】获取方式:
链接:https://pan.baidu.com/s/1Tlg-dPDQieonsESx-ICbfQ
提取码:cndo

【php-5.2.17-fpm-0.5.14.diff.gz】获取方式:
链接:https://pan.baidu.com/s/1PZGPyV7WK4i2mLpDOPIFuA
提取码:cndo

class="php">

tarz -zxvf php-5.2.17.tar.gz

gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | sudo patch -d php-5.2.17 -p1

# 打patch 
cd php-5.2.17/
patch -p0 -b <../php-5.2.17.patch



1> configure
注意:configure前需要检查依赖安装

2> make 或者 make -j `nproc`
注意:按要求安装相关依赖

PHP 5.2.17安装编译时报错集锦
注意通过yum list和yum provides预查找要安装的依赖包是否存在?

yum list *ldap*
yum provides *ldap*

【问题_1】
configure: error: DBA: Could not find necessary header file(s).
【解决】
yum install gdbm-devel
*************************
./configure --prefix=/usr/local/php --with-config-file-path=/usr/bin --with-mysql=/usr/include/mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear --with-zlib --enable-pdo --with-pdo-mysql
***********************
【问题_2】
checking whether to enable LIBXML support... yes
checking libxml2 install dir... /usr
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
【解决】
=># yum list libxml2
=># yum install libxml2.x86_64

=># yum list xml2-config
  如果还出现configure: error: xml2-config not found. Please check your libxml2 installation错误,则可能是缺少libxml2-dev。

  执行# yum list xml2-config
************************
【问题_3】
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: libjpeg.(a|so) not found.
【解决】
=># cp -frp /usr/lib64/libjpeg.* /usr/lib
**************************
【问题_4】
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
checking for jpeg_read_header in -ljpeg... yes
configure: error: libpng.(a|so) not found.
【解决】
=># cp -frp /usr/lib64/libpng.* /usr/lib
*********************
【问题_5】
checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype.h not found.
【解决】
=> # yum install freetype-devel
************************
【问题_6】
checking whether to enable JavaScript Object Serialization support... yes
checking for ANSI C header files... (cached) yes
checking for LDAP support... yes
checking for LDAP Cyrus SASL support... yes
configure: error: Cannot find ldap.h
【解决】
=> # yum install  openldap-devel
************************
【问题_7】
checking whether to enable JavaScript Object Serialization support... yes
checking for ANSI C header files... (cached) yes
checking for LDAP support... yes
checking for LDAP Cyrus SASL support... yes
configure: error: Cannot find ldap libraries in /usr/lib.
【解决】
=> # yum install  openldap.x86_64
*************************
【问题_8】
checking whether time.h and sys/time.h may both be included... yes
checking for working alloca.h... (cached) yes
checking for alloca... (cached) yes
checking for 8-bit clean memcmp... yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
【解决】
=> # yum install libmcrypt-devel
*************************
【问题_9】
checking whether time.h and sys/time.h may both be included... yes
checking for working alloca.h... (cached) yes
checking for alloca... (cached) yes
checking for 8-bit clean memcmp... yes
checking for mcrypt support... yes
checking for libmcrypt version... >= 2.5.6
checking for mcrypt_module_open in -lmcrypt... no
checking for mcrypt_module_open in -lmcrypt... yes
checking for mhash support... yes
configure: error: Please reinstall libmhash - I cannot find mhash.h
【解决】
=> # yum install mhash-devel
********************
【问题_10】
checking whether to include mime_magic support... no
checking for MING support... no
checking for mSQL support... no
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... no
configure: error: Cannot find MySQL header files under /usr/local/mysql.
Note that the MySQL client library is not bundled anymore!
【解决】
=> -with-mysql=/usr/include/mysql,这个参数应该不对,
把它改为
--with-mysql

--with-mysql=/bin/mysql
********************
【问题_11】
checking whether to include mime_magic support... no
checking for MING support... no
checking for mSQL support... no
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... no
configure: error: Cannot find MySQL header files under /bin/mysql.
Note that the MySQL client library is not bundled anymore!
【解决】
=> # find / -name mysql.h
=> # yum list mysql-devel

yum install mysql-community-devel
******************
【问题_12】
checking whether to include mime_magic support... no
checking for MING support... no
checking for mSQL support... no
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... no
configure: error: Cannot find libmysqlclient under /usr.
Note that the MySQL client library is not bundled anymore!
**********************

【解决】
注意:
Centos和Debian对dev包的名称不同
1> CentOS => -devel => freetype-devel.x86_64 0:2.8-14.el7
2> Debian => -dev
***********************
【问题_13】
make => in error
/opt/temp/0909/php-5.2.12/ext/dom/node.c: 在函数‘dom_canonicalization’中:
/opt/temp/0909/php-5.2.12/ext/dom/node.c:1953:21: 错误:提领指向不完全类型的指针
    ret = buf->buffer->use;
                     ^
In file included from /opt/temp/0909/php-5.2.12/main/php.h:38:0,
                 from /opt/temp/0909/php-5.2.12/ext/dom/node.c:26:
/opt/temp/0909/php-5.2.12/ext/dom/node.c:1955:40: 错误:提领指向不完全类型的指针
     RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
                                        ^
/opt/temp/0909/php-5.2.12/Zend/zend_API.h:472:14: 附注:in definition of macro ‘ZVAL_STRINGL’
   char *__s=(s); int __l=l;  \
              ^
/opt/temp/0909/php-5.2.12/ext/dom/node.c:1955:5: 附注:in expansion of macro ‘RETVAL_STRINGL’
     RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
     ^
make: *** [ext/dom/node.lo] 错误 1
【解决】
C代码本身编译报错的话,需要从源码解决,将C代码调整或者打相应版本的patch


3> make install

2、php-fpm配置文件位置:
# ll /usr/local/php/etc/php-fpm.conf 
-rw-r--r--. 1 root root 5203 9月  16 14:18 /usr/local/php/etc/php-fpm.conf


3、配置:
采用php-fpm,一般都是同nginx在同一主机下通讯,如果要跨主机走TCP,要调整以下配置:
1> listen地址放开:
    Address to accept fastcgi requests on.
                        Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
                        <value name="listen_address">0.0.0.0:9000</value>


2> 从php-fpm允许可访问ip配置:
Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
                        Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
                        Makes sense only with AF_INET listening socket.
                        <value name="allowed_clients">127.0.0.1,172.60.1.163</value>


4、打开php-fpm慢日志方式:
The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
		'0s' means 'off'
		<value name="request_slowlog_timeout">3s</value>

		The log file for slow requests
		<value name="slowlog">logs/slow.log</value>


5、优化pm线程池,注意区分static还是dynamic
Process manager settings
			<value name="pm">

				Sets style of controling worker process count.
				Valid values are 'static' and 'apache-like'
				<value name="style">apache-like</value>

				Sets the limit on the number of simultaneous requests that will be served.
				Equivalent to Apache MaxClients directive.
				Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
				Used with any pm_style.
				<value name="max_children">100</value>

				Settings group for 'apache-like' pm style
				<value name="apache_like">

					Sets the number of server processes created on startup.
					Used only when 'apache-like' pm_style is selected
					<value name="StartServers">5</value>

					Sets the desired minimum number of idle server processes.
					Used only when 'apache-like' pm_style is selected
					<value name="MinSpareServers">5</value>

					Sets the desired maximum number of idle server processes.
					Used only when 'apache-like' pm_style is selected
					<value name="MaxSpareServers">100</value>

				</value>

			</value>


6、采用非root用户配置
Unix user of processes
          <value name="user">deploy_user</value>

             Unix group of processes
        <value name="group">root</value>


7、日志级别和日志文件位置
Error log file
     <value name="error_log">/usr/local/php/logs/php-fpm.log</value>

     Log level
     <value name="log_level">debug</value>


【温馨提示】
如果您觉得满意,可以选择支持下,您的支持是我最大的动力:

发表评论
用户名: 匿名