CentOS7编译安装php7

下载源码包

安装wget并下载php源码包, 去 https://www.php.net/releases/ 可以找到历史版本的包

[root@localhost ~]# yum install wget -y && wget http://cn2.php.net/distributions/php-7.2.4.tar.gz --no-check-certificate

依赖安装

# 安装编译工具
[root@localhost ~]# yum install gcc autoconf gcc-c++ -y 
# 各种库的依赖环境,如果不需要某些库可以去掉
[root@localhost ~]# 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 readline readline-devel libxslt libxslt-devel openjpeg-devel systemd-devel -y

编译安装

# 解压
[root@localhost ~]# tar zxvf php-7.2.4.tar.gz
[root@localhost ~]# cd php-7.2.4
# 编译,视情况而定需要加的编译参数
[root@localhost php-7.2.4]# ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-systemd \
--enable-fileinfo

编译成功(编译期间如果有报错直接百度搜索一般都有答案)

image

安装

[root@localhost php-7.2.4]# make && make install

安装成功,(安装期间如果有报错直接百度搜索一般都有答案)

image

配置

注意:以下操作都是在源码解压目录进行的

使用php源码目录中的生产环境配置

[root@localhost php-7.2.4]# cp php.ini-production /usr/local/php/etc/php.ini

使用php-fpm的默认配置

[root@localhost php-7.2.4]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.2.4]# cp  /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

php-fpm的systemd配置

[root@localhost php-7.2.4]# cp ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/
# 开机自启
[root@localhost php-7.2.4]# systemctl enable php-fpm
# 启动php
[root@localhost php-7.2.4]# systemctl start php-fpm
# 查看php运行状态,active (running)表示运行正常
[root@localhost php-7.2.4]# systemctl status php-fpm
# 添加环境变量
[root@localhost php-7.2.4]# vim ~/.bashrc

向末尾添加以下内容,然后保存退出

export PATH=$PATH:'/usr/local/php/bin/'

重载环境变量

[root@localhost php-7.2.4]# source ~/.bashrc
# 测试php是否安装成功
[root@localhost php-7.2.4]# php -v
PHP 7.2.4 (cli) (built: Apr  9 2020 09:59:55) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

最后,点个赞吧或者评论留下安装时候遇到的问题。看到了都会回复的。

你可能感兴趣的:(CentOS7编译安装php7)