一个神奇的PHP框架:Phalcon 之编译安装

前言

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