CentOS6.10安装PHP7.3
2022-05-20 09:31 猎手家园 阅读(670) 评论(0) 编辑 收藏 举报一、依赖包安装
1、gcc
yum install gcc gcc-c++ ncurses-devel perl
yum -y install openssl openssl-devel
2、安装cmake
注:cmake版本要大于3.0,如果已经安装了低版本cmake,先卸载
rpm -qa | grep cmake
cmake -version
yum remove -y cmake
#这里下载免安装版 wget https://cmake.org/files/v3.13/cmake-3.13.5-Linux-x86_64.tar.gz tar xzf cmake-3.13.5-Linux-x86_64.tar.gz -C /usr/local cd /usr/local mv cmake-3.13.5-Linux-x86_64 cmake-3.13.5 #建立软连接 ln -sf /usr/local/cmake-3.13.5/bin/* /usr/bin/ #检验 cmake -version cmake version 3.13.5
3、其它,PHP的安装是最费劲的,每个人的系统不一样,所以只能根据错误提示进行修正。
(1)configure: error: libxml2 not found. Please check your libxml2 installation.
yum install libxml2
yum install libxml2-devel -y
(2)checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
yum install curl-devel -y
(3)configure: error: jpeglib.h not found.
yum install libjpeg-devel -y
yum install libpng
yum install libpng-devel
(4)configure: error: freetype-config not found.
yum install freetype-devel
(5)configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install -y libxslt-devel*
(6)configure: error: Please reinstall the BZip2 distribution
yum install -y bzip2-devel
注意:libzip的版本不能太高
网上有人说安装1.2.0版本,但我试验过,1.2.0版本太低会报错,我最终安装的是1.5.2版本。
#先删除旧版本 yum remove -y libzip
#下载新版本并安装
wget https://libzip.org/download/libzip-1.5.2.tar.gz tar -xvzf libzip-1.5.2.tar.gz cd libzip-1.5.2 mkdir build cd build/ cmake .. make & make install
添加配置文件:
vim /etc/ld.so.conf.d/libzip.conf
/usr/local/lib64/
/usr/local/lib/
/lib/
/usr/local/lib/
/lib64/
/usr/local/share/
/usr/local/share/
如cmake时遇到错误:zstd library not found; zstandard support disabled
yum install epel-release
yum install libzstd-devel
二、安装PHP7.3
1、软件下载
https://www.php.net/downloads.php
2、安装
#编译
./configure --prefix=/usr/local/php7.3 --with-config-file-path=/usr/local/php7.3/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-openssl --with-pcre-regex --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-openssl --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --enable-mbstring --enable-mysqlnd --with-pdo-mysql=mysqlnd
安装执行configure报错error: off_t undefined; check your library configuration
vim /etc/ld.so.conf #添加如下几行 /usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64 #保存退出 #最好是重启,使之生效
参数说明:
#指定php安装目录 –prefix=/usr/local/php7.3 #指定php.ini位置 –with-config-file-path=/usr/local/php7.3/etc #打开curl浏览工具的支持 –with-curl #打开对freetype字体库的支持 –with-freetype-dir #打开gd库的支持 –with-gd #打开gnu 的gettext 支持,编码库用到 –with-gettext #选项指令 --with-iconv-dir 用于 PHP 编译时指定 iconv 在系统里的路径,否则会扫描默认路径。 –with-iconv-dir #打开libxml2库的支持 –with-libxml-dir #object code libraries [EPREFIX/lib] –with-libdir=lib64 #openssl的支持,加密传输https时用到的 –with-openssl #OPENSSL: Include Kerberos support –with-kerberos #fpm –enable-fpm #Include Perl Compatible Regular Expressions support. –with-pcre-regex #PDO: MySQL支持 –with-pdo-mysql –with-pdo-sqlite #打开pear命令的支持,PHP扩展用的 –with-pear #打开对png图片的支持 –with-png-dir #打开对jpeg图片的支持 –with-jpeg-dir #打开对XMLRPC-EP支持 –with-xmlrpc #打开对XSL的支持. DIR is the libxslt base install directory (libxslt >= 1.1.0 required) –with-xsl #打开对ZLIB的支持 (requires zlib >= 1.2.0.4) –with-zlib #打开bc精确数学函数 –enable-bcmath #打开LIBXML支持 –enable-libxml #优化线程 –enable-inline-optimization –enable-mbregex #多字节,字符串的支持 –enable-mbstring #开启Zend OPcache支持 –enable-opcache #freeTDS需要用到的,可能是链接mssql 才用到 –enable-pcntl #可以处理相关的IPC函数 –enable-shmop –enable-sysvsem #开启SOAP支持 –enable-soap #打开 sockets 支持 –enable-sockets –enable-xml #打开对zip的支持 –enable-zip
当你看到这个截图,说明编译成功了
#安装
make && make install
#安装成功
Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/php7.3/lib/php/extensions/no-debug-non-zts-20180731/ Installing PHP CLI binary: /usr/local/php7.3/bin/ Installing PHP CLI man page: /usr/local/php7.3/php/man/man1/ Installing PHP FPM binary: /usr/local/php7.3/sbin/ Installing PHP FPM defconfig: /usr/local/php7.3/etc/ Installing PHP FPM man page: /usr/local/php7.3/php/man/man8/ Installing PHP FPM status page: /usr/local/php7.3/php/php/fpm/ Installing phpdbg binary: /usr/local/php7.3/bin/ Installing phpdbg man page: /usr/local/php7.3/php/man/man1/ Installing PHP CGI binary: /usr/local/php7.3/bin/ Installing PHP CGI man page: /usr/local/php7.3/php/man/man1/ Installing build environment: /usr/local/php7.3/lib/php/build/ Installing header files: /usr/local/php7.3/include/php/ Installing helper programs: /usr/local/php7.3/bin/ program: phpize program: php-config Installing man pages: /usr/local/php7.3/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php7.3/lib/php/ [PEAR] Archive_Tar - installed: 1.4.14 [PEAR] Console_Getopt - installed: 1.4.3 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.4.5 warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.14 is not the recommended version 1.4.4 [PEAR] PEAR - installed: 1.10.13 Wrote PEAR system config file at: /usr/local/php7.3/etc/pear.conf You may want to add: /usr/local/php7.3/lib/php to your php.ini include_path /root/packages/php-7.3.30/build/shtool install -c ext/phar/phar.phar /usr/local/php7.3/bin ln -s -f phar.phar /usr/local/php7.3/bin/phar Installing PDO headers: /usr/local/php7.3/include/php/ext/pdo/
#查看php版本
/usr/local/php7.3/bin/php -v #显示如下 PHP 7.3.30 (cli) (built: May 19 2022 17:20:22) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.30, Copyright (c) 1998-2018 Zend Technologies
3、配置文件
#拷贝文件
cp /usr/local/php7.3/etc/php-fpm.conf.default /usr/local/php7.3/etc/php-fpm.conf cp /usr/local/php7.3/etc/php-fpm.d/www.conf.default /usr/local/php7.3/etc/php-fpm.d/www.conf cp php.ini-development /usr/local/php7.3/etc/php.ini
#配置 www.conf
cd /usr/local/php/etc/php-fpm.d
vim www.conf
#具体内容
[www] listen = 127.0.0.1:9001 #改一下默认端口,默认端口是9000 user = nobody group = nobody pm = dynamic pm.max_children = 128 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 10000 rlimit_files = 1024
slowlog = log/$pool.log.slow
4、修改php.ini配置文件
cd /usr/local/php7.3/etc
vim php.ini
cgi.fix_pathinfo=0
5、启动php
cd /usr/local/php7.3/sbin ./php-fpm ps aux | grep php #如果看到有结果则说明安装成功 root 2021 0.0 0.1 217880 6312 ? Ss 00:59 0:00 php-fpm: master process (/usr/local/php7.3/etc/php-fpm.conf) nobody 2022 0.0 0.1 217880 5792 ? S 00:59 0:00 php-fpm: pool www nobody 2023 0.0 0.1 217880 5792 ? S 00:59 0:00 php-fpm: pool www
6、添加环境变量
vim /etc/profile
#在文件底部加入
#PHP7.3
export PATH=$PATH:/usr/local/php7.3/bin
#保存,使环境变量生效
source /etc/profile
7、配置fpm命令
cd php-7.3.30/sbin cp php-fpm /etc/init.d/php-fpm #增加权限 chmod +x /etc/init.d/php-fpm
8、fpm命令
service php-fpm reload service php-fpm start service php-fpm stop
9、查看进程状态
service php-fpm status
结果:php-fpm (pid 1072864) is running...
三、安装PHP扩展
1、需要autoconf版本2.68
#检查是否有安装autoconf其他版本: rpm -qf /usr/bin/autoconf #如有安装则先卸载相应版本 rpm -e --nodeps autoconf-2.63
#下载安装新版本
#下载 wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz #安装: tar zxvf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure --prefix=/usr/ make && make install #检查版本: /usr/bin/autoconf -V
2、PHP安装包中自带很多扩展,以安装zip为例
#1、进入要安装的扩展包文件夹下,如: cd php-7.3.30/ext/zip #2、通过phpize生成编译文件: /usr/local/php7.3/bin/phpize #3、编译 ./configure --with-php-config=/usr/local/php7.3/bin/php-config #4、安装 make && make install
3、安装自带扩展以外的扩展,如redis
下载:http://pecl.php.net/get/redis-5.0.0.tgz
#1、解压并进入目录 tar xzf redis-5.0.0.tgz cd redis-5.0.0 #2、通过phpize生成编译文件: /usr/local/php7.3/bin/phpize #3、编译 ./configure --with-php-config=/usr/local/php7.3/bin/php-config #4、安装 make && make install
#重要一步
打开文件 etc/php.ini,写入redis扩展
vim etc/php.ini extension=redis.so #在最后一行写入redis.io 扩展
重启php-fpm后,输入:php -m 就能检查扩展是否安装成功
![](https://images.cnblogs.com/cnblogs_com/hunttown/823638/o_yunqiyu.jpg)