博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Centos7.4和Ubuntu18.04安装PHP7.2
阅读量:6862 次
发布时间:2019-06-26

本文共 4423 字,大约阅读时间需要 14 分钟。

安装依赖

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 re2cyum install bison

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

wget https://libzip.org/download/libzip-1.5.1.tar.gztar zxvf libzip-1.5.1.tar.gz cd libzip-1.5.1more INSTALL.md mkdir buildcd build/cmake ..makemake testmake install

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

wget https://cmake.org/files/v3.12/cmake-3.12.2.tar.gztar zxvf cmake-3.12.2.tar.gz cd cmake-3.12.2./bootstrapgmakegmake installwhereis cmakecd /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/etccp php-fpm.conf.default php-fpm.confvi 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.dcp 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:9000;    fastcgi_index  index.php;    fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;    include        fastcgi_params;}

 

转载地址:http://coqyl.baihongyu.com/

你可能感兴趣的文章
Windows核心编程04-字符编码
查看>>
mysqlcluster笔记
查看>>
ArcCore重构-Makefile模块化
查看>>
例10-3 uva10375(唯一分解定理)
查看>>
Python 魔术方法指南
查看>>
HTML概述
查看>>
BZOJ 4245: [ONTAK2015]OR-XOR
查看>>
github 错误
查看>>
idea 项目转 eclipse项目
查看>>
js去除空格,判断是否包含
查看>>
css3 背景色 实现边框渐变运动动画
查看>>
c#实现常用排序算法
查看>>
rails中输出excel
查看>>
leetcode504
查看>>
消息中间件系列三:使用RabbitMq原生Java客户端进行消息通信(消费者(接收方)自动确认模式、消费者(接收方)自行确认模式、生产者(发送方)确认模式)...
查看>>
软件过程与项目管理(第七周作业)
查看>>
Java-生成验证码图片(自定义内容,尺寸,路径)
查看>>
Word2007:如何在竖版(纵向)页面中间插入横版(横向)页面
查看>>
CentOS中配置xrdp,通过微软远程桌面访问CentOS桌面
查看>>
Java中关于nextInt()、next()和nextLine()的理解
查看>>