這篇文章主要介紹CentOS7編譯安裝php7.1的過程和配置詳解,親測 ,需要的朋友可以參考。
1.首先安裝依賴包:
1 yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-deve zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel
2.下載PHP壓縮包並解壓:
1 wget http://php.net/distributions/php-7.1.0.tar.gz 2 tar -zxvf php-7.1.0.tar.gz 3 cd php-7.1.0
3.編譯安裝,編譯的時候可能會出現各種報錯情況:
./configure \ --prefix=/usr/local/php \ --with-config-file-path=/etc \ --enable-fpm \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-soap \ --with-libxml-dir \ --with-xmlrpc \ --with-openssl \ --with-mcrypt \ --with-mhash \ --with-pcre-regex \ --with-sqlite3 \ --with-zlib \ --enable-bcmath \ --with-iconv \ --with-bz2 \ --enable-calendar \ --with-curl \ --with-cdb \ --enable-dom \ --enable-exif \ --enable-fileinfo \ --enable-filter \ --with-pcre-dir \ --enable-ftp \ --with-gd \ --with-openssl-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype-dir \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --with-gettext \ --with-gmp \ --with-mhash \ --enable-json \ --enable-mbstring \ --enable-mbregex \ --enable-mbregex-backtrack \ --with-libmbfl \ --with-onig \ --enable-pdo \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-zlib-dir \ --with-pdo-sqlite \ --with-readline \ --enable-session \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-wddx \ --with-libxml-dir \ --with-xsl \ --enable-zip \ --enable-mysqlnd-compression-support \ --with-pear \ --enable-opcache
全部複製以上程式碼一次執行。
4.編譯成功後安裝:
1 make && make install
注意:編譯時可能會出現 make : ***[sapi/cli/php] error 1 報錯,解決方法:
1).$ vim Makefile
開啟,Makefile檔案,在EXTRA_LIBS最後面增加 -liconv 如:
XTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lreadline -ltermcap -lmcrypt -lltdl -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lxml2 -lssl -lcrypto -lcurl -lxml2 -lssl -lcrypto -lfreetype -lz -lpng12 -lxml2 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lxml2 -lssl -lcrypto -lcrypt -liconv
按Esc,按:wq儲存退出。
2).$ make clean && make && make install
重新執行編譯。
5.安裝成功後配置環境變數:
1 vim /etc/profile
在 /etc/profile檔案末尾新增php環境變數 :
source /etc/profile
檢視環境變數:
echo $PATH
看到php環境變數的路徑後,以後就可以直接使用php命令了,檢視php版本:
php -v
6.現在的PHP沒有.ini檔案和配置檔案,還需要配置php-fpm:
php-fpm的啟動、停止和重啟:
1 service php-fpm start #啟動 2 service php-fpm stop #停止 3 service php-fpm restart #重啟
總結:
以上所述是CentOS7編譯安裝php7.1的教程詳解,希望對大家有所幫助,如果大家有任何疑問歡迎留言交流!