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-mysql=mysqlnd --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 --disable-safe-mode --with-gettext
报错: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
编译安装:
make && make install
3.配置文件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 = 17 disable_functions = #disable_classes = #zend.enable_gc = On #激活循环引用收集器。
expose_php = On #max_execution_time = 300 #程序执行最大时间,默认为30s,0表示没有时间限制,这里设置300s,可以自定义设置
max_input_time = 300 memory_limit = 128M error_reporting = E_ALL display_errors = Off display_startup_errors = On php有错误出理,就会提示,而且在事件查看器中有记录。如果设置为display_startup_errors = Off,则不会有任何提示
log_errors = On log_errors_max_len = 1024 error_log=/data/log/php/error_php7.log 设置错误日志文件保存路径
ignore_repeated_errors = Off ignore_repeated_source = Off report_memleaks = On track_errors = On html_errors = On variables_order = "GPCS" 此指令描述了PHP注册GET, POST, Cookie, 环境 和 内置变量的顺序 (各自使用G, P, C, E 和 S , 一般使用 EGPCS 或 GPC). 注册使用从左往右的顺序, 新的值会覆盖旧的值
request_order = "GP" register_argc_argv = Off auto_globals_jit = On post_max_size = 16M auto_prepend_file = auto_append_file = default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root = user_dir = enable_dl = Off file_uploads = On upload_max_filesize = 2M max_file_uploads = 20 allow_url_fopen = On allow_url_include = Off default_socket_timeout = 60 cgi.fix_pathinfo= 1
[CLI Server]
cli_server.color = On
[Date]
date.timezone = Asia/Shanghai 设置区域时间
[Pdo_mysql]
pdo_mysql.cache_size = 2000 pdo_mysql.default_socket= 默认的socket时间
[Phar]
[mail function] 邮件功能
SMTP = localhost smtp_port = 25 mail.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 = -1 mysqli.allow_persistent = On mysqli.max_links = -1 mysqli.cache_size = 2000 mysqli.default_port = 3306 mysqli.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 = On pgsql.auto_reset_persistent = Off pgsql.max_persistent = -1 pgsql.max_links = -1 pgsql.ignore_notice = 0 pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[Session]
session.save_handler = files session.use_strict_mode = 0
session.use_cookies = 1 session.use_only_cookies = 1 session.name = PHPSESSID session.auto_start = 0 session.cookie_lifetime = 0 session.cookie_path = / session.cookie_domain = cookie的有效域名
session.cookie_httponly = session.serialize_handler = php session.gc_probability = 1 session.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:9999 fpm监听端口,即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