前言
CentOS7下升級PHP到最新版本以及編譯安裝phalcon框架,看相關文檔無數遍,自己嘗試編譯安裝之后才理解的更深,編譯步驟以及碰到的問題做個簡單的記錄
php-7.0.11編譯安裝
1.下載php-7.0.11源碼
http://php.net/downloads.php#v7.0.11
2.依賴開發包
yum install gcc gcc-c++ libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel curl curl-devel openssl openssl-devel
3.編譯安裝
$YOUR_PHP_SRC_DIR/configure --prefix=/usr/local/php-7.0.11 --with-config-file-path=/usr/local/php-7.0.11/etc --enable-fpm --with-pdo-mysql=mysqlnd --enable-mysqlnd --with-mysqli=mysqlnd --with-openssl --with-mcrypt --with-gd --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --enable-exif --enable-mbstring --enable-pcntl --with-curl --enable-sockets --enable-soap --enable-ftp --with-zlib --enable-zip --with-bz2
4.生產環境常用php編譯配置
./configure
--prefix=/u01/server/php-7.1.0
--with-config-file-path=/u01/server/php-7.1.0/etc
--enable-fpm
--disable-cgi
--with-fpm-user=daemon
--with-fpm-group=daemon
--enable-mbstring
--enable-soap
--enable-bcmath
--enable-ftp
--with-xmlrpc
--with-zlib
--with-bz2=/usr/local
--with-curl
--enable-exif
--with-openssl
--enable-calendar
--enable-ctype
--enable-pcntl
--enable-session
--enable-zip
--enable-sockets
--with-mysqli=mysqlnd
--with-pdo-mysql=mysqlnd
--with-sqlite3
--enable-phar
--with-iconv-dir=/u01/server/common
--with-gettext
--enable-intl
--with-icu-dir=/u01/server/common
--with-mcrypt=/u01/server/common
--with-gd
--with-png-dir=/u01/server/common
--with-jpeg-dir=/u01/server/common
--with-freetype-dir=/u01/server/common
--with-xpm-dir=/u01/server/common/libxpm-3.5.5
phalcon編譯安裝
1.下載最新phalcon源碼
git clone git://github.com/phalcon/cphalcon.git
2.編譯安裝
cd cphalcon/build
./install
3.加上配置(php.ini)
extension=phalcon.so
4.重啟php-fpm
service php-fpm restart
問題
1.GCC編譯器報錯(內存不夠用)
cc: internal compiler error: Killed (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [phalcon.lo] Error 1
后記
1.使用phalcon文檔里高級編譯方法,編譯之后的文件會很大,將近20幾兆
2.使用phalcon文檔里通用編譯方法,編譯之后文件只有5M左右
3.使用通用編譯方法,命令自動搜索路徑需要顯示指定需要編譯PHP版本php-config,phpize這2個命令的路徑
4.cphalcon/build/install安裝腳本會自動根據系統環境以及安裝的PHP版本編譯
5.編譯的時間比較長>_<
6.編譯時需要足夠可用的內存>=2G
7.編譯php時,官方建議使用mysqlnd驅動
8.解決phalcon高級編譯可執行文件很大的問題
export CC="gcc"
export CFLAGS="-O2 -Wall -fvisibility=hidden -flto -DZEPHIR_RELEASE=1"
9.使用php自帶的gd庫時,需要帶上--with-bz2,可能依賴這個庫
參考資料
【1】phalcon倉庫
https://github.com/phalcon/cphalcon
【2】gcc: Internal error: Killed (program cc1) while compiling PHP
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48796