首页编程LINUX/UNIX文章详细

Centos系统 + AMH4.2面板 PHP升级7.3.5

原创 2022-09-12 14:19:25 397

APHP7.3.5

下载

  wget http://cn2.php.net/distributions/php-7.3.5.tar.gz

  wget https://www.php.net/distributions/php-7.3.5.tar.xz

解压

 tar -zxvf php-7.3.5.tar.gz

进入php-7.3.5文件夹中

cd php-7.3.5

二. 编译PHP7.3.5

./configure --prefix=/usr/local/php7.0 --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib  --with-curl --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --enable-zip --enable-openssl --enable-pcntl --with-iconv=/usr/local/libiconv --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --without-pear

编译完成之后,执行安装命令

make && make install

安装过程大约需要10分钟时间,请耐心等待。

三、配置PHP

上面编译过程中我们已经将配置文件指明了位置路径

--prefix=/usr/local/php7.0 指明了安装php路径,
-with-config-file-path=/etc 指明了php.ini存放路径。

[可选项] 设置让PHP错误信息打印在页面上

vim /usr/local/php/php.ini

display_errors = On
修改/usr/local/php7.0/etc/php-fpm.conf.default
添加脚本授权

listen.owner = www
listen.group = www
listen.mode = 0660

重启linux,如果openssl报错,说明openssl文件没有安装或者php.ini配置有问题。为了进一步确认问题所在可以在测试环境中查看phpinfo()看看到底是哪里出现的问题。我这里查看出现的是配置有问题,如图
可以看出来openssl目录与路径都为空
解决办法:
/etc/php.ini
追加

extension=openssl
openssl.capath=/etc/pki/tls/certs/
openssl.cafile=/etc/pki/tls/certs/ca-bundle.crt

重新启动环境,查看配置如
目录与ca证书已经加载成功。
因为在上面我们在安装php编译过程中已经将openssl配置编译进去了,所以这里只需要配置一下就好。

注意:如果是在前面编译文件的时候没有将openssl扩展编译进去下面我们将安装php7.3.5 openssl扩展方法写出来。

五、安装openssl

1、找到之前编译安装PHP的安装包。
2、解压并进入文件夹

cd php7.3.5/ext/openssl

3、运行 phpize 初始化php,因为我们将php7.3.5安装在/usr/local/php7.0目录中了,所以php初始化文件在php7.0目录中。

/usr/local/php7.0/bin/phpize
备注,如果出现如下错误:Cannot find config.m4.
Make sure that you run ‘/usr/local/php/bin/phpize’ in the top level source directory of the module

【解决办法】cp ./config0.m4 ./config.m4 即可解决,解决问题后需要重新初始化,因为前面初始化过程中并没有成功。
4、编译

./configure --with-openssl --with-php-config=/usr/local/php7.0/bin/php-config 

5、安装

make && make install

安装成功会打印出如下信息:

/bin/sh /root/php-7.3.5/ext/openssl/libtool --mode=install cp ./openssl.la /root/php-7.3.5/ext/openssl/modules
cp ./.libs/openssl.so /root/php-7.3.5/ext/openssl/modules/openssl.so
cp ./.libs/openssl.lai /root/php-7.3.5/ext/openssl/modules/openssl.la
PATH="$PATH:/sbin" ldconfig -n /root/php-7.3.5/ext/openssl/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /root/php-7.3.5/ext/openssl/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.
Installing shared extensions:     /usr/local/php7.0/lib/php/extensions/no-debug-non-zts-20180731/

最后提示的目录就是openssl.so安装成功的目录,进入后会发现是如下信息。
/usr/local/php7.0/lib/php/extensions/no-debug-non-zts-20180731/openssl.so
5、找到php.ini,在最后面添加如下内容
extension=openssl.so
重启nginx,查看phpinfo(),到这里我们从php安装到openssl扩展的安装也就说完了。

推荐