CentOS 安裝 PHP7.4.X

參考大佬文章:CentOS 安裝 PHP7.4.X

編譯前準(zhǔn)備

yum --exclude=kernel* update -y
yum groupinstall -y 'Development Tools'
yum install -y epel-release
yum install -y wget openssl-devel bzip2-devel libffi-devel  sqlite-devel vim gpm-libs oniguruma oniguruma-devel libsodium libsodium-devel xz-devel libxml2-devel libcurl-devel
yum install -y bash-completion bash-completion-extras libicu-devel libjpeg libjpeg-devel  nss_ldap cmake  boost-devel libevent libevent-devel gd gd-devel openjpeg-devel 
yum install -y libgcrypt-devel libpng-devel libgpg-error-devel libxslt-devel cmake libmcrypt-devel libmcrypt  recode-devel recode  

安裝高版本libzip

yum remove  -y libzip-devel
yum install -y http://rpms.remirepo.net/enterprise/7/remi/x86_64/libzip5-1.9.2-3.el7.remi.x86_64.rpm
yum install -y http://rpms.remirepo.net/enterprise/7/remi/x86_64/libzip5-devel-1.9.2-3.el7.remi.x86_64.rpm 

編譯安裝源碼

PHP官網(wǎng)下載PHP源碼

wget https://www.php.net/distributions/php-7.4.1.tar.gz
tar -zvxf php-7.4.1.tar.gz && cd php-7.4.1/
mkdir -p /usr/local/php-7.4.1 && useradd -s /sbin/nologin www

在Linux下安裝PHP俐填,源代碼方式安裝静稻,總需要配置很多參數(shù)捅膘。這里列出常用配置參數(shù)娃闲,并詳細(xì)用中文解釋說明了忆矛。
給大家一些參考:
--prefix=/usr/local/PHP #php 安裝目錄
--with-apxs2=/usr/local/apache/bin/apxs #表示使用apache2.0以上版本媳维,apxs表示使用的apache1.0版本 --with-fpm-user=www #指定所屬用戶 --with-fpm-grop=www #指定所屬組
--with-config-file-path=/usr/local/PHP/etc #指定php.ini位置
--with-MySQL=/usr/local/mysql #mysql安裝目錄攻晒,對mysql的支持
--with-MySQLi=/usr/local/mysql/bin/mysql_config #mysqli文件目錄,優(yōu)化支持
--enable-safe-mode #打開安全模式
--enable-ftp #打開ftp的支持
--enable-zip #打開對zip的支持
--with-bz2 #打開對bz2文件的支持
--with-jpeg-dir #打開對jpeg圖片的支持
--with-png-dir #打開對png圖片的支持
--with-freetype-dir #打開對freetype字體庫的支持
--without-iconv #關(guān)閉iconv函數(shù)寂嘉,種字符集間的轉(zhuǎn)換
--with-libXML-dir #打開libxml2庫的支持
--with-XMLrpc #打開xml-rpc的c語言
--with-zlib-dir #打開zlib庫的支持
--with-gd #打開gd庫的支持奏瞬,7.4 后不再支持這種寫法枫绅,所以需要改為 --enable-gd
--enable-gd-native-ttf #支持TrueType字符串函數(shù)庫
--with-curl #打開curl瀏覽工具的支持
--with-curlwrappers #運(yùn)用curl工具打開url流
--with-ttf #打開freetype1.*的支持,可以不加了
--with-xsl #打開XSLT 文件支持硼端,擴(kuò)展了libXML2庫并淋,需要libxslt軟件
--with-gettext #打開gnu 的gettext 支持,編碼庫用到
--with-pear #打開pear命令的支持珍昨,PHP擴(kuò)展用的
--enable-calendar #打開日歷擴(kuò)展功能
--enable-mbstring #多字節(jié)县耽,字符串的支持
--enable-bcmath #打開圖片大小調(diào)整,用到zabbix監(jiān)控的時候用到了這個模塊
--enable-sockets #打開 sockets 支持
--enable-exif #圖片的元數(shù)據(jù)支持
--enable-magic-quotes #魔術(shù)引用的支持
--disable-rpath #關(guān)閉額外的運(yùn)行庫文件
--disable-debug #關(guān)閉調(diào)試模式
--with-mime-magic=/usr/share/file/magic.mime #魔術(shù)頭文件位置
CGI方式安裝才用的參數(shù)
--enable-fpm #打上PHP-fpm 補(bǔ)丁后才有這個參數(shù),CGI方式安裝的啟動程序
--enable-fastCGI #支持fastcgi方式啟動PHP
--enable-force-CGI-redirect #同上 ,幫助里沒有解釋
--with-ncurses #支持ncurses 屏幕繪制以及基于文本終端的圖形互動功能的動態(tài)庫
--enable-pcntl #freeTDS需要用到的镣典,可能是鏈接mssql 才用到
mhash和mcrypt算法的擴(kuò)展
--with-mcrypt #算法
--with-mhash #算法
--with-gmp
--enable-inline-optimization
--with-openssl #openssl的支持兔毙,加密傳輸時用到的
--enable-dbase
--with-pcre-dir=/usr/local/bin/pcre-config #perl的正則庫案安裝位置
--disable-dmalloc
--with-gdbm #dba的gdbm支持
--enable-sigchild
--enable-sysvsem
--enable-sysvshm
--enable-zend-multibyte #支持zend的多字節(jié)
--enable-mbregex
--enable-wddx
--enable-shmop
--enable-soap

編譯PHP的時候慎用 –with-curlwrappers參數(shù)

編譯

在這里可以用各種各樣的參數(shù)來自定義 PHP,例如啟動哪些擴(kuò)展功能包的支持等兄春。用./configure --help命令可以列出當(dāng)前可用的所有參數(shù)澎剥。

./configure \
--prefix=/usr/local/php-7.4.1 \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-config-file-path=/usr/local/php-7.4.1/etc \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--enable-pdo \
--with-zlib \
--enable-xml \
--enable-session \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--enable-pcntl \
--enable-ftp \
--with-zip \
--with-ffi \
--with-zlib-dir \
--with-openssl \
--enable-gd \
--with-openssl \
--with-mhash \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--with-gettext \
--enable-fileinfo \
--enable-opcache \
--enable-maintainer-zts \
--with-xsl \
--with-sodium \
--enable-tokenizer

如果報錯
error: Package requirements (sqlite3 > 3.7.4) were not met
處理yum install -y sqlite-devel
error: Package requirements (oniguruma) were not met
處理yum install -y oniguruma oniguruma-devel,如果這兩個包安裝不了赶舆,安裝如下依賴庫yum -y install epel-release

注意:
編譯安裝(或升級PHP7.4)所遇到的主要就是這兩個問題哑姚,對于其他的報錯,都是依賴的問題芜茵,根據(jù)對應(yīng)的提示安裝相應(yīng)的依賴就行了叙量。
以下是預(yù)編譯完成后PHP所無法識別的擴(kuò)展,也就是九串,這些擴(kuò)展在預(yù)編譯的時候就不要選上了:
【警示】以下是不可用選項(xiàng)
configure: WARNING: unrecognized options:
--with-libxml-dir,
--with-pcre-regex,
--with-pcre-dir,
--with-gd,
--with-jpeg-dir,
--with-png-dir,
--with-freetype-dir,
--enable-mbregex-backtrack,
--with-onig,
--enable-wddx,
--with-libxml-dir,
--enable-zip

操作成功結(jié)果:


image.png

安裝

make && make install

配置PHP環(huán)境變量

vim /etc/profile             #打開profile文件增加如下绞佩,然后使文件生效
PATH=/usr/local/php-7.4.1/bin:/usr/local/php-7.4.1/sbin:$PATH

使環(huán)境變量生效
source /etc/profile
檢查是否安裝成功

image.png

配置PHP-FPM

[root@php php-7.4.1]# pwd
/root/php-7.4.1

把所需的幾個配置文件放到需要的位置

cp php.ini-production /usr/local/php-7.4.1/etc/php.ini
cp /usr/local/php-7.4.1/etc/php-fpm.conf.default /usr/local/php-7.4.1/etc/php-fpm.conf
cp /usr/local/php-7.4.1/etc/php-fpm.d/www.conf.default /usr/local/php-7.4.1/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

啟動PHP-FPM

/etc/init.d/php-fpm start        #啟動
/etc/init.d/php-fpm restart      #重新啟動
/etc/init.d/php-fpm reload       #重新加載
/etc/init.d/php-fpm stop         #停止
/etc/init.d/php-fpm status       #查看狀態(tài)

檢測端口是否監(jiān)聽

ss -ntulp | grep php-fpm

演示YUM安裝PHP7版本

1、安裝前準(zhǔn)備

更新系統(tǒng)軟件倉庫不更新內(nèi)核蒸辆,安裝開發(fā)工具包

yum --exclude=kernel* update -y
yum groupinstall -y  'Development Tools'

2征炼、添加epel第三方依賴庫,安裝YUM源

yum -y  install epel-release yum-utils
rpm  -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
rpm  -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

3躬贡、安裝PHP相關(guān)依賴庫和模塊

yum install  -y  --enablerepo=remi --enablerepo=remi-php74 mod_php php-gd* php php-opcache php-mbstring php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-fpm
yum install  -y  --enablerepo=remi --enablerepo=remi-php74 php-cli php-redis php-pecl-mcrypt php-process php-devel php-pear
yum install  -y  vim libevent-devel libmcrypt-devel libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt libxslt-devel cyrus-sasl-plain cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib openssl openssl-devel pcre pcre-devel zlib zlib-devel wget net-tools

4谆奥、檢查YUM安裝是否成功

安裝完,執(zhí)行如下命令:

php --version                      #查看版本
php -m                             #查看安裝模塊拂玻,需要用到的模塊酸些,沒有安裝的需要YUM安裝
systemctl enable --now php-fpm     #設(shè)置開機(jī)啟動,并啟動檐蚜。
ss -ntulp | grep php-fpm

優(yōu)化PHP

1魄懂、調(diào)整PHP-FPM文件

vim /etc/php-fpm.conf
log_level = error # 指定要記錄的php-fpm日志級別
rlimit_files =  32768  # 為主進(jìn)程設(shè)置打開文件的限制,虛擬機(jī)無法設(shè)置闯第。
events.mechanism = epoll # 指定事件驅(qū)動模型

2市栗、調(diào)整PHP.ini文件

隱藏后端使用的真正腳本類型,擾亂入侵者的滲透思路,另外,切記不要把敏感數(shù)據(jù)直接明文存在session中,有泄露風(fēng)險。

vim /etc/php.ini
error_reporting = E_WARING & ERROR #設(shè)置php的錯誤報告級別,只需要報告警告和錯誤即可
error_log = /var/log/php_errors.log #指定php錯誤日志存放位置
log_errors_max_len =  2048  #指定php錯誤日志的最大長度
expose_php = off #隱藏php的詳細(xì)版本號
session.name = JSESSIONID #表示jsp程序,php的則是PHPSESSID

修改完配置文件需要重新啟動才可以生效

systemctl restart php-fpm
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市填帽,隨后出現(xiàn)的幾起案子蛛淋,更是在濱河造成了極大的恐慌,老刑警劉巖篡腌,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件褐荷,死亡現(xiàn)場離奇詭異,居然都是意外死亡嘹悼,警方通過查閱死者的電腦和手機(jī)叛甫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來杨伙,“玉大人其监,你說我怎么就攤上這事∽禾ǎ” “怎么了棠赛?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵哮奇,是天一觀的道長膛腐。 經(jīng)常有香客問我,道長鼎俘,這世上最難降的妖魔是什么哲身? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮贸伐,結(jié)果婚禮上勘天,老公的妹妹穿的比我還像新娘。我一直安慰自己捉邢,他們只是感情好脯丝,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著伏伐,像睡著了一般宠进。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上藐翎,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天材蹬,我揣著相機(jī)與錄音,去河邊找鬼吝镣。 笑死堤器,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的末贾。 我是一名探鬼主播闸溃,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了辉川?” 一聲冷哼從身側(cè)響起掂为,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎员串,沒想到半個月后勇哗,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡寸齐,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年欲诺,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片渺鹦。...
    茶點(diǎn)故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡扰法,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出毅厚,到底是詐尸還是另有隱情塞颁,我是刑警寧澤,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布吸耿,位于F島的核電站祠锣,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏咽安。R本人自食惡果不足惜伴网,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望妆棒。 院中可真熱鬧澡腾,春花似錦、人聲如沸糕珊。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽红选。三九已至澜公,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間纠脾,已是汗流浹背玛瘸。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留苟蹈,地道東北人糊渊。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像慧脱,于是被迫代替她去往敵國和親渺绒。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,843評論 2 354

推薦閱讀更多精彩內(nèi)容