centos8以源码方式安装php7.4
source link: https://www.daozhao.com/10253.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
centos8以源码方式安装php7.4
centos8以源码方式安装php7.4
学习学习源码安装挺好的。
本文主要参考、学习自https://www.cnblogs.com/alliancehacker/p/12255445.html 感谢原作者
地址 https://www.php.net/distributions/php-7.4.13.tar.bz2
# 下载
wget https://www.php.net/distributions/php-7.4.13.tar.bz2 --no-check-certificate
# 解压
tar --bzip -xvf ./php-7.4.13.tar.bz2
# 剪切至通用位置
mv php-7.4.13.tar.bz2 /usr/local/php
安装编译工具
yum -y install gcc gcc-c++
yum -y install libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel libicu-devel freetype-devel openldap-devel openldap openldap-devel
创建用户组
方便和nginx使用
groupadd nginx
useradd -g nginx nginx
编译参数含义(可选)
可以参考文末的附录
执行编译参数
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-mcrypt --with-libmbfl --enable-ftp --with-gd --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm
换行就是下面这样的,效果等价
./configure --prefix=/usr/local/php \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm
执行上述命令会检查依赖项
一般都会有依赖性缺失的问题,不想每次检查的话,可以依次将下面的问题清理完,再支持configue操作
报错一
安装sqlite3这个包就好
yum install sqlite-devel
报错二
没有找到这个文件夹,我们就给它一个,将对应的东西复制进去
cp -frp /usr/lib64/libldap* /usr/lib/
报错三
安装oniguruma这个包,这个就有点烦人,这个我是参考https://blog.csdn.net/qq_17631419/article/details/106803807 感谢原作者 centos7
sudo yum install oniguruma-devel
centos8
# 下载
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -zxf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4
# 编译安装
./autogen.sh && ./configure --prefix=/usr
make && make install
再次尝试编译
cd /usr/local/php
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-mcrypt --with-libmbfl --enable-ftp --with-gd --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm
出现这个就稳了
make && make install (耗时较长)
出现这个就算大功告成了
映射全局命令
ln -s /usr/local/php/sbin/* /usr/local/sbin/
ln -s /usr/local/php/bin/* /usr/local/bin/
删除php7.4.*
rm -rf /usr/local/php /bin/php /usr/local/sbin/php-fpm /usr/local/bin/php /usr/local/bin/pear /usr/local/bin/peardev /usr/local/bin/pecl /usr/local/bin/phar /usr/local/bin/phar.phar /usr/local/bin/php-cgi /usr/local/bin/php-config /usr/local/bin/phpdbg /usr/local/bin/phpize
安装成功后的配置
php.ini
php.ini文件位于 /usr/local/php/lib或者/usr/local/php 如果不存在则使用/usr/local/php/php-production.ini复制一个后更改 上调上传文件大小大小上限
upload_max_size = 128M
php-fpm
php-fpm位于/usr/local/php/etc/下 创建php-fpm.conf
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
编辑 php-fpm.conf 放开pid
[global]
; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
pid = run/php-fpm.pid
根据注释可以看出此时pid的绝对路径是/usr/local/php/var/run/php-fpm.pid
,后面配合systemctl
需要用到
放开log
; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; into a local file.
; Note: the default prefix is /usr/local/php/var
; Default Value: log/php-fpm.log
error_log = log/php-fpm.log
修改www.conf
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
vi www.conf
检查user和group是不是nginx
; Start a new pool named 'nginx'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www]
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = nginx
group = nginx
更改监听方式为sock
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /usr/local/php/var/run/www.sock
listen.mode = 0660
使用systemctl管理php-fpm
vi /usr/lib/systemd/system/php-fpm.service
在里面写入下列内容,注意pid路径的正确性
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载systemctll配置
systemctl daemon-reload
设置开机启动
systemctl enable php-fpm
状态管理指令
systemctl start php-fpm
systemctl status php-fpm
systemctl stop php-fpm
systemctl restart php-fpm
systemctl enable php-fpm
systemctl didable php-fpm
附录:编译参数含义
想直接撸可以跳过进入下一步
./configure
–prefix=/usr/local/php php安装目录
–with-apxs2=/usr/local/apache/bin/apxs
–with-config-file-path=/usr/local/php/etc 指定php.ini位置
–with-MySQL=/usr/local/mysql mysql安装目录,对mysql的支持
–with-mysqli=/usr/local/mysql/bin/mysql_config mysqli文件目录,优化支持
–enable-safe-mode 打开安全模式
–enable-ftp 打开ftp的支持
–enable-zip 打开对zip的支持
–with-bz2 打开对bz2文件的支持
–with-jpeg-dir 打开对jpeg图片的支持
–with-png-dir 打开对png图片的支持
–with-freetype-dir 打开对freetype字体库的支持
–without-iconv 关闭iconv函数,种字符集间的转换
–with-libxml-dir 打开libxml2库的支持
–with-xmlrpc 打开xml-rpc的C语言
–with-zlib-dir 打开zlib库的支持
–with-gd 打开gd库的支持
–enable-gd-native-ttf 支持TrueType字符串函数库
–with-curl 打开curl浏览工具的支持
–with-curlwrappers 运用curl工具打开url流
–with-ttf 打开freetype1.*的支持,可以不加了
–with-xsl 打开XSLT文件支持,扩展了libxml2库 ,需要libxslt软件
–with-gettext 打开gnu的gettext 支持,编码库用到
–with-pear 打开pear命令的支持,php扩展用的
–enable-calendar 打开日历扩展功能
–enable-mbstring 多字节,字符串的支持
–enable-bcmath 打开图片大小调整,用到zabbix监控的时候用到了这个模块
–enable-sockets 打开sockets 支持
–enable-exif 图片的元数据支持
–enable-magic-quotes 魔术引用的支持
–disable-rpath 关闭额外的运行库文件
–disable-debug 关闭调试模式
–with-mime-magic=/usr/share/file/magic.mime 魔术头文件位置
cgi方式安装才用的参数
–enable-fpm 打上php-fpm补丁后才有这个参数,cgi方式安装的启动程序
–enable-fastcgi 支持fastcgi方式启动php
–enable-force-cgi-redirect 同上,帮助里没有解释
–with-ncurses 持ncurses屏幕绘制以及基于文本终端的图形互动功能的动态库
–enable-pcntl freeTDS需要用到的,可能是链接mssql才用到
mhash和mcrypt算法的扩展
–with-mcrypt 算法
–with-mhash 算法
–with-gmp
–enable-inline-optimization
–with-openssl openssl的支持,加密传输时用到的
–enable-dbase
–with-pcre-dir=/usr/local/bin/pcre-config perl的正则库案安装位置
–disable-dmalloc
–with-gdbm dba的gdbm支持
–enable-sigchild
–enable-sysvsem
–enable-sysvshm
–enable-zend-multibyte 支持zend的多字节
–enable-mbregex
–enable-wddx
–enable-shmop
–enable-soap
PHP配置选项完整列表 数据库选项
--with-dbplus 包括 dbplus 的支持。
--with-adabas[=DIR] 包括 Adabas D 的支持。DIR 是 Adabas 的基本安装目录,默认为 /usr/local。
--with-sapdb[=DIR] 包括 SAP DB 的支持。DIR 是 SAP DB 的基本安装目录,默认为 /usr/local。
--with-solid[=DIR] 包括 Solid 的支持。DIR 是 Solid 的基本安装目录,默认为 /usr/local/solid。
--with-ibm-db2[=DIR] 包括 IBM DB2 的支持。DIR 是 DB2 的基本安装目录,默认为 /home/db2inst1/sqllib。
--with-empress[=DIR] 包括 Empress 的支持。DIR 是 Empress 的基本安装目录,默认为 $EMPRESSPATH。自 PHP4起,本选项仅支持 Empress 8.60 及以上版本。
--with-empress-bcs[=DIR] 包括 Empress Local Access 的支持。DIR 是 Empress 的基本安装目录,默认为$EMPRESSPATH。自 PHP4 起,本选项仅支持 Empress 8.60 及以上版本。
--with-birdstep[=DIR] 包括 Birdstep 的支持。DIR 是 Birdstep 的基本安装目录,默认为/usr/local/birdstep。
--with-custom-odbc[=DIR] 包括用户自定义 ODBC 的支持。DIR 是 ODBC 的基本安装目录,默认为 /usr/local。要确认定义了CUSTOM_ODBC_LIBS 并且在 include 目录中有某个 odbc.h。例如,对于 QNX 下的 Sybase SQLAnywhere 5.5.00,在运行 configure 脚本之前应该先定义以下环境变量: CPPFLAGS="-DODBC_QNX-DSQLANY_BUG" LDFLAGS=-lunix CUSTOM_ODBC_LIBS="-ldblib-lodbc".
--with-iodbc[=DIR] 包括 iODBC 的支持。DIR 是 iODBC 的基本安装目录,默认为 /usr/local。
--with-esoob[=DIR] 包括 Easysoft OOB 的支持。DIR 是 OOB 的基本安装目录,默认为/usr/local/easysoft/oob/client。
--with-unixODBC[=DIR] 包括 unixODBC 的支持。DIR 是 unixODBC 的基本安装目录,默认为 /usr/local。
--with-openlink[=DIR] 包括 OpenLink ODBC 的支持。DIR 是 OpenLink 的基本安装目录,默认为 /usr/local。这和 iODBC一样。
--with-dbmaker[=DIR] 包括 DBMaker 的支持。DIR 是 DBMaker 的基本安装目录,默认为最新版 DBMaker 安装的目录(例如/home/dbmaker/3.6)。
--disable-unified-odbc 取消对 unified ODBC 的支持。仅适用于激活了 iODBC,Adabas,Solid,Velocis 或用户自定义 ODBC界面。仅能用于 PHP 3!
图像选项
--without-gd 禁用 GD 支持。仅用于 PHP 3!
--with-imagick Imagick 扩展被移到 PEAR 中的 PECL 中去了,可以在这里找到。PHP 4 中的安装指示可以在 PEAR站点中找到。只用 --with-imagick 仅在 PHP 3 中支持,除非依照 PEAR 站点的指示去做。
--with-ming[=DIR] 包括 ming 支持。
杂类选项
--enable-force-cgi-redirect 激活服务器内部重定向的安全检查。如果是在 Apache 中以 CGI 方式使用 PHP 则应该使用此选项。
--enable-discard-path 使用此选项可以使 PHP 的 CGI 可执行程序安全地放置在 web 目录树以外的地方,并且别人也不能绕过 .htaccess的安全设置。
--with-fastcgi 将 PHP 编译成 FastCGI 应用程序。
--enable-debug 编译时加入调试符号。
--with-layout=TYPE 设置安装后的文件布局。TYPE 可以是 PHP(默认值)或者 GNU。
--with-pear=DIR 将 PEAR 安装在 DIR 目录中(默认为 PREFIX/lib/php)。
--without-pear 不安装 PEAR。
--enable-sigchild 激活 PHP 自己的 SIGCHILD 句柄。
--disable-rpath 禁止传递附加的运行时库搜索路径。
--enable-libgcc 激活显式 libgcc 连接。
--enable-php-streams 包含试验的 PHP 流。除非是测试源代码,否则不要使用!
--with-zlib-dir=<DIR> 定义zlib 的安装路径。
--with-aspell[=DIR] 包含 ASPELL 支持。
--with-ccvs[=DIR] 包含 CCVS 支持。
--with-cybercash[=DIR] 包含 CyberCash 支持。DIR 是 CyberCash MCK 的安装目录。
--with-icap[=DIR] 包含 ICAP 支持。
--with-ircg-config ircg-config 脚本的路径。
--with-ircg 包含 ircg 支持。
--enable-mailparse 包含 mailparse 支持。
--with-muscat[=DIR] 包含 muscat 支持。
--with-satellite[=DIR] 激活通过 Satellite(试验性质)的 CORBA 支持。DIR 是 ORBit 的主目录。
--enable-trans-sid 激活透明的 session id 传播。
--with-regex[=TYPE] 使用系统 regex 库(不赞成)。
--with-vpopmail[=DIR] 包含 vpopmail 支持。
--with-tsrm-pthreads 使用 POSIX 线程(默认值)。
--enable-shared[=PKGS] 编译共享库 [default=yes]。
--enable-static[=PKGS] 编译静态库 [default=yes]。
--enable-fast-install[=PKGS] 为快速安装而优化 [default=yes]。
--with-gnu-ld 假定 C 编译器使用 GNU ld [default=no]。
--disable-libtool-lock 避免锁死(可能会破坏并行编译)。
--with-pic 尝试只使用 PIC/non-PIC 对象 [default=use both]。
--enable-memory-limit 编译时加入内存限制支持。
--disable-url-fopen-wrapper 禁止通过 URL 的 fopen wrapper,不能通过 HTTP 或 FTP 访问文件。
--enable-versioning 仅输出所需要的符号。更多信息见 INSTALL 文件。
--with-imsp[=DIR] 包含 IMSp 支持(DIR 是 IMSP 的 include 目录和 libimsp.a 目录)。仅用于 PHP 3!
--with-mck[=DIR] 包含 Cybercash MCK 支持。DIR 是 cybercash mck 编译目录,默认为/usr/src/mck-3.2.0.3-Linux。帮助见 extra/cyberlib。仅用于 PHP 3!
--with-mod-dav=DIR 包含通过 Apache 的 mod_dav 的 DAV 支持。DIR 是 mod_dav 的安装目录(仅用于 Apache模块版本!)仅用于 PHP 3!
--enable-debugger 编译入远程调试函数。仅用于 PHP 3!
--enable-versioning 利用 Solaris 2.x 和 Linux 提供的版本控制与作用范围的优势。仅用于 PHP 3!
PHP 选项
--enable-maintainer-mode 激活将编译规则和未使用的(以及一些混淆的)依赖文件放入临时安装中。
--with-config-file-path=PATH 设定php.ini 所在的路径,默认为PREFIX/lib。
--enable-safe-mode 默认激活安全模式。
--with-exec-dir[=DIR] 安全模式下只允许此目录下执行程序。默认为/usr/local/php/bin。
--enable-magic-quotes 默认激活 magic quotes。
--disable-short-tags 默认禁止简写的 PHP 开始标记 <?。
服务器选项
--with-aolserver=DIR 指定已安装的 AOLserver 的路径。
--with-apxs[=FILE] 编译共享 Apache 模块。FILE 是可选的 Apache 的 apxs 工具的路径,默认为 apxs。确保指定的 apxs版本是安装后的文件而不是 Apache 源程序中包中的。
--with-apache[=DIR] 编译Apache 模块。DIR是 Apache 源程序的最高一级目录。默认为/usr/local/apache。
--with-mod_charset 激活 mod_charset 中的传递表(Apache 中)。
--with-apxs2[=FILE] 编译共享的Apache 2.0 模块。FILE是可选的 Apache 的apxs 工具的路径,默认为apxs。
--with-fhttpd[=DIR] 编译 fhttpd 模块。DIR 是 fhttpd 的源代码路径,默认为 /usr/local/src/fhttpd。
--with-isapi=DIR 将 PHP 编译为 ISAPI 模块用于 Zeus。
--with-nsapi=DIR 指定已安装的 Netscape 服务器路径。
--with-phttpd=DIR
--with-pi3web=DIR 将 PHP 编译为用于 Pi3Web 的模块。
--with-roxen=DIR 将 PHP 编译为一个 Pike 模块。DIR 是 Roxen 的根目录,通常为/usr/local/roxen/server。
--enable-roxen-zts 编译 Roxen 模块,使用 Zend Thread Safety。
--with-servlet[=DIR] 包含 servlet 支持。DIR 是 JSDK 的基本安装目录。本 SAPI 需要 Java 扩展必须被编译为共享的dl。
--with-thttpd=SRCDIR 将 PHP 编译为 thttpd 模块。
--with-tux=MODULEDIR 将 PHP 编译为 TUX 模块(仅用于 Linux)。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK