一、依賴包安裝
1、gcc
yum install gcc gcc-c++ ncurses-devel perl
yum -y install openssl openssl-devel
2、安裝cmake
注:cmake版本要大於3.0,如果已經安裝了低版本cmake,先解除安裝
rpm -qa | grep cmake
cmake -version
yum remove -y cmake
#這裡下載免安裝版 wget https://cmake.org/files/v3.13/cmake-3.13.5-Linux-x86_64.tar.gz tar xzf cmake-3.13.5-Linux-x86_64.tar.gz -C /usr/local cd /usr/local mv cmake-3.13.5-Linux-x86_64 cmake-3.13.5 #建立軟連線 ln -sf /usr/local/cmake-3.13.5/bin/* /usr/bin/ #檢驗 cmake -version cmake version 3.13.5
3、其它,PHP的安裝是最費勁的,每個人的系統不一樣,所以只能根據錯誤提示進行修正。
(1)configure: error: libxml2 not found. Please check your libxml2 installation.
yum install libxml2
yum install libxml2-devel -y
(2)checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
yum install curl-devel -y
(3)configure: error: jpeglib.h not found.
yum install libjpeg-devel -y
yum install libpng
yum install libpng-devel
(4)configure: error: freetype-config not found.
yum install freetype-devel
(5)configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install -y libxslt-devel*
(6)configure: error: Please reinstall the BZip2 distribution
yum install -y bzip2-devel
注意:libzip的版本不能太高
網上有人說安裝1.2.0版本,但我試驗過,1.2.0版本太低會報錯,我最終安裝的是1.5.2版本。
#先刪除舊版本 yum remove -y libzip
#下載新版本並安裝
wget https://libzip.org/download/libzip-1.5.2.tar.gz tar -xvzf libzip-1.5.2.tar.gz cd libzip-1.5.2 mkdir build cd build/ cmake .. make & make install
新增配置檔案:
vim /etc/ld.so.conf.d/libzip.conf
/usr/local/lib64/
/usr/local/lib/
/lib/
/usr/local/lib/
/lib64/
/usr/local/share/
/usr/local/share/
如cmake時遇到錯誤:zstd library not found; zstandard support disabled
yum install epel-release
yum install libzstd-devel
二、安裝PHP7.3
1、軟體下載
https://www.php.net/downloads.php
2、安裝
#編譯
./configure --prefix=/usr/local/php7.3 --with-config-file-path=/usr/local/php7.3/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-openssl --with-pcre-regex --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-openssl --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --enable-mbstring --enable-mysqlnd --with-pdo-mysql=mysqlnd
安裝執行configure報錯error: off_t undefined; check your library configuration
vim /etc/ld.so.conf #新增如下幾行 /usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64 #儲存退出 #最好是重啟,使之生效
引數說明:
#指定php安裝目錄 –prefix=/usr/local/php7.3 #指定php.ini位置 –with-config-file-path=/usr/local/php7.3/etc #開啟curl瀏覽工具的支援 –with-curl #開啟對freetype字型庫的支援 –with-freetype-dir #開啟gd庫的支援 –with-gd #開啟gnu 的gettext 支援,編碼庫用到 –with-gettext #選項指令 --with-iconv-dir 用於 PHP 編譯時指定 iconv 在系統裡的路徑,否則會掃描預設路徑。 –with-iconv-dir #開啟libxml2庫的支援 –with-libxml-dir #object code libraries [EPREFIX/lib] –with-libdir=lib64 #openssl的支援,加密傳輸https時用到的 –with-openssl #OPENSSL: Include Kerberos support –with-kerberos #fpm –enable-fpm #Include Perl Compatible Regular Expressions support. –with-pcre-regex #PDO: MySQL支援 –with-pdo-mysql –with-pdo-sqlite #開啟pear命令的支援,PHP擴充套件用的 –with-pear #開啟對png圖片的支援 –with-png-dir #開啟對jpeg圖片的支援 –with-jpeg-dir #開啟對XMLRPC-EP支援 –with-xmlrpc #開啟對XSL的支援. DIR is the libxslt base install directory (libxslt >= 1.1.0 required) –with-xsl #開啟對ZLIB的支援 (requires zlib >= 1.2.0.4) –with-zlib #開啟bc精確數學函式 –enable-bcmath #開啟LIBXML支援 –enable-libxml #最佳化執行緒 –enable-inline-optimization –enable-mbregex #多位元組,字串的支援 –enable-mbstring #開啟Zend OPcache支援 –enable-opcache #freeTDS需要用到的,可能是連結mssql 才用到 –enable-pcntl #可以處理相關的IPC函式 –enable-shmop –enable-sysvsem #開啟SOAP支援 –enable-soap #開啟 sockets 支援 –enable-sockets –enable-xml #開啟對zip的支援 –enable-zip
當你看到這個截圖,說明編譯成功了
#安裝
make && make install
#安裝成功
Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/php7.3/lib/php/extensions/no-debug-non-zts-20180731/ Installing PHP CLI binary: /usr/local/php7.3/bin/ Installing PHP CLI man page: /usr/local/php7.3/php/man/man1/ Installing PHP FPM binary: /usr/local/php7.3/sbin/ Installing PHP FPM defconfig: /usr/local/php7.3/etc/ Installing PHP FPM man page: /usr/local/php7.3/php/man/man8/ Installing PHP FPM status page: /usr/local/php7.3/php/php/fpm/ Installing phpdbg binary: /usr/local/php7.3/bin/ Installing phpdbg man page: /usr/local/php7.3/php/man/man1/ Installing PHP CGI binary: /usr/local/php7.3/bin/ Installing PHP CGI man page: /usr/local/php7.3/php/man/man1/ Installing build environment: /usr/local/php7.3/lib/php/build/ Installing header files: /usr/local/php7.3/include/php/ Installing helper programs: /usr/local/php7.3/bin/ program: phpize program: php-config Installing man pages: /usr/local/php7.3/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php7.3/lib/php/ [PEAR] Archive_Tar - installed: 1.4.14 [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.14 is not the recommended version 1.4.4 [PEAR] PEAR - installed: 1.10.13 Wrote PEAR system config file at: /usr/local/php7.3/etc/pear.conf You may want to add: /usr/local/php7.3/lib/php to your php.ini include_path /root/packages/php-7.3.30/build/shtool install -c ext/phar/phar.phar /usr/local/php7.3/bin ln -s -f phar.phar /usr/local/php7.3/bin/phar Installing PDO headers: /usr/local/php7.3/include/php/ext/pdo/
#檢視php版本
/usr/local/php7.3/bin/php -v #顯示如下 PHP 7.3.30 (cli) (built: May 19 2022 17:20:22) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.30, Copyright (c) 1998-2018 Zend Technologies
3、配置檔案
#複製檔案
cp /usr/local/php7.3/etc/php-fpm.conf.default /usr/local/php7.3/etc/php-fpm.conf cp /usr/local/php7.3/etc/php-fpm.d/www.conf.default /usr/local/php7.3/etc/php-fpm.d/www.conf cp php.ini-development /usr/local/php7.3/etc/php.ini
#配置 www.conf
cd /usr/local/php/etc/php-fpm.d
vim www.conf
#具體內容
[www] listen = 127.0.0.1:9001 #改一下預設埠,預設埠是9000 user = nobody group = nobody pm = dynamic pm.max_children = 128 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 10000 rlimit_files = 1024
slowlog = log/$pool.log.slow
4、修改php.ini配置檔案
cd /usr/local/php7.3/etc
vim php.ini
cgi.fix_pathinfo=0
5、啟動php
cd /usr/local/php7.3/sbin ./php-fpm ps aux | grep php #如果看到有結果則說明安裝成功 root 2021 0.0 0.1 217880 6312 ? Ss 00:59 0:00 php-fpm: master process (/usr/local/php7.3/etc/php-fpm.conf) nobody 2022 0.0 0.1 217880 5792 ? S 00:59 0:00 php-fpm: pool www nobody 2023 0.0 0.1 217880 5792 ? S 00:59 0:00 php-fpm: pool www
6、新增環境變數
vim /etc/profile
#在檔案底部加入
#PHP7.3
export PATH=$PATH:/usr/local/php7.3/bin
#儲存,使環境變數生效
source /etc/profile
7、配置fpm命令
cd php-7.3.30/sbin cp php-fpm /etc/init.d/php-fpm #增加許可權 chmod +x /etc/init.d/php-fpm
8、fpm命令
service php-fpm reload service php-fpm start service php-fpm stop
9、檢視程式狀態
service php-fpm status
結果:php-fpm (pid 1072864) is running...
三、安裝PHP擴充套件
1、需要autoconf版本2.68
#檢查是否有安裝autoconf其他版本: rpm -qf /usr/bin/autoconf #如有安裝則先解除安裝相應版本 rpm -e --nodeps autoconf-2.63
#下載安裝新版本
#下載 wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz #安裝: tar zxvf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure --prefix=/usr/ make && make install #檢查版本: /usr/bin/autoconf -V
2、PHP安裝包中自帶很多擴充套件,以安裝zip為例
#1、進入要安裝的擴充套件包資料夾下,如: cd php-7.3.30/ext/zip #2、透過phpize生成編譯檔案: /usr/local/php7.3/bin/phpize #3、編譯 ./configure --with-php-config=/usr/local/php7.3/bin/php-config #4、安裝 make && make install
3、安裝自帶擴充套件以外的擴充套件,如redis
下載:http://pecl.php.net/get/redis-5.0.0.tgz
#1、解壓並進入目錄 tar xzf redis-5.0.0.tgz cd redis-5.0.0 #2、透過phpize生成編譯檔案: /usr/local/php7.3/bin/phpize #3、編譯 ./configure --with-php-config=/usr/local/php7.3/bin/php-config #4、安裝 make && make install
#重要一步
開啟檔案 etc/php.ini,寫入redis擴充套件
vim etc/php.ini extension=redis.so #在最後一行寫入redis.io 擴充套件
重啟php-fpm後,輸入:php -m 就能檢查擴充套件是否安裝成功