centos7 源码编译安装 php
准备工作
下载 PHP 源码包并解压
$ wget https://www.php.net/distributions/php-7.2.19.tar.bz2
$ yum -y install bzip2 # 如果有可以不用安装
$ tar -jxvf php-7.2.19.tar.bz2
进入 PHP 源码包目录
$ cd php-7.2.19
配置和构建 PHP
常用配置项及其说明 如果看着麻烦可以直接看下面的总结步骤
--prefix=/usr/local/php7 # 配置安装目录
--with-config-file-path=/usr/local/php7 # 配置文件 php.ini 的路径
--enable-sockets # 开启 socket
--enable-fpm # 启用 fpm 扩展
--enable-cli # 启用 命令行模式 (从 php 4.3.0 之后这个模块默认开启所以可以不用再加此命令)
--enable-mbstring # 启用 mbstring 库
--enable-pcntl # 启用 pcntl (仅 CLI / CGI)
--enable-soap # 启用 soap
--enable-opcache # 开启 opcache 缓存
--disable-fileinfo # 禁用 fileinfo (由于 5.3+ 之后已经不再持续维护了,但默认是开启的,所以还是禁止了吧)(1G以下内存服务器直接关了吧)
--disable-rpath #禁用在搜索路径中传递其他运行库。
--with-mysqli # 启用 mysqli 扩展
--with-pdo-mysql # 启用 pdo 扩展
--with-iconv-dir # 启用 XMLRPC-EPI 字符编码转换 扩展
--with-openssl # 启用 openssl 扩展 (需要 openssl openssl-devel)
--with-fpm-user=www #设定 fpm 所属的用户
--with-fpm-group=www #设定 fpm 所属的组别
--with-curl # 启用 curl 扩展
--with-mhash # 开启 mhash 基于离散数学原理的不可逆向的php加密方式扩展库
# GD
--with-gd # 启用 GD 图片操作 扩展
--with-jpeg-dir # 开启对 jpeg 图片的支持 (需要 libjpeg)
--with-png-dir # 开启对 png 图片支持 (需要 libpng)
--with-freetype-dir # 开启 freetype
# 压缩
--enable-zip # 启用 zip
--with-zlib # 启用对 zlib 支持
# xml
--enable-simplexml # 启用对 simplexml 支持
--with-libxml-dir # 启用对 libxml2 支持一些不常用的选项
--enable-debug 开启 debug 模式
执行 configure 配置 如果看着麻烦可以直接看下面的总结步骤
$ ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --enable-sockets --enable-fpm --enable-cli --enable-mbstring --enable-pcntl --enable-soap --enable-opcache --disable-fileinfo --disable-rpath --with-mysqli --with-pdo-mysql --with-iconv-dir --with-openssl --with-fpm-user=www --with-fpm-group=www --with-curl --with-mhash --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-zip --with-zlib --enable-simplexml --with-libxml-dir
=== 第 [1] 尝试 ===
...
configure: error: libxml2 not found. Please check your libxml2 installation.
# 安装 libxml2 库
$ yum -y install libxml2 libxml2-devel
=== 第 [2] 尝试 ===
...
configure: error: Cannot find OpenSSL\'s <evp.h>
# 安装 openssl 库
$ yum -y install openssl openssl-devel
=== 第 [3] 尝试 ===
...
checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support
# 安装 curl 库
$ yum -y install libcurl libcurl-devel
=== 第 [4] 尝试 ===
...
configure: error: jpeglib.h not found.
# 安装 libjpeg 顺便 把 libpng 也装上
$ yum -y install libjpeg libjpeg-devel libpng libpng-devel
=== 第 [5] 尝试 ===
...
configure: error: freetype-config not found.
# 安装 freetype 库
$ yum -y install freetype freetype-devel
=== 第 [6] 尝试 ===
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+ Thank you for using PHP.
...
# 成功
$ make && make install
安装总结
$ wget https://www.php.net/distributions/php-7.2.19.tar.bz2
$ yum -y install bzip2 # 如果有可以不用安装
$ tar -jxvf php-7.2.19.tar.bz2
$ cd php-7.2.19
$ yum -y install libxml2 libxml2-devel openssl openssl-devel libcurl libcurl-devel install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
# **此处的 —prefix 安装目录可以不和我一样**
$ ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --enable-sockets --enable-fpm --enable-cli --enable-mbstring --enable-pcntl --enable-soap --enable-opcache --disable-fileinfo --disable-rpath --with-mysqli --with-pdo-mysql --with-iconv-dir --with-openssl --with-fpm-user=www --with-fpm-group=www --with-curl --with-mhash --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-zip --with-zlib --enable-simplexml --with-libxml-dir
$ make && make install
配置 nginx 支持
$ cp php-7.2.19/php.ini-production /usr/local/php/php.ini # 复制 php.ini 文件到目录
$ vi /usr/local/nginx/conf/nginx.conf
...
http {
...
server {
...
# 把 [1] 换成 [2]
# 让 nginx 支持 php 文件
#[1]
location / {
root html;
index index.html index.htm;
}
#[2]
location / {
root html;
index index.php index.html index.htm;
}
...
# 把 [1] 换成 [2]
# 配置监听 php 端口
# 注意: 要把 /scripts 换成 $document_root
#[1]
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
#[2]
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
...
}
# 重启 php-fpm
$ pkill -9 php-fpm
$ /usr/local/php7/sbin/php-fpm
配置更简单的启动命令
# 复制启动脚本到 init.d 目录
$ cp php-7.2.19/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# 增加执行权限
$ chmod +x /etc/init.d/php-fpm
# 配置 php-fpm 文件
$ cd /usr/local/php7/etc/
$ cp php-fpm.conf.default php-fpm.conf
# 进入 php-fpm.conf , 并去除 pid = run/php-fpm.pid 的注释
$ vim php-fpm.conf
===
...
[global]
; Pid file
; Note: the default prefix is /usr/local/php7/var
; Default Value: none
# 取消下面的注释
pid = run/php-fpm.pid
...
===
# 复制 www.conf 文件
$ cp php-fpm.d/www.conf.default php-fpm.d/www.conf
# 重启 php 服务器
$ pkill -9 php-fpm
$ /usr/local/nginx/php7/sbin/php-fpm
# 测试
$ /etc/init.d/php-fpm stop # 停止服务
Gracefully shutting down php-fpm . done
$ /etc/init.d/php-fpm start # 启动服务
Starting php-fpm done
$ /etc/init.d/php-fpm restart # 重启服务
Gracefully shutting down php-fpm . done
Starting php-fpm done
- /etc/init.d/php-fpm stop # 停止服务
- /etc/init.d/php-fpm start # 启动服务
- /etc/init.d/php-fpm restart # 重启服务
CentOS 7 配置自启动
# 启动(因为上面已经配置好启动脚本了,并且放到了 /etc/init.d 中所以下面命令是可以用的)
# 在 centos7 中 systemctl 是找 /etc/init.d 中的脚本
$ systemctl start php-fpm # 启动
$ systemctl enable php-fpm # 自启动
php-fpm.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig php-fpm on # 这里他提示我 php-fpm 并不是系统服务所以不能使用 systemctl 推荐我使用 /sbin/chkconfig php-fpm on 来实现自启动
$ /sbin/chkconfig php-fpm on 再次重启即可完成自启动
# 注: 如果不想配置 php-fpm 服务器化到此已经可以结束了,如果想看服务化可以看以下操作
Centos 7 服务化 php-fpm
# 在 centos 7 之后我们可以使用 systemctl 更好的管理系统服务
# 所以我们也要让 php-fpm 支持
# 因为 php 7.2 源码包里面含有 systemctl 所需要的脚本文件
# 我们只要复制过去即可,我们来开始配置
# 进入下载的 php源码包
$ cd php-7.2.19/sapi/fpm
# 复制其中的 php-fpm.service 到 /usr/lib/systemd/system/
$ cp php-fpm.service /usr/lib/systemd/system/
# 再次使用 systemctl enable php-fpm 进行配置自启动
$ systemctl enable php-fpm
# 重启测试一下看看自己服务器的 php-fpm 是否成功运行
- systemctl enable xxxxxx # 配置自启动
- systemctl stop xxxxx # 停止服务
- systemctl start xxxx # 开启服务
- systemctl status xxxx # 查看状态
centos7 源码编译安装 php的更多相关文章
- Centos7源码编译安装PHP7.2(生产环境)
安装PHP依赖包,否则在编译的过程中可能会出现各种报错 # Centos 安装epel-release源并将系统包更新到最新版本 $ yum install epel-release-y $ yum ...
- centos7源码编译安装lamp/lnmp
centos7源码编译安装lamp/lnmp 进程:是包工头(相当于是个门,只管开门关门,不管门内的事儿) 线程:是各种工种(cpu调度的是线程) 进程 是一件事情, 线程 是 同一个时间范围内 同时 ...
- centos7 源码编译安装TensorFlow CPU 版本
一.前言 我们都知道,普通使用pip安装的TensorFlow是万金油版本,当你运行的时候,会提示你不是当前电脑中最优的版本,特别是CPU版本,没有使用指令集优化会让TensorFlow用起来更慢. ...
- Centos7源码编译安装mysql8
前面介绍了很多关于mysql的文章,下面主要介绍一下mysql8的源码编译安装 一 基本环境 [root@CentOS-7-x86-64-Minimal-1810 ~]# cd /usr/local/ ...
- CentOS7 源码编译安装Nginx
源码编译安装nginx 1.下载nginx源码包(这里以nginx-1.18.0为例) wget http://nginx.org/download/nginx-1.18.0.tar.gz 2 ...
- centos7源码编译安装Subversion 1.9.5
svn是Subversion的简称,是一个开放源代码的版本控制系统.svn有两种运行方式:1.独立服务器(svn://xxx.xxx/xxx) 2.借助apache(http://svn.xxx.xx ...
- centos7 源码编译安装 nginx
安装步骤 下载 nginx 源码包 官网 $ wget http://nginx.org/download/nginx-1.16.0.tar.gz 解压 nginx 压缩包 $ tar -zxvf n ...
- CentOS7 源码编译安装Tengine
简介 Tengine是由淘宝网发起的Web服务器项目.它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性.它的目的是打造一个高效.安全的Web平台. 发展 Tengine的性能和 ...
- CentOS7源码编译安装Postgresql9.5
1.安装必要的基本软件 yum install -y gcc.x86_64 glibc.x86_64 glibc-devel.x86_64 vim-enhanced.x86_64 gcc-java a ...
随机推荐
- 计算机网络(十二),Socket简介
目录 1.Socket简介 2.Socket工作原理 十二.Socket简介 1.Socket简介 2.Socket工作原理
- C语言 - strcat和strncat的编程实现及总结
一.函数strcat与stcncat的函数实现 1.strcat函数的实现 要求: 原型:char * strcat(char *dest, const char *src); 头文件:#inc ...
- 如何在IntelliJ Idea中同时启动不同端口
配置多实例: 选择Idea右上角启动按钮边上的Edit Configurations,在打开的对话框中,去掉Single Instance Only的选项,VM Options中增加-Dserver. ...
- AcWing:105. 七夕祭(前缀和 + 中位数 + 分治 + 贪心)
七夕节因牛郎织女的传说而被扣上了「情人节」的帽子. 于是TYVJ今年举办了一次线下七夕祭. Vani同学今年成功邀请到了cl同学陪他来共度七夕,于是他们决定去TYVJ七夕祭游玩. TYVJ七夕祭和11 ...
- HBase2.0新特性解析
作者 | 个推大数据运维工程师 行者 升级背景 个推作为专业的数据智能服务商,在业务开展过程中存在海量的数据存储与查询的需求,为此个推选用了高可靠.高性能.面向列.可伸缩的分布式数据存储系统--HBa ...
- TCP之LAST_ACK状态
前提: A:主动关闭: B:被动关闭: A执行主动关闭,发送FIN,B收到FIN,发送ACK,进入CLOSE_WAIT,B发送FIN,进入LAST_ACK等待最后一个ACK到来: 关闭方式: (1) ...
- 字符串 kotlin(6)
字符串用 String 类型表示.字符串是不可变的. 字符串的元素——字符可以使用索引运算符访问: s[i] . 可以用 for 循环迭代字符串: for (c in str) { println(c ...
- Singletom 单例
class Singletom { //最差写法.构造方法是public的,有可能会被new出多个,那就不是单例了. public Singletom(){ } public static Singl ...
- C#连接Oracle数据库的四种方法
C#连接数据库的四种方法 在进行以下连接数据库之前,请先在本地安装好Oracle Client,同时本次测试System.Data的版本为:2.0.0.0. 在安装Oracle Client上请注意, ...
- 【汇总】PHP 伪协议 利用
日期:2019-07-28 21:24:36 更新: 作者:Bay0net 介绍: 0x01.基本信息 文件包含函数 include() require() include_once() requir ...