一,下載php7.4
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
二,查看本地的centos的版本
[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
五,生成php配置文件
[root@yjweb php-7.4.2]# cp php.ini-production /usr/local/soft/php7/etc/php.ini
六,生成www配置文件
[root@yjweb etc]# cd /usr/local/soft/php7/etc/php-fpm.d/ [root@yjweb php-fpm.d]# cp www.conf.default www.conf
七,生成php-fpm配置文件
[root@yjweb etc]# cd /usr/local/soft/php7/etc [root@yjweb etc]# cp php-fpm.conf.default php-fpm.conf
八,生成php-fpm服務啟動文件
[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
九,測試啟動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
十,如何查看當前已安裝的php的版本?
[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
十一,查看本地centos的版本
[webop@yjweb ~]$ cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core)