1.安装依赖软件库:
yum install -y libxml2-devel libtool* curl-devel libjpeg-devel libpng-devel freetype-devel
2.下载php7源码包进行编译安装
[root@iZ2zef0e6br88incakir9rZ opt]# wget http://cn2.php.net/distributions/php-7.0.14.tar.gz
[root@iZ2zef0e6br88incakir9rZ opt]# tar xf php-7.0.14.tar.gz
[root@iZ2zef0e6br88incakir9rZ opt]# cd php-7.0.14
[root@iZ2zef0e6br88incakir9rZ opt]# ./configure --prefix=/usr/local/php-7.0.14 --enable-fpm --enable-opcache --with-config-file-path=/usr/local/php-7.0.14/etc --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-static --enable-sockets --enable-wddx --enable-zip --enable-calendar --enable-bcmath --enable-soap --with-zlib --with-iconv --with-freetype-dir --with-gd --with-jpeg-dir --with-xmlrpc --enable-mbstring --with-sqlite3 --with-curl --enable-ftp --with-mcrypt --with-openssl --with-gettext --enable-pcntl
报错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决:下载libmcrypt源码库
wget https://svwh.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
解决php编译报错configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install -y epel-release
yum install -y libmcrypt-devel
两个不能一起安装,因为CentOs6默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装
libmcrypt。
重新编译安装:
make && make install
3.配置文件php.ini
在安装包目录下找到并拷贝重命名到安装目录
cp php.ini-development /usr/local/php7/lib/php.ini
[PHP]
engine = On #是否启用php解析引擎
short_open_tag = On #是否使用简介标志
precision = 14 #浮点数中显示有效数字的位数
output_buffering = 4096 #输出缓冲区的大小
zlib.output_compression = Off #是否开启zlib输出压缩
implicit_flush = Off #unserialize_callback_func = #serialize_precision = 17disable_functions = #disable_classes = #zend.enable_gc = On #激活循环引用收集器。
expose_php = On #max_execution_time = 300 #程序执行最大时间,默认为30s,0表示没有时间限制,这里设置300s,可以自定义设置
max_input_time = 300memory_limit = 128Merror_reporting = E_ALLdisplay_errors = Offdisplay_startup_errors = On php有错误出理,就会提示,而且在事件查看器中有记录。如果设置为display_startup_errors = Off,则不会有任何提示
log_errors = Onlog_errors_max_len = 1024error_log=/data/log/php/error_php7.log 设置错误日志文件保存路径
ignore_repeated_errors = Offignore_repeated_source = Offreport_memleaks = Ontrack_errors = Onhtml_errors = Onvariables_order = "GPCS"此指令描述了PHP注册GET, POST, Cookie, 环境 和 内置变量的顺序 (各自使用G, P, C, E 和 S , 一般使用 EGPCS 或 GPC). 注册使用从左往右的顺序, 新的值会覆盖旧的值
request_order = "GP"register_argc_argv = Offauto_globals_jit = Onpost_max_size = 16Mauto_prepend_file =auto_append_file = default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =user_dir =enable_dl = Offfile_uploads = Onupload_max_filesize = 2Mmax_file_uploads = 20allow_url_fopen = Onallow_url_include = Offdefault_socket_timeout = 60cgi.fix_pathinfo= 1
[CLI Server]
cli_server.color = On
[Date]
date.timezone = Asia/Shanghai设置区域时间
[Pdo_mysql]
pdo_mysql.cache_size = 2000pdo_mysql.default_socket= 默认的socket时间
[Phar]
[mail function] 邮件功能
SMTP = localhostsmtp_port = 25mail.add_x_header = On 是否开启最大的header
[SQL]
sql.safe_mode = Off对于每个不同数据库的连接函数,其默认值请参考相应的手册页面。
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1mysqli.allow_persistent = Onmysqli.max_links = -1mysqli.cache_size = 2000mysqli.default_port = 3306mysqli.default_socket =mysqli.default_host = mysqli.default_user =mysqli.default_pw =mysqli.reconnect = Off[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = On
[PostgreSQL]
pgsql.allow_persistent = Onpgsql.auto_reset_persistent = Offpgsql.max_persistent = -1pgsql.max_links = -1pgsql.ignore_notice = 0pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[Session]
session.save_handler = filessession.use_strict_mode = 0
session.use_cookies = 1session.use_only_cookies = 1session.name = PHPSESSIDsession.auto_start = 0session.cookie_lifetime = 0session.cookie_path = / session.cookie_domain = cookie的有效域名
session.cookie_httponly =session.serialize_handler = phpsession.gc_probability = 1session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
[Assertion]
zend.assertions = 1
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
4.进程服务的配置文件php-fpm,把php-fpm引入www.conf文件中的配置
[root@iZ2zef0e6br88incakir9rZ etc]# cat /usr/local/php-7.0.14/etc/php-fpm.conf
include=/usr/local/php-7.0.14/etc/php-fpm.d/*.conf
[root@iZ2zef0e6br88incakir9rZ etc]# vim /usr/local/php-7.0.14/etc/php-fpm.d/www.conf
[global] 全局定义
log_level = notice错误级别. 可用级别为: alert(必须立即处理), error(错误情况), warning(警告情况), notice(一般重要信息), debug(调试信息). 默认: notice.
error_log=/data/log/php/error_php-fpm7.log错误日志文件保存路径
[www] 定义www的pool
user = www启动进程的帐户
group = www 启动进程组
listen = 127.0.0.1:9999fpm监听端口,即nginx中php处理的地址
pm = dynamic
pm的模式,分为static|dynamic两种
pm.max_children = 50子进程最大数
pm.start_servers = 10启动时的进程数
pm.min_spare_servers = 10保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程
pm.max_spare_servers = 50保证空闲进程数最大值,如果空闲进程大于此值,此进行清理
5.复制服务控制脚本php-fpm到系统服务脚本目录:
cp /opt/php-7.0.14/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm7 && chmod 755 /etc/init.d/php-fpm7
设置php7开启启动:
chkconfig --add php-fpm7
chkconfig php-fpm7 on
启动php:
service php-fpm7 start