安装依赖

yum install gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

在Ubuntu 18.04下, 需要额外补充的包有

sudo apt install libxml2-dev libcurl4 libcurl4-openssl-dev libjpeg-dev libgmp-dev libreadline-dev libxslt libxslt-dev libzip-dev

安装

开发环境(在Ubuntu下貌似无效)

    --enable-phpdbg\
--enable-dtrace\

生产环境:

    --disable-phpdbg\
--disable-dtrace\

执行configure

./configure \
--prefix=/opt/php/php7.2.10 \
--with-config-file-path=/opt/php/php7.2.10/etc \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir \
--enable-soap \
--enable-calendar \
--enable-pdo \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir \
--with-png-dir \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--disable-debug \
--enable-shared \
--enable-fileinfo \
--enable-filter \
--with-sqlite3 \
--with-libzip \
--with-iconv \
--with-cdb \
--enable-dom \
--with-gmp \
--enable-json \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache \
--enable-wddx \
--with-libmbfl \
--with-onig \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-xmlreader \
--enable-xmlwriter

遇到的问题的解决

1. 关于re2c和bison的warning, 通过安装解决

yum install re2c
yum install bison

2. 关于libzip的错误, 通过centos yum安装报版本太低, 需要编译安装

wget https://libzip.org/download/libzip-1.5.1.tar.gz
tar zxvf libzip-1.5..tar.gz
cd libzip-1.5.
more INSTALL.md
mkdir build
cd build/
cmake ..
make
make test
make install

3. 编译libzip时报centos7自带的cmake版本过低, 于是编译安装cmake

wget https://cmake.org/files/v3.12/cmake-3.12.2.tar.gz
tar zxvf cmake-3.12..tar.gz
cd cmake-3.12.
./bootstrap
gmake
gmake install
whereis cmake
cd /usr/bin/
ln -s /usr/local/bin/cmake cmake

4. 出现 configure: error: off_t undefined; check your library configuration 未定义的类型 off_t错误

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
# 更新配置
ldconfig -v

5. 在Ubuntu18.04下编译php5.6.38时, configure参数都和上面一样, 遇到两个问题: easy.h should be in <curl-dir>/include/curl/ 和 configure: error: Unable to locate gmp.h 都是因为在 /usr/include下无法找到对应的头文件, 并且在configure参数中通过 --with-gmp=/usr/include/x86_64-linux-gnu 指定无效, 在/usr/include/ 下 ln -s 才能通过. 在make时, 遇到了 openssl.c:1904:15: error: dereferencing pointer to incomplete type ‘X509_EXTENSION  , openssl.c:3485:14: error: dereferencing pointer to incomplete type ‘EVP_PKEY 这样的问题, 原因是 PHP 5.6 is receiving only security fixes and OpenSSL 1.1 is not supported. Please use PHP 7.x if you want to use OpenSSL 1.1. 在openssl1.1下就不要再用php5.6了.

执行 make, make test, make install 完成剩下的安装

配置PHP

配置php

源码包里面有配置文件, 按刚才configure里面设置的路径, 复制到 /opt/php/php7.2.10/etc
php.ini-development     测试开发环境
php.ini-production         生产环境

配置php-fpm

# 复制一份新的php-fpm配置文件
cd /opt/php/php7.2.10/etc
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
# 配置错误日志:
error_log = /var/log/php-fpm.log
# 配置pid文件:
pid = /var/run/php-fpm.pid
# 保存退出 cd /opt/php/php7.2.10/etc/php-fpm.d
cp www.conf.default www.conf

添加php-fpm到系统服务

# 到源代码目录下将样例文件复制到系统服务目录下, 注意, 在Ubuntu18.04中, 这个目录是 /lib/systemd/system/
cp ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/
# 配置开机启动php-fpm:
systemctl enable php-fpm
# 启动php-fpm (启动前先按下一步将用户和用户组创建好, 否则启动会失败)
systemctl start php-fpm
# 查看状态
systemctl status php-fpm

创建nginx用户

如果你在configure这一步指定的是其他的用户组和用户, 那么这里要把nginx替换掉

建立nginx 组
groupadd -r nginx
# -r 表示创建的是系统组
useradd -s /sbin/nologin -g nginx -r nginx
# -r 表示创建的是系统用户
id nginx

在Nginx中添加PHP支持

vi /opt/nginx/conf/nginx.conf

# 把前面的#注释符号去掉,把script改为$document_root最终如下:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
}

安装Swoole扩展

通过pecl安装

sudo pecl install swoole
# 根据自己系统带了哪些模块选择, 我的系统里缺少http2和postgresql, 所以这两个没选
enable sockets supports? [no] : yes
enable openssl support? [no] : yes
enable http2 support? [no] :
enable mysqlnd support? [no] : yes
enable postgresql coroutine client support? [no] :

然后根据提示, 在php.ini里添加相应的扩展

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
...
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop
extension=mongodb
extension=swoole

重启php-fpm后, 在phpinfo()里就能看到swoole的信息了.

Centos7.4和Ubuntu18.04安装PHP7.2的更多相关文章

  1. ubuntu18.04 安装 php7.2

    sudo apt-get install software-properties-common python-software-properties sudo add-apt-repository p ...

  2. Ubuntu18.04安装PHP7.3

    因为近期需要做毕业设计,需要用到Linux系统,在此分享一下在Linux-Ubuntu系统下安装PHP环境的一小点知识,如有偏差错误的,请各位学友多多指教哈! sudo apt-get install ...

  3. Ubuntu18.04安装Docker, centos7安装Docker

    Ubuntu18.04安装Docker 第一种方法从Ubuntu的仓库直接下载安装: 安装比较简单,这种安装的Docker不是最新版本,不过对于学习够用了,依次执行下面命令进行安装. $ sudo a ...

  4. Ubuntu18.04安装mysql5.7

    Ubuntu18.04安装mysql5.7 1.1安装 首先执行下面三条命令: # 安装mysql服务 sudo apt-get install mysql-server # 安装客户端 sudo a ...

  5. Ubuntu18.04安装RabbitMQ

    Ubuntu18.04安装RabbitMQ 2018年06月10日 19:32:38 dmfrm 阅读数:2492    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...

  6. ubuntu18.04 安装mysql不出现设置 root 帐户的密码问题(装)

    ubuntu18.04 安装mysql不出现设置 root 帐户的密码问题      https://blog.csdn.net/NeptuneClouds/article/details/80995 ...

  7. ubuntu18.04 安装hadoop 2.7.3+hive 2.3.4

    1. 安装hadoop 详细请参见本人的另外一片博文<Hadoop 2.7.3 分布式集群安装> 2. 下载hive 2.3.4 解压文件到/opt/software -bin.tar.g ...

  8. Ubuntu18.04安装Virtualenv虚拟环境

    在Ubuntu18.04安装Virtualenv虚拟环境 [实验环境]: 在这台电脑上已经安装了python3 [安装参考] 1.查看是否已安装virtualenv virtualenv --vers ...

  9. Ubuntu18.04安装thunderbird并设置中文

    Ubuntu18.04安装thunderbird并设置中文 安装thunderbird sudo apt-get install thunderbird 安装中文包 sudo apt-get inst ...

随机推荐

  1. DNS使用的是TCP协议还是UDP协议(转)

    原文链接:DNS使用的是TCP协议还是UDP协议 DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情 ...

  2. 京东的Netty实践,京麦TCP网关长连接容器架构

    背景 早期京麦搭建 HTTP 和 TCP 长连接功能主要用于消息通知的推送,并未应用于 API 网关.随着逐步对 NIO 的深入学习和对 Netty 框架的了解,以及对系统通信稳定能力越来越高的要求, ...

  3. rank,dense_rank,row_number使用和区别

    rank,dense_rank,row_number区别 一:语法(用法):     rank() over([partition by col1] order by col2)      dense ...

  4. iOS:移动端“用户反馈和客服”的几个平台SDK的介绍

    简单阐述: 用户反馈功能几乎是每个app都有的一个功能点,通过反馈功能实现与用户的连接.沟通,随时随地收集用户意见反馈和Bug报告,即时和用户保持沟通,在一定程度上提升了app的竞争力.而给app评分 ...

  5. iOS:给图片置灰色

    一.在iOS开发中,给图片置灰色这个功能经常会用到,例如商品展示时,商品过期或者下线了,那么图片就需要这个功能.下面这个方法就可以到达目的. /** UIImage:去色功能的实现(图片灰色显示) @ ...

  6. Js计算指定日期加上多少天,加多少月,加多少年的日期

    function DateAdd(interval,number,date) { /* * 功能:实现VBScript的DateAdd功能. * 参数:interval,字符串表达式,表示要添加的时间 ...

  7. [转]Python机器学习工具箱

    原文在这里  Python在科学计算领域,有两个重要的扩展模块:Numpy和Scipy.其中Numpy是一个用python实现的科学计算包.包括: 一个强大的N维数组对象Array: 比较成熟的(广播 ...

  8. 微信小程序--后台交互/wx.request({})方法/渲染页面方法 解析

    小程序的后台获取数据方式get/post具体函数格式如下:wx.request({}) data: { logs:[] }, onLoad:function(){ this.getdata(); } ...

  9. Java-JUC(八):使用wait,notify|notifyAll完成生产者消费者通信,虚假唤醒(Spurious Wakeups)问题出现场景,及问题解决方案。

    模拟通过线程实现消费者和订阅者模式: 首先,定义一个店员:店员包含进货.卖货方法:其次,定义一个生产者,生产者负责给店员生产产品:再者,定义一个消费者,消费者负责从店员那里消费产品. 店员: /** ...

  10. windows 通过Web.config添加mimetype映射

    在Web.config里添加以下代码即可 <configuration> <system.webServer> <staticContent> <!-- re ...