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

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. java 全端开源 电商系统 springboot uniapp 小程序 前后端分离 高可用

    Lilishop B2B2C商城系统 官方公众号 & 开源不易,如有帮助请点Star 所有jar包均可从maven中央仓库下载,无二次封装jar包,全端开源,无后门,无监控. 介绍 官网:ht ...

  2. 编译原理-非确定有穷自动机(nondeterministic finite automata,NFA)

    是一个五元组,M=(S,∑,f,S0,F) S:有穷状态集 ∑:输入字母表(有穷) f:f(S,α)=S' 表示从一个状态S出发,识别了一个字α后,可以到达S'这个状态集合之间的某一个状态(可能的后继 ...

  3. 『动善时』JMeter基础 — 47、JMeter的HTTP代理服务器详细介绍

    目录 1.HTTP代理服务器的添加 2.HTTP代理服务器界面详解 (1)State:状态 (2)Global Settings:全局设置 (3)Test Plan Creation:测试计划创建 ( ...

  4. 为什么有些公司的IT很乱?

    --别问,问就是赛马,问就是KPI驱动 为什么很多公司甚至是闻名遐迩的资深IT公司,都被吐槽IT技术建设很烂呢?按惯例,问为什么之前,先问是不是. ▒壹·鹅厂▒ 2018年一个名为"当下腾讯 ...

  5. 【题解】coin HDU2884 多重背包

    题目 Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. 图解 Redis | 不多说了,这就是 RDB 快照

    大家好,我是小林. 虽说 Redis 是内存数据库. 但是它为数据的持久化提供了两个技术,分别是「 AOF 日志和 RDB 快照」. 这两种技术都会用各用一个日志文件来记录信息,但是记录的内容是不同的 ...

  7. 聊聊IOC中依赖注入那些事 (Dependency inject)

    What is Dependency injection 依赖注入定义为组件之间依赖关系由容器在运行期决定,形象的说即由容器动态的将某个依赖关系注入到组件之中在面向对象编程中,我们经常处理的问题就是解 ...

  8. 从零实操基于WSL2 Docker部署Asp.Net Core项目

    前言 平日在公司里都是基于阿里Teambition中的飞流进行Docker部署Api项目或服务,已经习惯了那一套成熟的操作流程,开发和部署确实快捷方便,但是还没在自己的电脑上进行操作过,特别是Wind ...

  9. Unity3D 本地数据持久化几种方式

    下面介绍几种 Unity本地记录存储的实现方式. 第一种 Unity自身提供的 PlayerPrefs //保存数据 PlayerPrefs.SetString("Name",mN ...

  10. Redis 雪崩、穿透、击穿、并发、缓存讲解以及解决方案

    1.缓存雪崩 数据未加载到缓存中,或者缓存同一时间大面积的失效,从而导致所有请求都去查数据库,导致数据库CPU和内存负载过高,甚至宕机. 比如一个雪崩的简单过程 1.redis集群大面积故障 2.缓存 ...