centos7.5配置php,腾讯云centos7.5编译安装PHP7.4

我的环境为centos-release-7-5.1804.el7.centos.x86_64

下载php7.4

为了方便管理, 我将所有的下载的软件都放在同一个地方, 在/data 下面新建一个文件夹programs

cd /data

mkdir programs

cd programs

# 下载php源文件

wget https://www.php.net/distributions/php-7.4.7.tar.gz

这里下载的是目前最新的php版本, 2020-06-21, 最新的版本是php7.4.7

解压文件

tar -zxvf php-7.4.7.tar.gz

cd php-7.4.7

预下载依赖

经过我一步步的试错之后, 总结了一些必要的依赖, 可以预先安装, 以节省大量的时间

yum -y install libxml2-devel openssl-devel sqlite-devel libcurl-devel libicu-devel gcc-c++ oniguruma oniguruma-devel libxslt-devel libpng-devel libjpeg-devel freetype-devel

这里不能保证还会不会有其他的依赖需要安装, 但是上面这些也可以减少大量的时间了

配置

将下面的代码粘贴到终端执行,

这段配置项经过我的反复修复, configure完成之后应该不会再出现

configure: WARNING: unrecognized options: 这种警告了, 并且兼容了laravel所需的依赖

./configure \

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

--enable-mysqlnd \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--enable-pdo \

--with-iconv-dir \

--with-freetype \

--with-jpeg \

--with-zlib \

--enable-xml \

--enable-session \

--disable-rpath \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--enable-mbregex \

--enable-mbstring \

--enable-intl \

--enable-pcntl \

--enable-bcmath \

--enable-ftp \

--enable-gd \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--with-zip \

--enable-soap \

--with-gettext \

--disable-fileinfo \

--enable-opcache \

--enable-maintainer-zts \

--with-xsl \

--enable-tokenizer \

--enable-fpm

pbp7.4已弃用的配置项

下面这些选项已经无效了, 注意配置的时候不需要加上了

configure: WARNING: unrecognized options:

--with-libxml-dir,

--with-pcre-regex,

--with-pcre-dir,

--with-gd, 应该使用 --enable-gd

--with-jpeg-dir, 应该使用 --with-jpeg

--with-png-dir,

--with-freetype-dir, 应该使用 --with-freetype

--enable-mbregex-backtrack,

--with-onig,

--enable-wddx,

--with-libxml-dir,

--enable-zip 应该使用 --with-zip

如果没有错误最好, 如果有错误, 可以参考下面部分

可能出现的错误

No package 'libxml-2.0' found

configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:

No package 'libxml-2.0' found

解决方法

yum install libxml2-devel

中途可能需要更新其他的依赖, 确定就可以了

No package 'openssl' found

configure: error: Package requirements (openssl >= 1.0.1) were not met:

No package 'openssl' found

解决方法

yum install openssl-devel

No package 'sqlite3' found

configure: error: Package requirements (sqlite3 > 3.7.4) were not met:

No package 'sqlite3' found

解决方法

yum install sqlite-devel

No package 'libcurl' found

configure: error: Package requirements (libcurl >= 7.15.5) were not met:

No package 'libcurl' found

解决方法

yum install libcurl-devel

Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met

configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:

No package 'icu-uc' found

No package 'icu-io' found

No package 'icu-i18n' found

解决方法

yum install libicu-devel

configure: error: C++ preprocessor "/lib/cpp" fails sanity check

checking whether g++ accepts -g... no

checking how to run the C++ preprocessor... /lib/cpp

configure: error: in `/data/programs/php-7.4.7':

configure: error: C++ preprocessor "/lib/cpp" fails sanity check

See `config.log' for more details

解决方法, 缺少g++库, 安装

yum install gcc-c++

No package 'oniguruma' found

configure: error: Package requirements (oniguruma) were not met:

No package 'oniguruma' found

如果启用了--with-mbstring,则需要安装 oniguruma, 因为7.4的正则表达式使用了oniguruma

解决方法

yum install oniguruma oniguruma-devel

No package 'libxslt' found

configure: error: Package requirements (libxslt >= 1.1.0) were not met:

No package 'libxslt' found

--with-xsl 打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件

解决方法

yum install libxslt-devel

No package 'libpng' found

configure: error: Package requirements (libpng) were not met:

No package 'libpng' found

解决方法

yum install libpng-devel

No package 'libjpeg' found

configure: error: Package requirements (libjpeg) were not met:

No package 'libjpeg' found

解决方法

yum install libjpeg-devel

No package 'freetype2' found

configure: error: Package requirements (freetype2) were not met:

No package 'freetype2' found

解决方法

yum install freetype-devel

No package 'libzip' found

configure: error: Package requirements (libzip >= 0.11) were not met:

No package 'libzip' found

解决方法

这里不使用软件仓库中的libzip, 也就是不使用yum install libzip-devel,

因为版本不够, 安装方法看下面一条

Requested 'libzip >= 0.11' but version of libzip is 0.10.1

这是因为软件仓库的libzip版本过低, 需要手动编译安装

# 先删除原有的libzip

yum remove -y libzip

# 下载并手动编译安装, 自己下载到合适的位置

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

# 更新依赖路径, centos版本小于8的,一定要执行下面这个命令,不然还是找不到 libzip

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"

# 上面一行的代码参考自 https://wujie.me/centos7-3-compile-and-install-php-7-4-1/

配置完成

出现下面的提示就代表已经配置成功了, 可以进行编译安装了

+--------------------------------------------------------------------+

| License: |

| This software is subject to the PHP License, available in this |

| distribution in the file LICENSE. By continuing this installation |

| process, you are bound by the terms of this license agreement. |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point. |

+--------------------------------------------------------------------+

Thank you for using PHP.

编译安装

没啥好说的, make 就行了

make && make install

在我的破机器上足足编译了7分钟, 还好, 没出啥问题, 编译并安装成功了

invertedregexiterator.inc

pharcommand.inc

clicommand.inc

directorytreeiterator.inc

directorygraphiterator.inc

phar.inc

Build complete.

Don't forget to run 'make test'.

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20190902/

Installing PHP CLI binary: /usr/local/php/bin/

Installing PHP CLI man page: /usr/local/php/php/man/man1/

Installing PHP FPM binary: /usr/local/php/sbin/

Installing PHP FPM defconfig: /usr/local/php/etc/

Installing PHP FPM man page: /usr/local/php/php/man/man8/

Installing PHP FPM status page: /usr/local/php/php/php/fpm/

Installing phpdbg binary: /usr/local/php/bin/

Installing phpdbg man page: /usr/local/php/php/man/man1/

Installing PHP CGI binary: /usr/local/php/bin/

Installing PHP CGI man page: /usr/local/php/php/man/man1/

Installing build environment: /usr/local/php/lib/php/build/

Installing header files: /usr/local/php/include/php/

Installing helper programs: /usr/local/php/bin/

让我们不要忘了运行一下make test, 那就跑一下吧

后悔了, 应该先测试一下php命令的, 因为这个`test又花费了七八分钟, 要测试1.4万+个文件..

不过一路PASS, 挺好, 虽然结束后发了封邮件

测试php命令

是时候亮相一下php命令了,

如果忘了了php的安装目录, 使用whereis 找一下

whereis php

php: /usr/local/php

# 成功安装

/usr/local/php/bin/php -v

PHP 7.4.7 (cli) (built: Jun 21 2020 18:19:20) ( ZTS )

Copyright (c) The PHP Group

Zend Engine v3.4.0, Copyright (c) Zend Technologies

# 来看一下安装的模块

/usr/local/php/bin/php -m

[PHP Modules]

bcmath

Core

ctype

curl

date

dom

filter

ftp

gd

gettext

hash

iconv

intl

json

libxml

mbstring

mysqli

mysqlnd

openssl

pcntl

pcre

PDO

pdo_mysql

pdo_sqlite

Phar

posix

Reflection

session

shmop

SimpleXML

soap

sockets

SPL

sqlite3

standard

sysvsem

tokenizer

xml

xmlreader

xmlrpc

xmlwriter

xsl

zip

zlib

[Zend Modules]

将php命令复制到/usr/bin

cp /usr/local/php/bin/php /usr/bin/

# 现在就可以直接使用php命令了, 方便

php -v

配置php.ini

查看默认的php.ini文件的位置

php -i | grep php.ini

Configuration File (php.ini) Path => /usr/local/php/etc

显示在 /usr/local/php/etc这个文件夹下面, 我们去看一下

cd /usr/local/php/etc

ll

php-fpm.conf.default

php-fpm.d/

可以发现就两个文件, 其中并没有php.ini这个文件

这个时候我们就可以从php的源码中将php.ini复制一份即可

cp /data/programs/php-7.4.7/php.ini-development /usr/local/php/etc/php.ini

修改时区

编辑php.ini文件, 找到;date.timezone, 修改为:

date.timezone = Asia/Shanghai

配置php-fpm

先运行一下php-fpm

/usr/local/php/sbin/php-fpm

ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)

ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'

得到了两行报错, 原因是我们还没有配置php-fpm.conf

现在到 /usr/local/php/etc目录下将php-fpm.conf.default拷贝一份并重命名为php-fpm.conf

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

修改php-fpm监听的端口号

如果需要修改php-fpm监听的端口号, 那么不能直接在php-fpm.conf中进行修改, 也没有地方可以改

而应该在/usr/local/php/etc/php-fpm.d/ 下面的*.conf中进行修改, 仔细看php-fpm.conf文件

可以看到, 在最下面一行引入了php-fpm.d下面的所有的.conf文件

include=/usr/local/php/etc/php-fpm.d/*.conf

默认php已经带了一个www.conf.default 文件

将这个文件复制一份为www.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

编辑www.conf, 找到listen = 127.0.0.1:9000 这一段, 修改对应的监听端口即可

设置php-fpm为开机启动

编辑php-fpm.conf文件, 将pid的注释打开

pid = run/php-fpm.pid

编辑/etc/rc.local文件, 加入php-fpm的配置

/usr/local/php/sbin/php-fpm >/tmp/php-fpm.log 2>&1

至此, php7.4的安装就结束了, 感谢阅读

大功告成, 告辞

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值