1. 程式人生 > >centos離線安裝php以及相關問題彙總

centos離線安裝php以及相關問題彙總

離線安裝的兩種方式

此次安裝是為安裝zabbix做準備。安裝在測試環境上進行,有外網訪問;正式環境是離線環境,沒有外網訪問。所以需要先將相關的軟體包下載下來,這裡有兩種情況:

  1. 通過yumdownloader [package]首先將rpm軟體包下載下來,通過rpm命令進行安裝;
  2. 下載tar.gz壓縮包,進行make、make install進行安裝。

因為是初次安裝,php安裝需要先裝很多其他的依賴、擴充套件等,在安裝的時候基本是兩種方式混用的。

php的壓縮包tar.gz和rpm包

在比較兩種包的過程中,發現tar.gz包有19M大小,而rmp包只有1.4M大小,兩者相差比較大,讓我開始一度懷疑rmp安裝會不會出問題。其實不然,在通過rpm -ivh php-5.4.16-45.el7.x86_64.rpm

進行安裝的時候,會提示你:

error: Failed dependencies:
	php-common(x86-64) = 5.4.16-45.el7 is needed by php-5.4.16-45.el7.x86_64
	php-cli(x86-64) = 5.4.16-45.el7 is needed by php-5.4.16-45.el7.x86_64

也就是需要先安裝一php的基礎包,上面的rmp包應該只有核心程式碼。再者,前者是壓縮包,裡面已經包含了php各模組和程式碼,如上面提到的common、cli等,其他還有configure,make安裝執行檔案等等,後者裡面則是已經編譯好的程式碼,可以直接安裝(make要先編譯)

。綜上所述,兩種不同的安裝包在大小、功能上存在明顯差異。

重點過程

安裝過程中最重要的部分是環境依賴檢查和安裝,無論是php.tar.gz安裝方式執行./configure 進行依賴檢查還是rpm直接安裝rpm軟體包,都需要根據錯誤提示安裝相關的依賴包。

初始依賴安裝

  1. 首先下載上述壓縮程式包,放到伺服器上指定目錄,解壓。
  2. 上述文章在安裝php前先安裝了3個依賴Libmcrypt, mhash, mcrypt,文章同樣是通過tar.gz進行make install安裝。我個人認為可以通過yumdownloader下載三個依賴的rmp包, 然後再進行安裝。同時安裝可以放在後續的環境依賴檢查之後進行
先安裝Libmcrypt
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
###/usr/local/php5/bin/phpize #動態編譯php模組,使其可以使用configure編譯。
./configure
make
make install     # libmcript預設安裝在/usr/local

安裝mhash
tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install

安裝mcrypt
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure 
make
make install

執行./configure 可能會出現的錯誤 configure: error: *** libmcrypt was not found 是系統環境變數問題,解決方案如下:

ln -s   /usr/local/bin/libmcrypt_config   /usr/bin/libmcrypt_config  
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH  

然後make, make install,具體見上述文章。

環境依賴檢查和安裝

上述工作進行後,進入php壓縮包解壓目錄,執行: ./configure --prefix=/usr/local/php7 --with-config-file-path=/etc --with-bz2 --with-curl --with-gd --with-openssl -with-gettext --with-xsl --with-zlib-dir --enable-pcntl --enable-sockets --enable-calendar --enable-exif --enable-ftp --enable-mbstring --enable-fpm --enable-zip --with-mcrypt --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr/bin/mysql

上述命令主要用於依賴檢查,如果相關模組沒有裝,則會報錯。 其中: –prefix=/usr/local/php7 將php7安裝到指定目錄 –enable-fpm 編譯 PHP 時需要 --enable-fpm 配置選項來啟用 FPM 支援。

如果安裝mysql

–with-mysqli=–with-mysqli=/usr/bin/mysql_config(檢視mysql_config位置)

–with-pdo-mysql=/usr/bin/mysql(檢視mysql安裝位置) 出現(Thank you for using PHP.即為成功) make (如果看到Don’t forget to run ‘make test’ 編譯成功) make test make install

php安裝錯誤整理

相關依賴包我都是 yumdownloader xxx-devel 版本, 然後進行安裝,(下面為方便直接寫yum install,實際拆分為兩步)有一些可能需要強制安裝。 每安裝一個依賴都會執行上面的環境依賴檢查命令,檢視下一個缺失的軟體包。 libxml2包未正確安裝:

configure: error: xml2-config not found. Please check your libxml2 installation.

rpm安裝libxml2提示 已經安裝 rpm -i --force --nodeps libxml2-devel-2.9.8-4.fc29.x86_64.rpm 強制安裝-devel版本軟體包

checking libxml2 install dir... no
checking whether libxml build works... no
configure: error: build test failed.  Please check the config.log for details

還是libxml2 的問題,說明沒有正確安裝。解決辦法查到是解除安裝zlib包重新安裝,在安裝libxml2 包。如下: 重新安裝zlib-devel,然後重新安裝 libxml2-devel

yum erase zlib-devel
yum install zlib-devel  
rpm -i --force --nodeps libxml2-devel-2.9.8-4.fc29.x86_64.rpm

未安裝openssl:

checking for Kerberos support... no
checking whether to use system default cipher list instead of hardcoded value... no
checking for RAND_egd... no
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>

yum install openssl-devel

未安裝bzip2:

checking whether to enable bc style precision math functions... no
checking for BZip2 support... yes
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

yum install bzip2-devel

未安裝curl:

checking for cURL in default path... not found

yum install curl-devel

未安裝libpng:

checking for FreeType 2... no
checking whether to enable truetype string function in GD... no
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-webp-dir=<DIR>
If configure fails try --with-jpeg-dir=<DIR>
configure: error: png.h not found.

yum install libpng-devel

未安裝mysql或者mysql在其他伺服器:

checking whether to enable embedded MySQLi support... no
checking for specified location of the MySQL UNIX socket... no
mysql_config not found
configure: error: Please reinstall the mysql distribution

我這裡是因為mysql安裝在另外一臺伺服器 yum install mysql-devel

未安裝libxslt:

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

rpm --force -i --nodeps libxslt-devel-1.1.28-5.el7.x86_64.rpm

網路上其他錯誤整理,

configure error xml2-config not found. please check your libxml2 installation
sendos 5.5 安裝 PHP 5.4.3 報 configure error xml2-config not found. please check your libxml2 installation 錯誤
檢查是否安裝了libxm包
[[email protected] software]# rpm -qa |grep  libxml2
libxml2-2.6.26-2.1.12
libxml2-python-2.6.26-2.1.12
重新安裝libxml2和libxml2-devel包, yum安裝的時候發現新版本會提示更新,需要更新的可以更新,不要跳過就行了。
[[email protected] /]# yum install libxml2
[[email protected] /]# yum install libxml2-devel -y
——————————————————------————————————————
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install libxslt-devel
————————————————————————————————————

configure: error: xml2-config not found. Please check your libxml2 installation.
yum install libxml2-devel
configure: error: Cannot find OpenSSL’s
yum install openssl-devel
configure: error: Please reinstall the libcurl distribution -
easy.h should be in /include/curl/
yum install curl-devel
configure: error: libjpeg.(a|so) not found
yum install libjpeg-devel
configure: error: libpng.(a|so) not found.
yum install libpng-devel
configure: error: libXpm.(a|so) not found.
yum install libXpm-devel
configure: error: freetype.h not found.
yum install freetype-devel
configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.
yum install libc-client-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install libmcrypt-devel
configure: error: Please reinstall libmhash – I cannot find mhash.h
yum install mhash-devel
configure: error: Cannot find MySQL header files under /usr.
Note that the MySQL client library is not bundled anymore!
yum install mysql-devel
configure: error: Please reinstall ming distribution. libming.(a|so) not found
- temp remove the config for ‘–with-ming=/opt/ming/’
configure: error: Cannot find pspell
yum install pspell-devel
configure: error: cannot find mm library
Download from http://www.ossp.org/pkg/lib/mm/
wget ftp://ftp.ossp.org/pkg/lib/mm/mm-1.4.2.tar.gz
Extract it:  tar -zxvf mm-1.4.2.tar.gz
configure: error: Cannot find libtidy
yum install libtidy-devel
yum install libtidy
change path at configure: ‘–with-tidy=/usr’
configure: error: not found. Please reinstall the expat distribution.
yum install expat-devel
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install libxslt-devel
*Tips: To uninstall, just enter:
yum remove {package-name}
Finally the compilation of php end with “Thank you for using PHP.”

安裝成功及環境變數配置

./configure執行成功出現Thank you for using PHP後,就可以執行make、make test、make install三條命令。 環境變數配置: vi /etc/profile

export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
export PATH=$PATH:/usr/local/php7/bin

儲存後 source /etc/profile

php -v 檢視版本 php -m 檢視已經安裝的擴充套件和依賴

rpm方式安裝參考

rpm -e --nodeps php-pgsql-5.3.3-49.el6.x86_64
rpm -e --nodeps php-odbc-5.3.3-49.el6.x86_64
rpm -e --nodeps php-xmlrpc-5.3.3-49.el6.x86_64 
rpm -e --nodeps php-common-5.3.3-49.el6.x86_64
rpm -e --nodeps php-pdo-5.3.3-49.el6.x86_64
rpm -e --nodeps php-pear-1.9.4-5.el6.noarch
rpm -e --nodeps php-mysql-5.3.3-49.el6.x86_64 
rpm -e --nodeps php-soap-5.3.3-49.el6.x86_64
rpm -e --nodeps php-gd-5.3.3-49.el6.x86_64
rpm -e --nodeps php-pecl-memcache-3.0.5-4.el6.x86_64
rpm -e --nodeps php-5.3.3-49.el6.x86_64
rpm -e --nodeps php-cli-5.3.3-49.el6.x86_64
rpm -e --nodeps php-ldap-5.3.3-49.el6.x86_64
rpm -e --nodeps php-xml-5.3.3-49.el6.x86_64

安裝:

rpm -ivh libXpm-3.5.10-2.el6.x86_64.rpm
yum install -y  gcc*
yum install -y httpd
rpm -ivh t1lib-5.1.2-6.el6_2.1.x86_64.rpm 
rpm -ivh php-common-5.6.33-1.w6.x86_64.rpm 
rpm -ivh php-cli-5.6.33-1.w6.x86_64.rpm 
rpm -ivh php-5.6.33-1.w6.x86_64.rpm 
rpm -ivh php-bcmath-5.6.33-1.w6.x86_64.rpm
rpm -ivh php-gd-5.6.33-1.w6.x86_64.rpm 
rpm -ivh php-ldap-5.6.33-1.w6.x86_64.rpm 
rpm -ivh php-mbstring-5.6.33-1.w6.x86_64.rpm
rpm -ivh php-pdo-5.6.33-1.w6.x86_64.rpm
rpm -ivh php-mysql-5.6.33-1.w6.x86_64.rpm  
rpm -ivh php-xml-5.6.33-1.w6.x86_64.rpm