:盡量少yum安裝。
假定已經(jīng)安裝好了httpd,如果沒(méi)有就yum install httpd禾酱,注意還要安裝yum install httpd-devel
以下是步驟:
1. 安裝先決條件
yum install -y gcc gcc-c++ make automake autoconf gd file bison patch mlocate flex diffutils zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel gmp-devel icu libxslt libxslt-devel php-devel
2. 下載php7.2.31.tar.gz科侈,到 /usr/src目錄, 解壓,進(jìn)入php源文件目錄
cd /usr/src
wget?https://www.php.net/distributions/php-7.2.31.tar.gz
tar -xvf php-7.2.31.tar.gz??
cd php-7.2.31/
3. 停止httpd服務(wù)
systemctl stop httpd.service
4. 編譯配置&安裝
./configure --help命令可以列出當(dāng)前可用的所有參數(shù)辅辩。
因?yàn)橐胊pache难礼,所以確認(rèn)一下apxs目錄
find / -name apxs
得到 /usr/bin/apxs ,如果沒(méi)有找到玫锋,安裝一下httpd-devel:yum intall httpd-devel
執(zhí)行以下命令進(jìn)行編譯配置:(編譯選項(xiàng)說(shuō)明見(jiàn)文末附件)
./configure --prefix=/usr/local/php --with-apxs2=/usr/bin/apxs --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-pdo --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir= --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-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --enable-maintainer-zts --with-xsl --enable-tokenizer
編譯配置完畢:
Build complete.Don't forget to run 'make test'.Installing PHP SAPI module: apache2handler/usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp7.la /usr/lib64/httpd/modules/usr/lib64/apr-1/build/libtool --mode=install install libphp7.la /usr/lib64/httpd/modules/libtool: install: install .libs/libphp7.so /usr/lib64/httpd/modules/libphp7.solibtool: install: install .libs/libphp7.lai /usr/lib64/httpd/modules/libphp7.lalibtool: install: warning: remember to run `libtool --finish /usr/src/php-7.2.31/libs'chmod 755 /usr/lib64/httpd/modules/libphp7.so[activating module `php7' in /etc/httpd/conf/httpd.conf]Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/Installing PHP CLI binary: /usr/local/php/bin/Installing PHP CLI man page: /usr/local/php/php/man/man1/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-configInstalling man pages: /usr/local/php/php/man/man1/ page: phpize.1 page: php-config.1Installing 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.5warning: 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.12Wrote PEAR system config file at: /usr/local/php/etc/pear.confYou may want to add: /usr/local/php/lib/php to your php.ini include_path/usr/src/php-7.2.31/build/shtool install -c ext/phar/phar.phar /usr/local/php/binln -s -f phar.phar /usr/local/php/bin/pharInstalling PDO headers: /usr/local/php/include/php/ext/pdo/
安裝:
make && make install
5. 配置php.ini
將安裝包的php.ini.product 復(fù)制到php安裝目錄
cp php.ini-production /usr/local/php/etc/php.ini
配置php.ini
date.timezone = PRC
expose_php=Off
6. 配置apache蛾茉,支持php
vim /etc/httpd/conf/httpd.conf
檢查有沒(méi)有添加 LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so ,沒(méi)有就添加撩鹿。
Apache配置擴(kuò)展名解析成 PHP
在http.conf文件尾部加入:
<FilesMatch \.php$>
????SetHandler application/x-httpd-php
</FilesMatch>
7. 配置環(huán)境變量
新建php環(huán)境變量
touch /etc/profile.d/php.sh
打開(kāi)php.sh文件并寫(xiě)入:
PATH=$PATH:/usr/local/php/bin
導(dǎo)出
export PATH
使配置文件生效
source /etc/profile
查看php 版本谦炬,確認(rèn)已經(jīng)安裝成功
8. 啟動(dòng)apache
service httpd restart
在web目錄建phpinfo文件查看。
【PHP編譯參數(shù)說(shuō)明】
引自:https://www.cnblogs.com/hubing/p/3735452.html
在Linux下安裝PHP节沦,源代碼方式安裝吧寺,總需要配置很多參數(shù)窜管。這里列出常用配置參數(shù),并詳細(xì)用中文解釋說(shuō)明了稚机。給大家一些參考
編譯PHP的時(shí)候慎用 –with-curlwrappers參數(shù)
./configure
--prefix=/usr/local/PHP?????????????????????????????????? php 安裝目錄
--with-apxs2=/usr/local/apache/bin/apxs???? 表示使用apache2.0以上版本幕帆,apxs表示使用的apache1.0版本
--with-config-file-path=/usr/local/PHP/etc?????????????? 指定php.ini位置
--with-MySQL=/usr/local/mysql??????????????????????? mysql安裝目錄,對(duì)mysql的支持
--with-MySQLi=/usr/local/mysql/bin/mysql_config??????????? mysqli文件目錄,優(yōu)化支持
--enable-safe-mode????????????????????????????? 打開(kāi)安全模式
--enable-ftp???????????????????????????????? 打開(kāi)ftp的支持
--enable-zip???????????????????????????????? 打開(kāi)對(duì)zip的支持
--with-bz2??????????????????????????????????? 打開(kāi)對(duì)bz2文件的支持??????????????????????
--with-jpeg-dir???????????????????????????????? 打開(kāi)對(duì)jpeg圖片的支持
--with-png-dir???????????????????????????????? 打開(kāi)對(duì)png圖片的支持
--with-freetype-dir????????????????????????????? 打開(kāi)對(duì)freetype字體庫(kù)的支持
--without-iconv???????????????????????????????? 關(guān)閉iconv函數(shù)赖条,種字符集間的轉(zhuǎn)換
--with-libXML-dir???????????????????????????????? 打開(kāi)libxml2庫(kù)的支持
--with-XMLrpc???????????????????????????????? 打開(kāi)xml-rpc的c語(yǔ)言
--with-zlib-dir???????????????????????????????? 打開(kāi)zlib庫(kù)的支持
--with-gd??????????????????????????????????? 打開(kāi)gd庫(kù)的支持
--enable-gd-native-ttf?????????????????????????? 支持TrueType字符串函數(shù)庫(kù)
--with-curl??????????????????????????????????? 打開(kāi)curl瀏覽工具的支持
--with-curlwrappers????????????????????????????? 運(yùn)用curl工具打開(kāi)url流
--with-ttf??????????????????????????????????? 打開(kāi)freetype1.*的支持失乾,可以不加了
--with-xsl 打開(kāi)XSLT 文件支持,擴(kuò)展了libXML2庫(kù) 纬乍,需要libxslt軟件
--with-gettext???????????????????????????????? 打開(kāi)gnu 的gettext 支持碱茁,編碼庫(kù)用到
--with-pear????????????????????? 打開(kāi)pear命令的支持,PHP擴(kuò)展用的
--enable-calendar????????????????? 打開(kāi)日歷擴(kuò)展功能
--enable-mbstring????????????????? 多字節(jié)仿贬,字符串的支持
--enable-bcmath????????????????? 打開(kāi)圖片大小調(diào)整,用到zabbix監(jiān)控的時(shí)候用到了這個(gè)模塊
--enable-sockets????????????????? 打開(kāi) sockets 支持
--enable-exif????????????????????? 圖片的元數(shù)據(jù)支持
--enable-magic-quotes?????????????? 魔術(shù)引用的支持
--disable-rpath???????????????????? 關(guān)閉額外的運(yùn)行庫(kù)文件
--disable-debug????????????????? 關(guān)閉調(diào)試模式
--with-mime-magic=/usr/share/file/magic.mime????? 魔術(shù)頭文件位置
CGI方式安裝才用的參數(shù)
--enable-fpm???????????????????? 打上PHP-fpm 補(bǔ)丁后才有這個(gè)參數(shù)纽竣,CGI方式安裝的啟動(dòng)程序
--enable-fastCGI????????????????? 支持fastcgi方式啟動(dòng)PHP
--enable-force-CGI-redirect???????????? 同上 ,幫助里沒(méi)有解釋
--with-ncurses???????????????????? 支持ncurses 屏幕繪制以及基于文本終端的圖形互動(dòng)功能的動(dòng)態(tài)庫(kù)
--enable-pcntl???????????????????? freeTDS需要用到的,可能是鏈接mssql 才用到
mhash和mcrypt算法的擴(kuò)展
--with-mcrypt???????????????????? 算法
--with-mhash???????????????????? 算法
--with-gmp
--enable-inline-optimization
--with-openssl???????????????????? openssl的支持茧泪,加密傳輸時(shí)用到的
--enable-dbase
--with-pcre-dir=/usr/local/bin/pcre-config????? perl的正則庫(kù)案安裝位置
--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