centos安装PHP7

新建php用户和php组

groupadd -r www && useradd -r -g www -s /bin/false -d /usr/local/php7 -M php

安装编译php7时需要的依赖包

yum -y install gcc libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libzip-devel wget cmake libtool

升级libzip(version >= 0.11)具体最新版本可看官方:https://nih.at/libzip/index.html

yum remove libzip -y

#1.5.1版本
wget https://nih.at/libzip/libzip-1.5.1.tar.gz
tar -zxvf libzip-1.5.1.tar.gz
cd libzip-1.5.1
mkdir build && cd build && cmake … && make && make install

#1.2.0版本(不要使用)
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install

#cmake版本低的时候
yum remove cmake
cd /opt
wget https://cmake.org/files/v3.10/cmake-3.10.2-Linux-x86_64.tar.gz
tar -zxvf cmake-3.10.2-Linux-x86_64.tar.gz
export CMAKE_HOME=/opt/cmake-3.10.2-Linux-x86_64
export PATH= P A T H : PATH: PATH:CMAKE_HOME/bin
source /etc/profile
cmake -version

##configure: error: off_t undefined; check your library configuration

添加搜索路径到配置文件

echo ‘/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64’>>/etc/ld.so.conf

更新配置

ldconfig -v

PHP7编译参数的配置

tar -xzvf php-7.3.2.tar.gz
cd php-7.3.2

./configure
–prefix=/usr/local/php7
–exec-prefix=/usr/local/php7
–bindir=/usr/local/php7/bin
–sbindir=/usr/local/php7/sbin
–includedir=/usr/local/php7/include
–libdir=/usr/local/php7/lib/php
–mandir=/usr/local/php7/php/man
–with-config-file-path=/usr/local/php7/etc
–with-mysql-sock=/var/lib/mysql/mysql.sock
–with-mhash
–with-openssl
–with-mysqli=shared,mysqlnd
–with-pdo-mysql=shared,mysqlnd
–with-gd
–with-iconv
–with-zlib
–enable-zip
–enable-inline-optimization
–disable-debug
–disable-rpath
–enable-shared
–enable-xml
–enable-bcmath
–enable-shmop
–enable-sysvsem
–enable-mbregex
–enable-mbstring
–enable-ftp
–enable-pcntl
–enable-sockets
–with-xmlrpc
–enable-soap
–without-pear
–with-gettext
–enable-session
–with-curl
–with-jpeg-dir
–with-freetype-dir
–enable-opcache
–enable-fpm
–with-fpm-user=www
–with-fpm-group=www
–without-gdbm
–disable-fileinfo

make
make test
make install

#问题:zipconf.h: No such file or directory
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
#当配置PHP时出现 make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1 时,是因为服务器内存不足1G。只需要在配置命令中添加 --disable-fileinfo即可

1 配置php.ini

php.ini是php运行核心配置文件:

######避免PHP信息暴露在http头中
expose_php = Off

######避免暴露php调用mysql的错误信息
display_errors = Off

######在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置)
log_errors = On

######设置PHP的扩展库路径
extension_dir = “/usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/”

######设置PHP的opcache和mysql动态库
zend_extension=opcache.so
extension=mysqli.so
extension=pdo_mysql.so

######设置PHP的时区
date.timezone = PRC

######开启opcache
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1

######设置PHP脚本允许访问的目录(需要根据实际情况配置)
;open_basedir = /usr/share/nginx/html;
2 配置php-fpm.conf

php-fpm.conf是 php-fpm 进程服务的配置文件:

######设置错误日志的路径
error_log = /var/log/php-fpm/error.log
######引入www.conf文件中的配置
include=/usr/local/php7/etc/php-fpm.d/*.conf
3 配置www.conf(在php-fpm.d目录下)

www.conf这是 php-fpm 进程服务的扩展配置文件:

######设置用户和用户组
user = nginx
group = nginx

######根据nginx.conf中的配置fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;设置PHP监听
; listen = 127.0.0.1:9000 #####不建议使用
listen = /var/run/php-fpm/php-fpm.sock

######开启慢日志
slowlog = /var/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 10s

######设置php的session目录(所属用户和用户组都是nginx)
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/sessio

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值