CentOS8安裝PHP7.3
阿新 • • 發佈:2022-05-20
一、依賴包安裝
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.20/cmake-3.20.2.tar.gz tar -xzvf cmake-3.20.2.tar.gz cd cmake-3.20.2 ./bootstrap; make; make install
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*
注意:libzip的版本不能太高
wget https://libzip.org/download/libzip-1.2.0.tar.gz tar -xvzf libzip-1.2.0.tar.gz cd libzip-1.2.0 mkdir build cd build/ cmake .. make make install
如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
引數說明:
指定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
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
4、配置fpm命令
cd php-7.3.30/sapi/fpm cp init.d.php-fpm /etc/init.d/php-fpm #增加許可權 chmod +x /etc/init.d/php-fpm
5、新增環境變數
vim /etc/profile #在檔案底部加入 #PHP7.3 export PATH=$PATH:/usr/local/php7.3/bin #儲存,使環境變數生效 source /etc/profile
6、fpm命令
service php-fpm reload service php-fpm start service php-fpm stop