Centos7 源码安装php7.4
· 技术积累 · Linux PHP

2023-02-08更新 | 在centos7上源码安装php7.4供参考

配置yum源

# 配置yum源加速
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.tencent.com/repo/centos7_base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo

# 更新缓存
yum clean all
yum makecache

安装依赖包

yum install epel-release gcc gcc-c++ make zlib zlib-devel pcre pcre-devel freetype freetype-devel \
openssl openssl-devel curl curl-devel libxslt libxslt-devel gd gd-devel glibc glibc-devel \
glib2 glib2-devel mcrypt libmcrypt-devel libmcrypt mhash libxslt-devel libicu-devel ncurses  \
ncurses-devel libjpeg-devel libpng libpng-devel libxml2-devel bzip2 bzip2-devel libcurl-devel \
sqlite-devel oniguruma oniguruma-devel ImageMagick-devel unixODBC unixODBC-devel -y

# 需要安装的扩展包
libiconv
libzip >=0.11 !=1.3.1 !=1.7.0
pcre2 >=10.30

# 安装liviconv
wget https://jinchuang.org/novel/php/libiconv-1.17.tar.gz
tar xf libiconv-1.17.tar.gz
cd libiconv-1.17
./configure --prefix=/usr/lcoal/libiconv
make && make install
echo "/usr/local/libiconv/lib" >>/etc/ld.so.conf
ldconfig

# 安装pcre2
wget https://jinchuang.org/novel/php/pcre2-10.39.tar.gz
tar xf pcre2-10.39.tar.gz
cd pcre2-10.39
./configure
make && make install
pcre2-config --version
echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/" >>/etc/profile && source /etc/profile

# 升级libzip
yum remove libzip libzip-devel -y
wget https://jinchuang.org/novel/php/libzip-1.3.2.tar.gz
tar xf libzip-1.3.2.tar.gz
cd libzip-1.3.2
./configure
make && make install
echo "/usr/lcoal/lib" >>/etc/ld.so.conf
ldconfig

官网声明:要使用 OpenSSL 函数,你必须安装» OpenSSL 库。
PHP 7.0 需要 OpenSSL >= 0.9.8。
PHP 7.1-8.0 需要 OpenSSL >= 1.0.1,< 3.0。
PHP >= 8.1 支持 OpenSSL >= 1.0.2,< 4.0。

下载、配置、编译安装php7.4.28,安装目录自行修改 (参数中的用户和组 修改为你自己的,版本不同参数会有所变化,可以在官网查询下)

wget https://jinchuang.org/novel/php/php-7.4.28.tar.gz
tar xf php-7.4.28.tar.gz
cd php-7.4.28
./configure \
--prefix=/usr/local/php74 \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-config-file-path=/usr/local/php74/etc \
--with-bz2 \
--with-curl \
--with-xsl \
--with-openssl \
--with-mhash \
--with-jpeg \
--with-freetype \
--with-iconv-dir=/usr/local/libiconv \
--with-gettext \
--with-zlib \
--with-xmlrpc \
--with-external-pcre \
--with-pcre-jit \
--with-pear \
--with-libxml \
--with-zip \
--with-pdo-odbc=unixODBC,/usr/ \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-libdir=lib64 \
--enable-gd \
--enable-mysqlnd \
--enable-intl \
--enable-dom \
--enable-xml \
--enable-simplexml \
--enable-fpm \
--enable-bcmath \
--enable-ftp \
--enable-sockets \
--enable-mbregex \
--enable-mbstring \
--enable-inline-optimization \
--enable-calendar \
--enable-static \
--enable-bcmath \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-exif \
--enable-sysvsem

make && make install (make 时间较久)

配置文件的调整

# 启动脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

#php.ini 和 php-fpm.conf 两个配置文件
cp php.ini-production /usr/local/php74/etc/php.ini
cd /usr/local/php74/etc/
cp php-fpm.conf.default php-fpm.conf

#php-fpm.conf 引用这个目录中*.conf 配置文件,修改启动用户。端口号等
cd php-fpm.d/
cp www.conf.default www.conf

启动、停止

# 启动(推荐)
/etc/init.d/php-fpm start
或者
/usr/local/php74/sbin/php-fpm

# 停止(推荐)
/etc/init.d/php-fpm stop
或者 
pkill php-fpm 
或
ps -ef |grep php-fpm|grep -v grep |awk '{print $2}'|xargs kill

补充下php7.0 源码configure的参数(已在centos7安装php-7.0.33验证过)

# php7.0 config参数
# 需要先源码安装 libiconv,jpeg,freetype,然后在参数中指定下安装目录

./configure \
--prefix=/usr/local/php70 \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-config-file-path=/usr/local/php70/etc \
--with-bz2 \
--with-curl \
--with-xsl \
--with-openssl \
--with-mhash \
--with-jpeg-dir=/usr/local/jpeg \
--with-freetype-dir=/usr/local/freetype \
--with-iconv-dir=/usr/local/libiconv \
--with-gettext \
--with-zlib \
--with-gd \
--with-xmlrpc \
--with-pcre-jit \
--with-pear \
--with-mysqli \
--with-pdo-odbc=unixODBC,/usr/ \
--with-pdo-mysql \
--with-libdir=lib64 \
--enable-mysqlnd \
--enable-intl \
--enable-dom \
--enable-xml \
--enable-libxml \
--enable-simplexml \
--enable-fpm \
--enable-bcmath \
--enable-ftp \
--enable-sockets \
--enable-mbregex \
--enable-mbstring \
--enable-calendar \
--enable-inline-optimization \
--enable-calendar \
--enable-static \
--enable-bcmath \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-zip \
--enable-exif \
--enable-sysvsem

本文最后更新时间 2024-04-10
文章链接地址:
https://hope.jinchuang.org/archives/300.html
本站文章除注明[转载|引用],均为本站原创内容,转载前请注明出处
关于网站搬家后,评论邮件通知发送失败报错的问题(openssl的问题)
typecho博客根据时间自动切换主题配色
Ubuntu 22.04 源码编译安装 PHP7.4 使用OpenSSL1.1.1版本
统计文本中每个字符出现的次数

Centos7 搭建 Nextcloud个人网盘

Centos7 源码安装Nginx

我要留言