centos7 源码编译安装php7.3.25
1. 系统环境
# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
// 编译php之前需要有gcc和autoconfig环境
# yum install -y gcc-c++ gcc# yum install autoconf# groupadd www
# useradd -g www www# wget https://www.php.net/distributions/php-7.3.25.tar.gz
# wget https://www.php.net/distributions/php-7.4.33.tar.gz # tar -zxvf php-7.3.25.tar.gz # cd php-7.3.25
--with-fpm-user=www --with-fpm-group=www
这里使用www www 用户、用户组,编译出来的程序启动,就是归属这个用户、用户组5. 编译错误时,解决依赖
configure: error: libxml2 not found. Please check your libxml2 installation.
yum install -y libxml2-devel
configure: error: Please reinstall the BZip2 distribution
yum install -y bzip2-devel
configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
yum install -y curl-devel
configure: error: jpeglib.h not found.
yum install -y libjpeg-devel
configure: error: png.h not found.
yum install -y libpng-devel
configure: error: freetype-config not found.
yum install -y freetype-devel
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install -y libxslt-devel
configure: error: Please reinstall the libzip distribution
yum install -y libzip-devel
checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
#先删除旧版本 # 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
装完了之后找一下/usr/local/lib下有没有pkgconfig目录,有的话执行命令export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"指定PKG_CONFIG_PATH。
6.重新编译,make && make install 成功输出
# /usr/local/php/bin/php -v
PHP 7.3.25 (cli) (built: Nov 8 2024 14:14:26) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.25, Copyright (c) 1998-2018 Zend Technologies
7. 添加环境变量
一次性的设置,只对当前会话有效,当注销时,刚刚设置的PATH就会失效
# export PATH=$PATH:/usr/local/php/bin
永久性设置,对所有用户有效,需要重启生效或使用source命令,将上一种方式的导出操作添加到文件/etc/profile的末尾。
[root@localhost php-7.3.25]# vim /etc/profile #添加如下内容 # export PATH=$PATH:/usr/local/php/bin [root@localhost php-7.3.25]# source /etc/profile
永久性设置,只针对一个用户,需要重启生效或使用source命令,优先级高于2,将方式1的导出操作添加到文件 ~/.bashrc的末尾。
8. 配置文件
[root@cloudhost php-7.3.25]# cp php.ini-development /usr/local/php/etc/php.ini [root@cloudhost php-7.3.25]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@cloudhost php-7.3.25]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
9. 注册系统服务
当php编译安装完成后,php-fpm还不是系统服务。为了方便使用,将其注册为系统服务。
找到 init.d.php-fpm
# find / -name init.d.php-fpm
/opt/php-7.3.25/sapi/fpm/init.d.php-fpm
将它拷贝到/etc/init.d目录下
# cp /opt/php-7.3.25/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
修改权限
[root@localhost ~]# chmod 755 /etc/init.d/php-fpm 或者 [root@localhost ~]# chmod +x /etc/init.d/php-fpm
php-fpm基本操作
/etc/init.d/php-fpm start
或者
service php-fpm start
service php-fpm status
service php-fpm stop
Usage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload|status|configtest}
浙公网安备 33010602011771号