發現yum安裝許多坑
於是只好編譯安裝
第一步得到鏡像地址
在 https://www.php.net/downloads.php 有的地址比較慢,需要耐心等待
cd /usr/local/src
wget https://www.php.net/distributions/php-7.2.19.tar.gz
tar xzvf php-7.2.19.tar.gz
cd php-7.2.19
接下來是編譯安裝
配置命令
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl
拆開看更清晰:
./configure
--prefix=/usr/local/php
--with-config-file-path=/usr/local/php
--enable-mbstring
--enable-ftp --with-gd
--with-jpeg-dir=/usr
--with-png-dir=/usr
--with-mysql=mysqlnd
--with-mysqli=mysqlnd
--with-pdo-mysql=mysqlnd
--with-pear --enable-sockets
--with-freetype-dir=/usr
--with-zlib --with-libxml-dir=/usr
--with-xmlrpc
--enable-zip
--enable-fpm
--enable-xml
--enable-sockets
--with-gd
--with-zlib
--with-iconv
--enable-zip
--with-freetype-dir=/usr/lib/
--enable-soap
--enable-pcntl
--enable-cli
--with-curl
這個先不管了
解決方法:
yum install libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel -y
若是64位系統
解決方法:
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
編譯php后發生warning:configure:WARNING:unrecognizedoptions:--with-mysql 只是php7版本不支持mysql模塊
./configure --help 查看configure的正確語法,重新編譯php支持mysql,改用--with-pdo-mysql
php7版本編譯語句是:
./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-mysqlnd-compression-support \ --with-iconv-dir \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir\ --enable-xml \ --disable-rpath \ --enable-bcmath\ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl --enable-mbregex \ --enable-mbstring \ --enable-intl \ --with-mcrypt \ --with-libmbfl \ --enable-ftp \ --with-gd \ --enable-gd-jis-conv \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --with-gettext \ --disable-fileinfo \ --enable-opcache \ --with-pear \ --enable-maintainer-zts \ --with-ldap=shared \ --without-gdbm
configure: WARNING: unrecognized options: --with-mcrypt, --enable-gd-native-ttf
php7.2不支持 --with-mcrypt, --enable-gd-native-ttf,把這兩個選項刪除掉。
修改后./configure通過的語句
其他錯誤解決: PHP編譯安裝時常見錯誤解決辦法,php編譯常見錯誤
ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor':
/home/king/php-5.2.13/ext/iconv/iconv.c:2491: undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
[root@test php-5.2.13]# vi Makefile
在安裝 PHP 到系統中時要是發生「undefined reference to libiconv_open'」之類的錯誤信息,那表示在「./configure 」沒抓好一些環境變數值。錯誤發生點在建立「-o sapi/cli/php」是出錯,沒給到要 link 的 iconv 函式庫參數。 解決方法:編輯Makefile 大約77 行左右的地方: EXTRA_LIBS = ..... -lcrypt 在最后加上 -liconv,例如: EXTRA_LIBS = ..... -lcrypt -liconv 然后重新再次 make 即可。
或者用另一種辦法
make ZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
作者用的第一種辦法解決的,編譯好Makefile后,記得先make clean一下,再make,不然會報錯
make && make install
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
查詢得知是應為vps內存太小沒到1G引起的,在./configure時加--disable-fileinfo也不能解決
內存不足,mysql 5.5以上版本編譯需要1G以上內存,可以編譯安裝mysql5.5