源码安装PHP

一、下载安装包并解压
官网地址:https://www.php.net/downloads.php

从官网上下载了一个php-7.4.19

[root@localhost ~]# tar -xzvf php-7.4.19.tar.gz -C /usr/local/
二、安装依赖
[root@localhost ~]# yum -y install gcc libxml2 libxml2-devel bzip2 bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libc-client-devel libxslt-devel openssl sqlite-devel openssl-devel curl libicu libicu-devel gcc-c++

比较特殊的两个依赖

[root@localhost ~]# yum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.6-1.el7.remi.x86_64.rpm
[root@localhost ~]# yum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.6-1.el7.remi.x86_64.rpm
三、编译安装
安装(将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系)

[root@localhost php-7.4.19]# ./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-config-file-scan-dir=/usr/local/php/etc/php.d –with-fpm-user=www –with-fpm-group=www –enable-fpm –disable-fileinfo –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-bcmath –enable-shmop –enable-exif –enable-sysvsem –enable-inline-optimization –with-curl=/usr/local –enable-mbregex –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-xmlrpc –enable-ftp –enable-intl –with-xsl –with-gettext –enable-zip –enable-soap –disable-debug

[root@localhost php-7.4.19]# make && make install
成功会输出:Thank you for using PHP. 等字样

四、注释
–enable-fpm

–prefix=/usr/local/php //指定 php 安装目录
–with-apxs2=/usr/local/apache/bin/apxs //整合apache,apxs功能是使用mod_so中的LoadModule指令,加载指定模块到 apache,要求 apache 要打开SO模块
–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扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。
–with-pdo-mysql=mysqlnd
–enable-ftp //打开ftp的支持
–enable-zip //打开对zip的支持
–with-bz2 //打开对bz2文件的支持,bzip2 函数用于透明地读写 bzip2(.bz2)压缩文件。
–with-jpeg-dir //打开对jpeg的支持
–with-png-dir //打开对png的支持
–with-freetype-dir //打开对freetype字体库的支持
–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 //魔术头文件位置
五、配置
[root@localhost php-7.4.19]# cp php.ini-development /usr/local/php/php.ini
[root@localhost php-7.4.19]# cp sapi/fpm/php-fpm /usr/local/bin/
[root@localhost local]# cp -rp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
配置php.ini (修改php.ini需要重启 php-fpm)

六、设置启动脚本
复制php启动脚本到/etc/init.d/

[root@localhost local]# cp -rp /usr/local/php-7.4.19/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
添加执行权限,添加到启动项并设置开机自启动。

[root@localhost local]# chmod +x /etc/init.d/php-fpm

[root@localhost local]# chkconfig –add php-fpm

[root@localhost local]# chkconfig php-fpm on
七、配置环境变量
最后往 /etc/profile 追加 PHP 的 bin sbin 两个目录路

[root@localhost local]# vim /etc/profile
PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH
export PATH
source /etc/profile
八、启动php-fpm
[root@localhost php-fpm.d]# cp -rp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@localhost php-fpm.d]# useradd www
/etc/init.d/php-fpm start
九、查看 PHP 版本信息
[root@localhost php]# php -v
PHP 7.4.19 (cli) (built: May 25 2021 14:46:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
十、配置nginx
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
index.php 配置文件

[root@localhost html]# vim /usr/local/nginx/html/index.php

十一、启动nginx,访问网页

IT大爆炸公众号平台主要致力于为大家提供免费的学习资源,知识星球主要致力于即将入坑或者已经入坑的运维行业的小伙伴。提供一个交流、提升的平台,遇见更好的自己。

声明:文中观点不代表本站立场。本文传送门:http://eyangzhen.com/149709.html

(0)
联系我们
联系我们
分享本页
返回顶部