很多时候可能会遇到需要手动源码安装软件的时候,所以自己实践了一把,并且把安装过程中遇到的问题,以及在网上找到的解决办法(实测有效)都记录下来,方便日后学习实践。

1. 系统环境

# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
// 编译php之前需要有gcc和autoconfig环境
# yum install -y gcc-c++ gcc
# yum install autoconf

2. 新增用户和用户组

# groupadd www
# useradd -g www www

3. 下载php

# wget https://www.php.net/distributions/php-7.3.25.tar.gz
# tar -zxvf php-7.3.25.tar.gz
# cd php-7.3.25

  

4. 编译

--with-fpm-user=www --with-fpm-group=www
这里使用www www 用户、用户组,编译出来的程序启动,就是归属这个用户、用户组

./configure --prefix=/usr/local/php
--with-fpm-user=www
--with-fpm-group=www
--with-curl
--with-freetype-dir
--with-gd
--with-gettext
--with-iconv-dir
--with-kerberos
--with-libdir=lib64
--with-libxml-dir
--with-mysqli
--with-openssl
--with-pcre-regex
--with-pdo-mysql
--with-pdo-sqlite
--with-pear
--with-png-dir
--with-jpeg-dir
--with-xmlrpc
--with-xsl
--with-zlib
--with-bz2
--with-mhash
--enable-fpm
--enable-bcmath
--enable-libxml
--enable-inline-optimization
--enable-mbregex
--enable-mbstring
--enable-opcache
--enable-pcntl
--enable-shmop
--enable-soap
--enable-sockets
--enable-sysvsem
--enable-sysvshm
--enable-xml
--enable-zip
--enable-fpm

 

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

off_t undefined 报错

checking for zip_file_set_encryption in -lzip... yes
checking for zip_libzip_version in -lzip... no
checking stdbool.h usability... yes
checking stdbool.h presence... yes
checking for stdbool.h... yes
checking fts.h usability... yes
checking fts.h presence... yes
checking for fts.h... yes
checking for int8_t... (cached) yes
checking for int16_t... (cached) yes
checking for int32_t... (cached) yes
checking for int64_t... (cached) yes
checking for uint8_t... (cached) yes
checking for uint16_t... (cached) yes
checking for uint32_t... (cached) yes
checking for uint64_t... (cached) yes
checking for ssize_t... yes
checking size of short... (cached) 2
checking size of int... (cached) 4
checking size of long... (cached) 8
checking size of long long... (cached) 8
checking size of off_t... 0
configure: error: off_t undefined; check your library configuration

off_t 类型是在 头文件 unistd.h中定义的,
在32位系统 编程成 long int ,64位系统则编译成 long long int ,
在进行编译的时候 是默认查找64位的动态链接库,
但是默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,
这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。#添加搜索路径到配置文件

echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf

#如下操作与上面等效
vim /etc/ld.so.conf
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib /usr/lib64
#保存退出
:wq
ldconfig -v # 使之生效

#然后 更新配置
ldconfig -v
# 安装
make && make install

报错  usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

configure过后,make报错

/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory
#解决方法:手动复制过去
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

6.重新编译,成功输出

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/
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/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in phar:///home/flame/software/php-7.3.0/pear/install-pear-nozlib.phar/PEAR/PackageFile/v2/Validator.php on line 1933
[PEAR] Archive_Tar - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/home/flame/software/php-7.3.0/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/

7. 配置php.ini和php-fpm,建立目录

cp php.ini-production /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/sbin/php-fpm /usr/local/bin

cd /usr/local/php/etc/php-fpm.d
vim www.conf

输入

[www]
listen = 127.0.0.1:9000
listen.mode = 0666 user = www #php代码目录权限 需要跟这个一致,
group = www #php代码目录权限 需要跟这个一致 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

编辑php.ini替换换 ;cgi.fix_pathinfo=1 为 cgi.fix_pathinfo=0 快捷命令:

8. 加入 systemtl 服务

cd /home/flame/software/php-7.3.25/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/

启动php-ftpm

systemctl start php-fpm

#查看状态

systemctl status php-fpm

#得到输出
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2018-12-27 16:13:16 CST; 2s ago
Main PID: 16835 (php-fpm)
CGroup: /system.slice/php-fpm.service
├─16835 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
├─16836 php-fpm: pool www
├─16837 php-fpm: pool www
├─16838 php-fpm: pool www
├─16839 php-fpm: pool www
├─16840 php-fpm: pool www
├─16841 php-fpm: pool www
├─16842 php-fpm: pool www
├─16843 php-fpm: pool www
├─16844 php-fpm: pool www
├─16845 php-fpm: pool www
├─16846 php-fpm: pool www
├─16847 php-fpm: pool www
├─16848 php-fpm: pool www
├─16849 php-fpm: pool www
├─16850 php-fpm: pool www
├─16851 php-fpm: pool www
├─16852 php-fpm: pool www
├─16853 php-fpm: pool www
├─16854 php-fpm: pool www
└─16855 php-fpm: pool www Dec 27 16:13:16 iZj6cas4fyg41lxhngh1z0Z systemd[1]: Started The PHP FastCGI Process Manager.

9. php命令环境

在$HOME/.profile里新增内容为

export PATH=$PATH:/usr/local/php/bin

centos7 源码安装指定版本的php7的更多相关文章

  1. centos7源码安装Python3的前提条件

    centos7源码安装Python3的前提条件: # yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline- ...

  2. CentOS7源码安装qbittorrent最新版本

    CentOS的软件 yum 里 yum search qbittorrent yum info qbittorrent 找到的是3.37版本 官网最新的是4.12版本.但需要源码安装: 官网下载最新版 ...

  3. centos7源码安装mysql5.7.19

    centos7源码包安装mysql5.7 5.7.20安装方法和5.7.19的一样. 1.安装前准备 清空环境.安装相应的软件包 1>关闭防火墙和SELinux 2>配置yum源(阿里云, ...

  4. Centos7源码安装mysql及读写分离,互为主从

       Linux服务器 -源码安装mysql 及读写分离,互为主从   一.环境介绍: Linux版本: CentOS 7 64位 mysq版本: mysql-5.6.26 这是我安装时所使用的版本, ...

  5. CentOS7 源码安装 PostgreSQL 12

    PostgreSQL 12 源码安装 Table of Contents 1. 下载 2. 准备环境 3. 编译安装 4. 设置环境变量 5. 初始化数据库 6. 配置参数文件 6.1. postgr ...

  6. Centos7源码安装Apache和PHP

    源码安装Apache 安装需要的依赖 yum -y install gcc autoconf automake make pcre pcre-devel openssl openssl-devel​# ...

  7. CentOS7源码安装Redis5.0.4非关系型数据库

    源码安装redis-5.0.4 一. 下载redis 1. 需要连接网络 二. 案例(另一种安装方法) [root@localhost ~]# wget http://download.redis.i ...

  8. centos7源码安装Apache及Tomcat

    源码安装Apache (1) 一.通过 https://apr.apache.org/  下载 APR 和 APR-util 通过 http://httpd.apache.org/download.c ...

  9. centos7 源码安装goaccess

    1. 使用yum安装在不同服务器上可能失败, 推荐使用源码安装goaccess # 安装依赖 yum install -y ncurses-devel GeoIP-devel.x86_64 tokyo ...

随机推荐

  1. python_selenium 之yaml文件读取(以读取元素信息为例)

    一.yaml源文件编写 二.对yaml文件内容的读取 #coding=gbkimport osimport yamlcurrent_path=os.path.dirname(__file__)yaml ...

  2. Spring Cloud系列(四):断路器Hystrix

    上一篇介绍了负载均衡的配置方法,做负载均衡是为了保证高可用性,但是有时候服务提供者挂掉了,比如服务A调用了服务B,服务B又调用了服务C,然后有一天服务C的所有节点都挂掉了,这时服务B就会因为C异常而在 ...

  3. Class.forName()、Class.forName().newInstance() 、New 三者区别!

    终于明白为什么加载数据库驱动只用Class.forName()了!!困扰了我2个小时!!希望我写的这个东西对各位有所帮助.      在Java开发特别是数据库开发中,经常会用到Class.forNa ...

  4. jquery给动态生成的元素绑定事件,on函数

    首先先解释一下什么是动态生成的元素:动态生成的元素即我们用jquery的内部插入函数append()所生成的html代码.相对的也有静态生成的元素:即直接编写在页面的html代码. 下面通过例子来讲解 ...

  5. Docker与k8s的恩怨情仇(一)—成为PaaS前浪的Cloud Foundry

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 大家在工作中或许或多或少都接触过Docker,那你知道Docker以及容器化背后的原理到底是什么吗? 容器化 ...

  6. huge page 能给MySQL 带来性能提升吗?

    最近一直在做性能压测相关的事情,有公众号的读者朋友咨询有赞的数据库服务器有没有开启huge page,我听说过huge page会对性能有所提升,本文就一探究竟.对过程没有兴趣的可以直接看结论. 二 ...

  7. 「模拟8.17」star way to heaven(并查集,最小生成树)

    80分打法 首先二分最后答案,答案即为r,可看作以每个k为圆心r为半径的圆 我们进行并查集维护,维护相交的圆的边界 最后判断是否存在圆将上下边界覆盖,如有证明不行 1 #include<iost ...

  8. 有模有样解决Flutter里Webview无法访问HTTP页面的问题

    探索过程 Android9(好像是吧)开始谷歌就默认不让开发者访问不安全HTTP内容了,如果非要用HTTP,那必须在networkSecurityConfig里配置cleartextTrafficPe ...

  9. Spring Boot动态权限变更实现的整体方案

    1.前言 ​ 在Web项目中,权限管理即权限访问控制为网站访问安全提供了保障,并且很多项目使用了Session作为缓存,结合AOP技术进行token认证和权限控制.权限控制流程大致如下图所示: ​ 现 ...

  10. 20201123 实验一《Python程序设计》实验报告

    20201123 2020-2021-2 <Python程序设计>实验一报告 课程:<Python程序设计> 班级:2011班 姓名:晏鹏捷 学号:20201123 实验教师: ...