ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
1.官网下载最新版本,移动到官网下载页面:[https://www.php.net/downloads.php](https://links.jianshu.com/go?to=https%3A%2F%2Fwww.php.net%2Fdownloads.php%23v7.3.5)。鼠标移动到要下载的版本超链接文案,审查页面元素获取链接。 这里以7.3.8为例:https://www.php.net/distributions/php-7.3.8.tar.gz ``` wget -P /usr/local/src/ https://www.php.net/distributions/php-7.3.8.tar.gz // -P参数用来指定下载到哪个目录下 ``` 2.配置编译参数,比如官方扩展库的安装与否,安装文件,配置文件等的路径等等。 ./configure --help 会有所有参数的作用解释 网上有中文翻译版。以下版本为网上借鉴,并实践后解决了其中的部分错误后整理所得。 ``` > useradd www > groupadd www ``` ``` ./configure --prefix=/usr/local/php7 \ --with-config-file-path=/usr/local/php7 \ --with-fpm-user=www \ --with-fpm-group=www \ --with-curl=/usr/local/php7/curl \ --with-openssl-dir=/usr/local/php7/openssl \ --with-openssl \ --enable-sockets \ --enable-fpm \ --enable-cli \ --enable-mbstring \ --enable-pcntl \ --enable-soap \ --enable-opcache \ --enable-fileinfo \ --disable-rpath \ --enable-mysqlnd \ --with-mysqli \ --with-pdo-mysql \ --with-iconv-dir \ --with-mhash \ --with-gd=no \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --enable-zip \ --with-zlib \ --enable-simplexml \ --with-libxml-dir //配置检查过程中会报各种: #1 configure: error: libxml2 not found. Please check your libxml2 installation. yum install libxml2 libxml2-devel //那么缺什么库就使用yum安装,然后再执行上面的编译配置 #2 configure: error: Cannot find OpenSSL's <evp.h> yum install openssl openssl-devel //依然报上面的错误 改--with-openssl=/usr/local/php7/openssl => --with-openssl=/usr/local/php7/openssl-dir #3 configure: error: Please reinstall the libzip distribution yum install libzip libzip-devel #4 checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11 yum remove -y libzip //移除旧版本的libzip库,源码安装最新版本(需要cmake) yum install wget wget -P /usr/local/src/ https://libzip.org/download/libzip-1.5.2.tar.gz cd /usr/local/src/ tar -vxf libzip-1.5.2.tar.gz cd libzip-1.5.2 mkdir build && cd build && cmake .. && make && make install #5 CMake Error at CMakeLists.txt:4 (CMAKE_MINIMUM_REQUIRED): #6 CMake 3.0.2 or higher is required. You are running version 2.8.12.2 yum remove -y cmake wget -P /usr/local/src/ https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz cd /usr/local/src/ tar -vxf cmake-3.15.2.tar.gz cd cmake-3.15.2 ./configure --prefix=/usr/local/cmake-3.15.2 make make install // 我在cmke的编译过程中没有遇到报错。最后检测 cmake --version #7 -bash: /usr/bin/cmake: No such file or directory ln -s /usr/local/cmake-3.15.2/bin/cmake /usr/bin/cmake //再执行cmake --version 显示cmake version 3.15.2 vim /root/.bashrc # 增加别名定义 alias cmake='/usr/local/cmake-3.15.2/bin/cmake'保存 source /root/.bashrc //立刻生效配置 //那么我们再回到libzip的cmake安装 把问题#4 下的方案在执行一遍 cd /usr/local/src/libzip-1.5.2 rm -rf build mkdir build && cd build cmake .. #8 -- Could NOT find NETTLE (missing: NETTLE_LIBRARY NETTLE_INCLUDE_DIR) #-- Could NOT find GnuTLS (missing: GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR) #-- Could NOT find BZip2 (missing: BZIP2_LIBRARIES BZIP2_INCLUDE_DIR) #CMake Warning at CMakeLists.txt:218 (MESSAGE): # -- bzip2 library not found; bzip2 support disabled #-- Configuring done #-- Generating done #-- Build files have been written to: /usr/local/src/libzip-1.5.2/bulid yum install bzip2 bzip2-devel //再来一次 make ..少了Cmake警告 那两个无法找到的库 好像是用来加密的 网上资料很少 我无视直接编译安装了 make make install // 成功 再回到php配置编译参数执行 #9 configure: error: off_t undefined; check your library configuration vim /etc/ld.so.conf //添加内容 /usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64 //保存并退出 :wq ldconfig -v # 使之生效 成功 再回到php配置编译参数执行 #10 configure: error: Cannot find OpenSSL's <evp.h> //这个问题又出现了 蛋疼 //网上看了半天没有解决方案 最后又加了一行 --with-openssl \ 就好了 真他妈神奇 看来编译配置参数的解释要去好好看看 #11 # configure: error: Please reinstall the libcurl // yum -y install curl-devel ``` &nbsp; 3 编译和安装 ``` make test // 结果运行了很久 最后报告显示还有不少测试错误 以为出问题了也不知道怎么处理 //后来网上说 只要配置参数部分成功完成 这步可以忽略 有写测试指标依赖于环境 主要是给官方做免费测试用的 make && make install //出现以下结果为编译成功 Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20180731/ Installing PHP CLI binary: /usr/local/php7/bin/ Installing PHP CLI man page: /usr/local/php7/php/man/man1/ Installing PHP FPM binary: /usr/local/php7/sbin/ Installing PHP FPM defconfig: /usr/local/php7/etc/ Installing PHP FPM man page: /usr/local/php7/php/man/man8/ Installing PHP FPM status page: /usr/local/php7/php/php/fpm/ Installing phpdbg binary: /usr/local/php7/bin/ Installing phpdbg man page: /usr/local/php7/php/man/man1/ Installing PHP CGI binary: /usr/local/php7/bin/ Installing PHP CGI man page: /usr/local/php7/php/man/man1/ Installing build environment: /usr/local/php7/lib/php/build/ Installing header files: /usr/local/php7/include/php/ Installing helper programs: /usr/local/php7/bin/ program: phpize program: php-config Installing man pages: /usr/local/php7/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php7/lib/php/ [PEAR] Archive_Tar - installed: 1.4.7 [PEAR] Console_Getopt - installed: 1.4.2 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.4.3 [PEAR] PEAR - installed: 1.10.9 Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf You may want to add: /usr/local/php7/lib/php to your php.ini include_path /usr/local/src/php-7.3.8/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin ln -s -f phar.phar /usr/local/php7/bin/phar Installing PDO headers: /usr/local/php7/include/php/ext/pdo/ ``` &nbsp; 4 添加PHP命令目录到环境变量 有点类似于类的自动加载,输入php 则会在环境变量里的目录查找是否有php这个执行文件,如果有就直接执行,达到php 替代 /usr/local/php7/bin/php 的简化作用 ``` vim /etc/profile //在文件末尾加入 PATH=$PATH:/usr/local/php7/bin/ export PATH //保存并退出 source /etc/profile //立刻生效配置 //测试php命令 php -v //显示以下为成功 这样 PHP 7.3.8 (cli) (built: Aug 11 2019 18:55:14) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies ``` &nbsp; 5.配置php-fpm ``` // 复制php.ini到编译配置参数指定的目录。php.ini在解压的源码目录里 cp /usr/local/src/php-7.3.8/php.ini-production /usr/local/php7/php.ini // 复制一份php-fpm的配置模版文件到同级目录 方便备份和修改 cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf // 复制一份php-fpm的扩展配置模板文件到同级目录 方便备份和修改 cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf // 复制开启自起脚本到系统启动自动加载脚本目录。fpm/init.d.php-fpm在解压的源码目录里 cp /usr/local/src/php-7.3.8/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm // 使开机自起脚本可被任何权限角色执行 chmod +x /etc/init.d/php-fpm ``` 6.关于配置文件的一些说明 参考:https://www.cnblogs.com/xiaozong/p/5724984.html php-fpm.conf是PHP-FPM特有的配置文件 php.ini是所有php模式中必须的配置文件 两者的区别是,php-fpm.conf是PHP-FPM进程管理器的配置文件,php.ini是PHP解析器的配置文件 有的PHP版本的配置文件路径中还有/fpm.d/www.conf配置文件 这是php-fpm.conf配置的文件的扩展文件,可以打开php-fpm.conf文件查看 ; include=fpm.d/*.conf 我们可以使用php-fpm.conf配置慢日志 我们是可以开启慢日志功能的。 slowlog = /usr/local/var/log/php-fpm.log.slow request_slowlog_timeout = 5s ``` > mkdir -p /usr/local/var/log/ > touch /usr/local/var/log/php-fpm.log.slow > chmod -R 0777 /usr/local/var/log ``` 不这样后面启动php-fpm会失败 因为安装php时编译参数指定了php-fpm使用www账户 当某个请求的时间超过了5秒,就会在慢日志中记录相应的记录,注意上面的时间5s,不能忽略了单位,相应的还有其他单位,m分,h时(当然,这这样做太扯淡了) php-fpm慢日志会记录下进程号,脚本名称,具体哪个文件哪行代码的哪个函数执行时间过长: [21-Nov-2016 10:30:38] [pool www] pid 11877 script_filename = /var/www/ceshi/c.php [0xb70fb88c] sleep() /var/www/ceshi/c.php:2 通过日志,我们就可以知道第2行的sleep 函数有点问题,这样我们就能追踪问题了。 &nbsp; 7.php.ini的绝对路径获取 ``` php --ini ``` &nbsp; 8.扩展安装检查 ``` php -m ```