操作系統(tǒng):CentOS7
安裝版本:PHP7.4
【官網(wǎng)】https://www.php.net/downloads
1)到PHP官網(wǎng)下載PHP7.4,并且解壓
cd /home/install/php
wget https://www.php.net/distributions/php-7.4.12.tar.gz
tar -zxvf php-7.4.12.tar.gz
1.png
2)切換到解壓目錄編譯配置
#更多可以在 ./configure --help 去查看
./configure --prefix=/usr/local/php \
--with-config-file-path=/etc --enable-fpm --enable-inline-optimization \
--disable-debug --enable-mysqlnd --enable-static --disable-rpath --enable-shared --enable-soap --with-xmlrpc \
--with-openssl --with-mhash --with-external-pcre --with-pcre-jit --with-zlib \
--enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl \
--with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pear \
--enable-opcache --enable-ftp --with-gdbm --with-openssl-dir --with-jpeg --with-zlib-dir \
--with-freetype --enable-gd --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --with-sqlite3\
--enable-mbstring --enable-mbregex --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg \
--enable-sysvsem --enable-sysvshm --with-xsl --with-zip --enable-mysqlnd-compression-support --enable-intl
編譯時可能會出現(xiàn)一些錯誤 configure error:(我編譯安裝時遇到的報錯如下拭嫁,有其他報錯請另外自己解決)
1. configure: error: Please reinstall the BZip2 distribution
解決:yum install bzip2 bzip2-devel -y
2. configure: error: Package requirements (libcurl >= 7.15.5) were not met:No package 'libcurl' found
解決:yum install libcurl libcurl-devel -y
3.configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解決:yum install libxslt libxslt-devel -y
4.configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
解決:yum install sqlite-devel -y
5.configure: error: GNU MP Library version 4.2 or greater required.
解決:yum install gmp-devel -y
6.configure: error: Package requirements (oniguruma) were not met: No package 'oniguruma' found
解決:yum install oniguruma-devel -y
7.configure: error: Please reinstall readline - I cannot find readline.h
解決:yum install readline-devel -y
8.configure: error: Package requirements (libpcre2-8 >= 10.30) were not met: No package 'libpcre2-8' found
解決:http://www.reibang.com/p/89646111a1ce
9.configure: error: DBA: Could not find necessary header file(s).
解決:yum install gdbm-devel -y
10.configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:No package 'libzip' found
解決:http://www.reibang.com/p/6cbd25addc29
11.configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met: No package 'libxml-2.0' found
解決:yum install libxml2-devel -y
12.configure: error: Package requirements (libpng) were not met: No package 'libpng' found
解決:yum install libpng-devel -y
13.configure: error: Package requirements (libjpeg) were not met:No package 'libjpeg' found
解決:yum install libjpeg-devel -y
14.configure: error: Package requirements (freetype2) were not met:No package 'freetype2' found
解決:yum install freetype-devel -y
15.configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:
No package 'icu-uc' found
No package 'icu-io' found
No package 'icu-i18n' found
解決:yum install libicu-devel -y
到這里沒有報錯過一會會出現(xiàn)下圖界面
2.png
然后再執(zhí)行編譯安裝命令(編譯安裝過程時間有些長沈矿,須耐心等待)
make
make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM defconfig: /usr/local/php/etc/
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing phpdbg binary: /usr/local/php/bin/
Installing phpdbg man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.9
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.5
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.9 is not the recommended version 1.4.4
[PEAR] PEAR - installed: 1.10.12
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/home/install/php/php-7.4.12/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin/phar.phar
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
3)以上終于完成PHP的源碼編譯安裝了篙耗,下面就是配置PHP
# 配置PHP
[root@localhost php-7.4.12]# php -v
bash: php: 未找到命令...
[root@localhost php-7.4.12]# /usr/local/php/bin/php -v
PHP 7.4.12 (cli) (built: Nov 16 2020 19:43:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
為PHP添加環(huán)境變量
export PATH=$PATH:/usr/local/php/bin
php -v 直接就能查看php版本隧魄,不需要再 /usr/local/php/bin/php -v 這么長了
[root@localhost php-7.4.12]# php -v
PHP 7.4.12 (cli) (built: Nov 16 2020 19:43:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
4)配置PHP-fpm涉馁,(請注意我的目錄江咳,是一直在PHP7的解壓目錄下操作命令)
/home/install/php/php-7.4.12/ 是我下載PHP包解壓出來的目錄
/usr/local/php/ 是PHP編譯安裝的目錄
3.png
開始配置PHP-fpm袖订,復(fù)制一些配置文件氮帐,做好備份準(zhǔn)備
[root@localhost php-7.4.12] cp php.ini-development /etc/php.ini
[root@localhost php-7.4.12] cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.12] cd /usr/local/php/etc
[root@localhost etc] cp php-fpm.conf.default php-fpm.conf
[root@localhost etc] cp php-fpm.d/www.conf.default php-fpm.d/www.conf
[root@localhost etc]chmod +x /etc/init.d/php-fpm
# /etc/init.d/php-fpm文件的內(nèi)容,確保正確
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
這時候就開始啟動php-fpm了
# service php-fpm {start|stop|force-quit|restart|reload|status|configtest}
service php-fpm start #啟動命令
ps ax|grep php-fpm # 查看是否啟動php-fpm
[root@localhost etc] ps ax | grep php-fpm # 或者 netstat -ant | grep 9000
33891 ? Ss 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
33892 ? S 0:00 php-fpm: pool www
33893 ? S 0:00 php-fpm: pool www
34443 pts/0 S+ 0:00 grep --color=auto php-fpm
終于完成了......
最后補(bǔ)個小tips
假如在編譯配置里加入這兩個配置而導(dǎo)致啟動失敗
--with-fpm-user=nginx
--with-fpm-group=nginx
如果啟動php-fpm失敗洛姑,則需要在安裝完之后的目錄 /usr/local/php/etc/php-fpm.d/www.conf(配置完后的文件)
找到user和group修改他們的值為 nobody 就可以啟動成功了
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = nobody
group = nobody