虽然之前写过很多编译安装PHP的文章, 但是隔段时间还是会重新安装一些PHP的版本,再次记录一下

1. 下载安装编译工具

yum groupinstall 'Development Tools'

2.安装依赖包

yum install 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 zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel

3. 下载并解压PHP7.4

wget http://mirrors.sohu.com/php/php-7.4.0.tar.gz
# 解压
tar -zxvf php-7.4.0.tar.gz cd php-7.4.0

4. 新增用户和用户组

groupadd www

useradd -g www www

5. 生成编译文件

./configure \
--prefix=/usr/local/php74 \
--with-config-file-path=/etc \
--with-fpm-user=www \
--with-fpm-group=www \
--with-curl \
--with-freetype-dir \
--enable-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 \
--with-zip \
--enable-fpm

注意:有些编译项需要进行修改可以通过./configure --help  查看具体的项

./configure --prefix=/usr/local/php74 --with-config-file-path=/usr/local/php74/etc --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

6. 编译安装

make  && make install -j 2

  -j 指定执行的进程数

7.安装成功之后,设置环境变量

vim /etc/profile

添加
PATH=$PATH:/usr/lcoal/php74/bin
export PATH 立即生效
source /etc/profile

8. 测试查看PHP版本

php -v

创建php-fpm软链接
ln -s /usr/local/php74/sbin/php-fpm /usr/local/php74/bin/php-fpm php-fpm -v

9.配置

#将源码中的配置文件复制到PHP的配置文件中

cp php.ini-production /usr/local/php74/etc/php.ini

#将PHP目录中的php-fpm配置文件进行修改
cp php-fpm.conf.default php-fpm.conf cp php-fpm.d/www.conf.default php-fpm.d/www.conf

10.添加php-fpm启动项

#将PHP源码中的php-fpm启动文件加入到服务自启动文件中
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #赋予执行权限
chmod +x /etc/init.d/php-fpm #启动php-fpm
/etc/init.d/php-fpm start

11.php-fpm服务化

centos7 已经使用systemctl来进行服务的管理,这里我们也使用systemctl来对php-fpm进行管理

修改php-fpm.conf文件
打开pid=/var/run/php-fpm.pid cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm74.service ln -s /usr/lib/systemd/system/php-fpm74.service /usr/lib/systemd/system/php-fpm.service systemctl daemon-reload systemctl enable php-fpm

php-fpm.service文件内容:

[Unit]
Description=The PHP FastCGI Process Manager
After=network.target [Service]
Type=simple
PIDFile=/usr/local/php74/var/run/php-fpm.pid
ExecStart=/usr/local/php74/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php74/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID PrivateTmp=true
[Install]
WantedBy=multi-user.target

停止之前启动的php-fpm, 使用systemctl启动php-fpm

systemctl start php-fpm.service

12.在使用的时候发现zip扩展没有安装,现在需要添加扩展

在PHP源代码包中,我的源码路径:/opt/php-7.4.0/, 需要进去到zip扩展包中cd  /opt/php-7.4.0/ext/zip

#生成配置文件
phpize ./configure --with-php-config=/usr/local/php74/bin/php-config --with-zip make && make install

在配置文件中开启扩展即可 php.ini

常见错误:

  1. error: Package requirements (sqlite3 > 3.7.4) were not met

yum install libsqlite3x-devel -y

  2.error: Package requirements (oniguruma) were not met

yum install oniguruma-devel -y

  3. 访问nginx无法解析PHP文件

server {
listen 8081;
server_name localhost;
index index.html index.php;
root /data/www; access_log /data/logs/www.access.log main;
error_log /data/logs/www.error.log;
location / {
if (!-e $request_filename) {
rewrite ^/(.*) /index.php last;
}
} location ~ .*\.(php|php5)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 这里注意需要进行修改
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

  3. configure: error: Package requirements (libzip >= 0.11) were not met: No package 'libzip'

libzip  版本太低了
编译安装,指定PKG_CONFIG_PATH,上面报错中其实有提示信息,让我们考虑调整PKG_CONFIG_PATH环境变量。
下面是详细步骤: # 先卸载已有
yum remove libzip
# 然后安装
wget https://libzip.org/download/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install 装完了之后找一下/usr/local/lib下有没有pkgconfig目录,有的话执行命令export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"指定PKG_CONFIG_PATH。
到这里问题解决!

   4. 安装扩展的时候,

Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment

安装autoconf

yum install -y autoconf

  

PHP7.4之编译安装的更多相关文章

  1. php7 redis扩展编译安装

    提示:php7版本不支持redis2点几的扩展 上正文: wget -c https://github.com/phpredis/phpredis/archive/php7.zip unzip php ...

  2. php7源码编译安装

    以下以CentOS 7.2为例,安装php的运行环境,首先打开php官网http://php.net/点击导航栏的Downloads进入下载页面:http://php.net/downloads.ph ...

  3. centos7.6编译安装php7.2.11及redis/memcached/rabbitmq/openssl/curl等常见扩展

    centos7.6编译安装php7..11及redis/memcached/rabbitmq/openssl/curl等常见扩展 获取Php的编译参数方法: [root@eus-api-cms-bac ...

  4. 编译安装PHP7及扩展

    一.编译安装PHP 1. 下载源码包并解压 源码包地址:http://php.net/downloads.php 下载源码包 当前PHP最新本门是7.2.9,下载 php-7.2.9 源码包 wget ...

  5. centos7编译安装LNMP(nginx-1.16.0,mysql8.0.16,php-7.3.6)常见问题报错及解决方法

    LNMP的安装与配置 nginx-1.16.0安装及配置: 第一步:前往官网下载nignx源码包 下载完毕后上传至服务器(先安装lrzsz) yum -y install lrzsz 安装完毕后执行: ...

  6. linux centos编译安装php7.3

    php7.2的编译安装参考:https://www.cnblogs.com/rxbook/p/9106513.html 已有的之前编译的旧版本php: mv /usr/local/php /usr/l ...

  7. CentOS7编译安装php7.1配置教程详解

    这篇文章主要介绍CentOS7编译安装php7.1的过程和配置详解,亲测 ,需要的朋友可以参考. 1.首先安装依赖包: yum install libxml2 libxml2-devel openss ...

  8. 一个神奇的PHP框架:Phalcon 之编译安装

    前言 CentOS7下升级PHP到最新版本以及编译安装phalcon框架,看相关文档无数遍,自己尝试编译安装之后才理解的更深,编译步骤以及碰到的问题做个简单的记录 php-7.0.11编译安装 1.下 ...

  9. CentOS 7.1编译安装PHP7

    原文: https://typecodes.com/web/centos7compilephp7.html?utm_source=tuicool&utm_medium=referral 1 创 ...

  10. 编译安装PHP7并安装Redis扩展Swoole扩展

    编译安装PHP7并安装Redis扩展Swoole扩展 在编译php7的机器上已经有编译安装过php5.3以上的版本,从而依赖库都有了 本php7是编译成fpm-php 使用的, 如果是apache那么 ...

随机推荐

  1. 千万级别mysql 分库分表后表分页查询优化方案初探

    随着使用的用户群体越来越多,表数据也会随着时间的推移,单表的数据量会越来越大. 以订单表为例,假如每天的订单量在 4 万左右,那么一个月的订单量就是 120 多万,一年就是 1400 多万,随着年数的 ...

  2. 受 LabelImg 启发的基于 web 的图像标注工具,基于 Vue 框架

    受 LabelImg 启发的基于 web 的图像标注工具,基于 Vue 框架   哟,网友们好,年更鸽子终于想起了他的博客园密码.如标题所述,今天给大家带来的是一个基于 vue2 的图像标注工具.至于 ...

  3. ECMA Script6 中的 尾调用优化

    在读 <深入理解ES6>一书中,看到有关函数的 "尾调用优化" 章节,特此记录一下 尾调用 指的是 函数作为另一个函数的最后一条语句被调用: function foo ...

  4. postgresql数据库中 JSON 字段 replace

    一.需求 postgresql 数据库,需要将某些表中的json字段的数据进行替换. 二.做法 思路:将json字段转为text,然后调用replace函数后,将text再转为json update ...

  5. RxJS 系列 – 概念篇

    前言 很长一段时间没有写 Angular 了 (哎...全栈的命),近期计划又要开始回去写了,于是就开始做复习咯. 我的复习是从 JS > TS > RxJS > Angular,与 ...

  6. Java!!冲

    开始学习Java!!!

  7. @RestController和@Controller的区别

    @RestController 和 @Controller 是Spring框架中用于定义控制器(Controller)的两个非常重要的注解,它们都用于处理HTTP请求,但它们之间存在一些关键的区别. ...

  8. 谷歌浏览器页面乱码问题在浏览器端解决,charset下载安装;

    一   下载插件(百度网盘) 链接:https://pan.baidu.com/s/1o9Zuo2m 密码:rrcz 二    将下载好的插件拖到谷歌浏览器中 三    如果谷歌浏览器右下角出现如下图 ...

  9. HOG算法的笔记与python实现

    这两篇[1][2]博客写的都非常详细.这里做个笔记记录一下. HOG称为方向梯度直方图(Histogram of Oriented Gradient),主要是为了对图像进行特征提取.所以在传统目标检测 ...

  10. vue的计算属性computed和监视属性waatch的区别

    共同的:都是用于监听数据变化的属性: 计算属性:必须有返回值return ,依赖其它属性值,其它属性值发生变化的时候就会重新计算 : 监视属性:每当数据变化的时候就会触发执行,watch有两个新值和旧 ...