centos8安装php7.4
阅读原文时间:2023年07月13日阅读:2

1,官方网站:

https://www.php.net/

2,下载

[root@yjweb source]# wget https://www.php.net/distributions/php-7.4.2.tar.gz

说明:在linux上以编译方式安装软件时,多数人都习惯把软件安装到 /usr/local目录下,

我们在生产环境中的习惯使用两个目录:

/usr/local/source    保存源码/rpm安装包

/usr/local/soft         保存安装的软件

之所以这样区分,是为了把当时下载的源码或安装包也保存一份,

一来以后用到时能了解到当时的版本

二来如果需要重新编译时也无需去各软件的官网上去找历史版本

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

[root@localhost lib]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)

1,解压命令和configure命令

[root@yjweb source]# tar -zxvf php-7.4.2.tar.gz
[root@yjweb source]# cd php-7.4.2/
[root@yjweb php-7.4.2]# ./configure --prefix=/usr/local/soft/php7 --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-iconv-dir=/usr/local --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --with-zip --with-config-file-path=/usr/local/soft/php7/etc -with-bz2 --enable-inline-optimization --enable-sysvsem

说明:上面的configure命令的参数是php-7.4.2可用的参数,

一些旧的不可用的参数会在configure时给出提示,

大家不要使用已经废弃的参数,避免安装完成后不能正常使用

2,安装命令:

[root@yjweb php-7.4.2]# make && make install

1,报错:Package 'libxml-2.0', required by 'virtual:world', not found

解决:

[root@localhost php-7.4.2]# yum install libxml2-devel

2,报错:Package 'krb5', required by 'virtual:world', not found

解决:

[root@localhost php-7.4.2]# yum install krb5-devel

3,报错:Package 'openssl', required by 'virtual:world', not found

解决:

[root@localhost php-7.4.2]# yum install openssl-devel

4,报错:Package 'sqlite3', required by 'virtual:world', not found

解决:

[root@localhost php-7.4.2]# yum install sqlite-devel

5,报错:Package 'libcurl', required by 'virtual:world', not found

解决:

[root@localhost php-7.4.2]# yum install libcurl-devel

6,报错:Package 'oniguruma', required by 'virtual:world', not found

解决:

参见:CentOS 8 安装 oniguruma 和 oniguruma-devel 一文
地址:https://www.cnblogs.com/architectforest/p/12433640.html

7,报错:Package 'libxslt', required by 'virtual:world', not found

解决:

[root@localhost php-7.4.2]# yum install libxslt-devel

8,报错:Package 'libjpeg', required by 'virtual:world', not found

解决:

[root@localhost php-7.4.2]# yum install libjpeg-devel

9,报错:Package 'libzip', required by 'virtual:world', not found

解决:

[root@localhost php-7.4.2]# yum install libzip-devel

10,报错:configure: error: Please reinstall the BZip2 distribution

解决:

[root@yjweb php-7.4.2]# yum -y install bzip2-devel

11,报错:Package 'libpng', required by 'virtual:world', not found

解决:

[root@yjweb php-7.4.2]# yum install libpng-devel

12,报错:Package 'freetype2', required by 'virtual:world', not found

解决:

[root@yjweb php-7.4.2]# yum install freetype-devel

[root@yjweb php-7.4.2]# cp php.ini-production /usr/local/soft/php7/etc/php.ini

[root@yjweb etc]# cd /usr/local/soft/php7/etc/php-fpm.d/
[root@yjweb php-fpm.d]# cp www.conf.default www.conf

[root@yjweb etc]# cd /usr/local/soft/php7/etc
[root@yjweb etc]# cp php-fpm.conf.default php-fpm.conf

[root@yjweb etc]# mkdir /usr/local/soft/php7/daemon
[root@yjweb etc]# cp /usr/local/source/php-7.4.2/sapi/fpm/init.d.php-fpm /usr/local/soft/php7/daemon/php-fpm
[root@yjweb etc]# chmod 740 /usr/local/soft/php7/daemon/php-fpm

[root@yjweb etc]# /usr/local/soft/php7/daemon/php-fpm start
Starting php-fpm done

[root@yjweb etc]# ps auxfww | grep php | grep -v grep
root 30476 0.0 0.0 141260 10948 ? Ss 11:40 0:00 php-fpm: master process (/usr/local/soft/php7/etc/php-fpm.conf)
nobody 30477 0.0 0.0 167012 10404 ? S 11:40 0:00 \_ php-fpm: pool www
nobody 30478 0.0 0.0 167012 10404 ? S 11:40 0:00 \_ php-fpm: pool www

[root@yjweb etc]# /usr/local/soft/php7/bin/php -v
PHP 7.4.2 (cli) (built: Mar 5 2020 11:16:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

[webop@yjweb ~]$ cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)