技术标签: php预先配置的安装包
一、准备
# cd /opt/zone
# wget http://am1.php.net/distributions/php-7.1.12.tar.gz
# tar zxvf php-7.1.12.tar.gz
# cd php-7.1.12
二、查看安装帮助,执行配置脚本进行编译预处理
# cd /opt/zone/php-7.1.12
# ./configure --prefix=/usr/local/php7.1.12 \
--with-openssl \
--with-kerberos \
--with-xmlrpc \
--with-mysql-sock \
--with-mysqli \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-zlib \
--with-iconv \
--with-bz2 \
--with-curl \
--with-cdb \
--with-pcre-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--with-libmbfl \
--with-onig \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-readline \
--with-libxml-dir \
--with-xsl \
--with-pear \
--enable-fpm \
--enable-cgi \
--enable-soap \
--enable-bcmath \
--enable-calendar \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--enable-ftp \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--enable-pdo \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--enable-zip \
--enable-mysqlnd-compression-support \
--enable-libxml \
--enable-inline-optimization \
--enable-opcache \
--enable-pcntl \
--enable-xml \
--enable-intl
三、预处理错误,一般是缺少依赖包,根据提示安装即可
3.1、error: Please reinstall the BZip2 distribution.
# apt-get install libbz2-dev
3.2、error: jpeglib.h not found.
# apt-get install libjpeg-dev
3.3、error: png.h not found.
# apt-get install libpng-dev
3.4、error: mcrypt.h not found. Please reinstall libmcrypt.
# apt-get -y install libmcrypt-dev
3.5、error: Please reinstall readline - I cannot find readline.h
# apt-get install libreadline-dev
3.6、openssl依赖,使用版本1.0.2g
# apt-get install openssl=1.0.2g-1ubuntu4.10
# apt-get install libssl-dev=1.0.2g-1ubuntu4.10
# apt-get install libcurl4-openssl-dev
以上两个版本,需要添加如下源:
# vi /etc/apt/sources.list
加入以下几行:
deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ xenial universe
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe
deb http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
然后:
# apt-get update
可以通过以下命令查看openssl版本:
# openssl version
3.7、error: freetype-config not found.
# apt-get -y install libfreetype6-dev
3.8、error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
# apt-get install libicu-dev
3.9、error: mcrypt.h not found. Please reinstall libmcrypt.
# apt-get -y install libmcrypt-dev
3.10、error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
# apt-get install libxslt-dev
3.11、make时出错
/opt/zone/php-7.1.12/ext/standard/random.c: In function ‘php_random_bytes’:
/opt/zone/php-7.1.12/ext/standard/random.c:113:15: error: ‘__NR_getrandom’ undeclared (first use in this function)
n = syscall(SYS_getrandom, bytes + read_bytes, amount_to_read, 0);
原因:make时,gcc(g++)版本是4:5.3.1-1ubuntu1,可以通过以下命令查看版本
# apt-show-versions -a gcc(g++)
解决方案:重新安装gcc(g++),指定版本4:4.8.2-1ubuntu6,通过以下命令
# apt-get install gcc(g++)=4:4.8.2-1ubuntu6
以下解决方案是正确的:
In file included from /usr/include/x86_64-linux-gnu/sys/syscall.h:31:0,
from /opt/zone/php-7.1.12/ext/standard/random.c:34:
/opt/zone/php-7.1.12/ext/standard/random.c: In function ‘php_random_bytes’:
/opt/zone/php-7.1.12/ext/standard/random.c:113:15: error: ‘__NR_getrandom’ undeclared (first use in this function)
n = syscall(SYS_getrandom, bytes + read_bytes, amount_to_read, 0);
^
/opt/zone/php-7.1.12/ext/standard/random.c:113:15: note: each undeclared identifier is reported only once for each function it appears in
# vi /opt/zone/php-7.1.12/ext/standard/random.c
修改该文件的第113行:n = syscall(SYS_getrandom, bytes + read_bytes, amount_to_read, 0);
改为:n = syscall(355, bytes + read_bytes, amount_to_read, 0);
3.12、error: cURL version 7.10.5 or later is required to compile php with cURL support
# apt-get remove curl
# apt-get install curl
# apt-get install libcurl4-openssl-dev
3.13、error: Please reinstall readline - I cannot find readline.h
# apt install -y libedit-dev libreadline-dev
四、编译安装
# cd /opt/zone/php-7.1.12
# make
# make install
php将会被安装到/usr/local/php7.1.12/目录下面。
五、配置php
5.1、php.ini
# cp /opt/zone/php-7.1.12/php.ini-development /usr/local/php7.1.12/lib/php.ini
php扩展库目录:/usr/local/php7.1.12/lib/php/extensions/no-debug-non-zts-20160303/
5.2、php-fpm
# mv /usr/local/php7.1.12/etc/php-fpm.conf.default /usr/local/php7.1.12/etc/php-fpm.conf
# mv /usr/local/php7.1.12/etc/php-fpm.d/www.conf.default /usr/local/php7.1.12/etc/php-fpm.d/www.conf
5.3、/usr/local/php7.1.12/etc/php-fpm.conf重要参数详解
pid = run/php-fpm.pid
#pid设置,默认在安装目录中的var/run/php-fpm.pid,建议开启
error_log = log/php-fpm.log
#错误日志,默认在安装目录中的var/log/php-fpm.log
log_level = notice
#错误级别. 可用级别为: alert(必须立即处理), error(错误情况), warning(警告情况), notice(一般重要信息), debug(调试信息). 默认: notice.
emergency_restart_threshold = 60
emergency_restart_interval = 60s
#表示在emergency_restart_interval所设值内出现SIGSEGV或者SIGBUS错误的php-cgi进程数如果超过 emergency_restart_threshold个,php-fpm就会优雅重启。这两个选项一般保持默认值。
process_control_timeout = 0
#设置子进程接受主进程复用信号的超时时间. 可用单位: s(秒), m(分), h(小时), 或者 d(天) 默认单位: s(秒). 默认值: 0.
daemonize = yes
#后台执行fpm,默认值为yes,如果为了调试可以改为no。在FPM中,可以使用不同的设置来运行多个进程池。 这些设置可以针对每个进程池单独设置。
5.4、/usr/local/php7.1.12/etc/php-fpm.d/www.conf重要参数详解
listen = 127.0.0.1:9000
#fpm监听端口,即nginx中php处理的地址,一般默认值即可。可用格式为: 'ip:port', 'port', '/path/to/unix/socket'. 每个进程池都需要设置.
#nginx的配置文件中,应该这样配置与php-fpm的通信:fastcgi_pass 127.0.0.1:9000;
listen.backlog = -1
#backlog数,-1表示无限制,由操作系统决定,此行注释掉就行。backlog含义参考:http://www.3gyou.cc/?p=41
listen.allowed_clients = 127.0.0.1
#允许访问FastCGI进程的IP,设置any为不限制IP,如果要设置其他主机的nginx也能访问这台FPM进程,listen处要设置成本地可被访问的IP。默认值是any。每个地址是用逗号分隔. 如果没有设置或者为空,则允许任何服务器请求连接
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
#unix socket设置选项,如果使用tcp方式访问,这里注释即可。
user = www-data
group = www-data
#启动进程的帐户和组
pm = dynamic #对于专用服务器,pm可以设置为static。
#如何控制子进程,选项有static和dynamic。如果选择static,则由pm.max_children指定固定的子进程数。如果选择dynamic,则由下开参数决定:
pm.max_children #,子进程最大数
pm.start_servers #,启动时的进程数
pm.min_spare_servers #,保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程
pm.max_spare_servers #,保证空闲进程数最大值,如果空闲进程大于此值,此进行清理
pm.max_requests = 1000
#设置每个子进程重生之前服务的请求数. 对于可能存在内存泄漏的第三方模块来说是非常有用的. 如果设置为 '0' 则一直接受请求. 等同于 PHP_FCGI_MAX_REQUESTS 环境变量. 默认值: 0.
pm.status_path = /status
#FPM状态页面的网址. 如果没有设置, 则无法访问状态页面. 默认值: none. munin监控会使用到
ping.path = /ping
#FPM监控页面的ping网址. 如果没有设置, 则无法访问ping页面. 该页面用于外部检测FPM是否存活并且可以响应请求. 请注意必须以斜线开头 (/)。
ping.response = pong
#用于定义ping请求的返回相应. 返回为 HTTP 200 的 text/plain 格式文本. 默认值: pong.
request_terminate_timeout = 0
#设置单个请求的超时中止时间. 该选项可能会对php.ini设置中的'max_execution_time'因为某些特殊原因没有中止运行的脚本有用. 设置为 '0' 表示 'Off'.当经常出现502错误时可以尝试更改此选项。
request_slowlog_timeout = 10s
#当一个请求该设置的超时时间后,就会将对应的PHP调用堆栈信息完整写入到慢日志中. 设置为 '0' 表示 'Off'
slowlog = log/$pool.log.slow
#慢请求的记录日志,配合request_slowlog_timeout使用
rlimit_files = 1024
#设置文件打开描述符的rlimit限制. 默认值: 系统定义值默认可打开句柄是1024,可使用 ulimit -n查看,ulimit -n 2048修改。
rlimit_core = 0
#设置核心rlimit最大限制值. 可用值: 'unlimited' 、0或者正整数. 默认值: 系统定义值.
chroot =
#启动时的Chroot目录. 所定义的目录需要是绝对路径. 如果没有设置, 则chroot不被使用.
chdir =
#设置启动目录,启动时会自动Chdir到该目录. 所定义的目录需要是绝对路径. 默认值: 当前目录,或者/目录(chroot时)
catch_workers_output = yes
#重定向运行过程中的stdout和stderr到主要的错误日志文件中. 如果没有设置, stdout 和 stderr 将会根据FastCGI的规则被重定向到 /dev/null . 默认值: 空.
5.5、php-fpm常见错误及解决办法整理
a、request_terminate_timeout的值如果设置为0或者过长的时间,可能会引起file_get_contents的资源问题。
如果file_get_contents请求的远程资源如果反应过慢,file_get_contents就会一直卡在那里不会超时,我们知道php.ini 里面max_execution_time 可以设置 PHP 脚本的最大执行时间,但是,在 php-cgi(php-fpm) 中,该参数不会起效。真正能够控制 PHP 脚本最大执行时间的是 php-fpm.conf 配置文件中的request_terminate_timeout参数。
request_terminate_timeout默认值为 0 秒,也就是说,PHP 脚本会一直执行下去。这样,当所有的 php-cgi 进程都卡在 file_get_contents() 函数时,这台 Nginx+PHP 的 WebServer 已经无法再处理新的 PHP 请求了,Nginx 将给用户返回“502 Bad Gateway”。修改该参数,设置一个 PHP 脚本最大执行时间是必要的,但是,治标不治本。例如改成 30s,如果发生 file_get_contents() 获取网页内容较慢的情况,这就意味着 150 个 php-cgi 进程,每秒钟只能处理 5 个请求,WebServer 同样很难避免"502 Bad Gateway"。解决办法是request_terminate_timeout设置为10s或者一个合理的值,或者给file_get_contents加一个超时参数。
b、max_requests参数配置不当,可能会引起间歇性502错误:
pm.max_requests = 1000 设置每个子进程重生之前服务的请求数. 对于可能存在内存泄漏的第三方模块来说是非常有用的. 如果设置为 '0' 则一直接受请求. 等同于 PHP_FCGI_MAX_REQUESTS 环境变量. 默认值: 0.
这段配置的意思是,当一个 PHP-CGI 进程处理的请求数累积到 500 个后,自动重启该进程。
但是为什么要重启进程呢?
一般在项目中,我们多多少少都会用到一些 PHP 的第三方库,这些第三方库经常存在内存泄漏问题,如果不定期重启 PHP-CGI 进程,势必造成内存使用量不断增长。因此 PHP-FPM 作为 PHP-CGI 的管理器,提供了这么一项监控功能,对请求达到指定次数的 PHP-CGI 进程进行重启,保证内存使用量不增长。
正是因为这个机制,在高并发的站点中,经常导致 502 错误,我猜测原因是 PHP-FPM 对从 NGINX 过来的请求队列没处理好。不过我目前用的还是 PHP 5.3.2,不知道在 PHP 5.3.3 中是否还存在这个问题。
目前我们的解决方法是,把这个值尽量设置大些,尽可能减少 PHP-CGI 重新 SPAWN 的次数,同时也能提高总体性能。在我们自己实际的生产环境中发现,内存泄漏并不明显,因此我们将这个值设置得非常大(204800)。大家要根据自己的实际情况设置这个值,不能盲目地加大。
话说回来,这套机制目的只为保证 PHP-CGI 不过分地占用内存,为何不通过检测内存的方式来处理呢?我非常认同高春辉所说的,通过设置进程的峰值内在占用量来重启 PHP-CGI 进程,会是更好的一个解决方案。
c、php-fpm的慢日志,debug及异常排查神器:
request_slowlog_timeout设置一个超时的参数,slowlog设置慢日志的存放位置,tail -f /var/log/www.slow.log即可看到执行过慢的php过程。
大家可以看到经常出现的网络读取超过、Mysql查询过慢的问题,根据提示信息再排查问题就有很明确的方向了。
5.6、php-fpm服务脚本
# cp /opt/zone/php-7.1.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #复制cgi管理器,得到php-fpm
# chmod +x /etc/init.d/php-fpm #附上可执行权限
# sysv-rc-conf php-fpm on #加入开机启动项,直接加入启动程序,例如把 /etc/init.d/php7.1.12-fpm 加入到系统自动启动列表中
# service php-fpm start #启动php-fpm
# ps -ef | grep php-fpm #查看php-fpm启动状态
# netstat -ntlp | grep 9000 #查看端口号
指定启动php.ini配置文件
在/etc/init.d/php-fpm文件中找到下面代码:
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
改为:
php_fpm_INI=${prefix}/lib/php.ini
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID -c $php_fpm_INI"
六、php-fpm的启动参数
测试php-fpm配置
# /usr/local/php7.1.12/sbin/php-fpm -t
# /usr/local/php7.1.12/sbin/php-fpm -c /usr/local/php7.1.12/etc/php.ini -y /usr/local/php7.1.12/etc/php-fpm.conf -t
启动php-fpm
# /usr/local/php7.1.12/sbin/php-fpm
# /usr/local/php7.1.12/sbin/php-fpm -c /usr/local/php7.1.12/etc/php.ini -y /usr/local/php7.1.12/etc/php-fpm.conf
关闭php-fpm
# kill -INT `cat /usr/local/php7.1.12/var/run/php-fpm.pid`
重启php-fpm
# kill -USR2 `cat /usr/local/php7.1.12/var/run/php-fpm.pid`
文章浏览阅读120次。1.薪资丰厚: 基本薪资+绩效+项目奖金+年终奖2.福利: 和正式员工福利基本看齐,共享工位,免费夜宵,班车,一流办公环境,月末周六双倍工资3.技术栈:C/C+当用例很多的时候,每次。不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦。不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦虑不焦。
文章浏览阅读871次,点赞11次,收藏3次。*单片机设计介绍, 基于51单片机冰箱温度控制器设计。_基于51单片机的智能冰箱控制系统设计
文章浏览阅读4.8k次。一、sftp服务器进入root模式(下面的操作默认都是在root用户下)#安装openssh-serverapt-get install -y openssh-server创建sftp的组和用户#创建sftp-users组groupadd sftp-users#创建sftp用户目录alicemkdir /home/alice#创建sftp用户alice,并且绑定其主目..._ubuntu sftp服务器查看用户和密码
文章浏览阅读5.9k次,点赞9次,收藏16次。解决了在simulink中使用s-function遇到的报错:State derivatives returned by S-function 'demo' in 'test/S-Function' during flag=1 call must be a real vector of length 2 _state derivatives returned by s-function 'pmsm' in 'ipmsm/ipmsm/s-function1
文章浏览阅读3.1k次。1. 打开配置文件Mac 如下图2. 在文件内部添加这段文字,就可以了:"update_check":false _mac sublime text 取消更新提示
文章浏览阅读548次,点赞10次,收藏6次。Linux系统下DNS配置指南_linux 服务器修改网络dns
文章浏览阅读1.6k次。将Total Commander设置为“默认”文件管理器?法一:开始,运行,输入regedit ,回车: 定位到HKEY_LOCAL_MACHINE_total commander默认文件管理器
文章浏览阅读7.7k次。反序列化无法找到程序集提示找不到程序集. 原因是序列化时把序列化类的命名空间等信息保存了,但应用程序和类库的命名空间可能是不一样的,所以提示找不到程序集. 解决方法如下: 方法1.将dll加入强名称,注册到全局程序集缓存中 方法2.在反序列化使用的IFormatter 对象加入Binder 属性,使其获取要反序列化的对象所在的程序集_未能找到程序集“g:\c#%5cc#%20%e4%b8%8a%e4%bd%8d%e6%9c%ba%5c%e7%a9%ba%e5%8e%8
文章浏览阅读234次。Jet-Lube EZY-Turn Kopr-Kote Deacon Moly-Lith 12|34 21 (Oilfield) 21 (Water Well) 21 Arctic (Oilfield) 21 Arctic (Water Well) 550 Extreme 550 Extreme All Weather 713-670-5700 769 Lubricant 930 Whitmore Drive Alco-EP Alco-EP ECF Alco-EP-73 Plus AP-1 AP-1W _dpezy
文章浏览阅读511次。本文从本人简书博客同步过来在上一篇中我们简要地介绍了 mpi4py 中的单边通信概念,下面我们将介绍单边通信的相关操作。创建/释放窗口对象注意:在使用单边通信操作之前,所有进程都须通过共同参与的创建窗口操作公开声明自己可供访问的内存空间。创建和释放窗口对象的方法(MPI.Win 类方法)接口如下:Create(type cls, memory, int disp_unit=..._win.fence() win.free()
文章浏览阅读551次,点赞23次,收藏7次。mit6.824的lab1,实现MapReduce_mitmapreduce实现csdn
文章浏览阅读6.6k次,点赞10次,收藏82次。在刚开始学Android开发时,下载好了Android studio,但是不知道如何下手,现在就通过一个简单的小项目熟悉如何使用这个软件进行Android开发。前提:下载好Android studio并配置好相关环境。首先介绍一下Android开发过程中需要修改的三类文件:位于java包下的各类activity文件:实现了用户与软件的交互,主要为java代码实现。位于res包下的.xml文件:在layout包里的为布局文件,即Android界面显示的视图,而drawable里则放置了某个控件的_android studio简单项目