【Phalcon】Phalcon在阿里云ecs 的linux环境搭建让你真正搭建起来 - Go语言中文社区

【Phalcon】Phalcon在阿里云ecs 的linux环境搭建让你真正搭建起来


Phalcon是一套实现MVC架构的高性能php应用程序框架。初始版本发布于2012年11月,开放源代码并基于BSD授权条款。与其他大部分的PHP框架不同,Phalcon是以扩展的方式以C语言所编写,因此Phalcon的执行速度高过其他PHP框架,并且消耗更少的资源,根据官方的测试,Phalcon是目前世界上速度最快的PHP框架, 没有之一。
php需要高于5.4版本 即为 5.5以上的php环境,若环境低于5.5版本,请安装或者切换版本即可
运用的地方为高并发等平台,可以用来做接口或者网站,就医160应该是采用了该php框架。
linux操作命令为:
git clone git://github.com/phalcon/cphalcon.git
cd cphalcon/build

sudo ./install

Add the extension to your php.ini:

extension=phalcon.so

但是 sudo ./install 命令总是会存在报错的情况,接下来处理下问题:

报错情况:

  sudo ./install

php 5.4 not longer supported   该版本不支持


解决方案1:

更改phalcon 安装文件的源代码   譬如路径下 /root/cphalcon/build  用记事本(别用其他编辑器哦) 删除一下代码


exit 1
fi  if [ "${PHP_FULL_VERSION:0:3}" == "5.4" ]; then
echo "php 5.4 is no longer supported"


解决方案2:

重新编译新的php 版本或者重新安装新的版本或者切换php 版本

譬如切换 到php 的最新版 php7

加入你的服务器放的是onestack的镜像


那么

最后探针一下 




成功,phalcon+php7 的服务器环境,简直是如虎添翼!

---------------------------------------------若有Zephir 或者 PHP7以下的版本请忽略-------------------------------------------------------------------------

万事具备只欠东风,但是值得一提的是php7高性能的php 环境下要安装phalcon ,坑还是不少,

In file included from /root/cphalcon/build/php7/64bits/phalcon.zep.c:174:0:

/root/cphalcon/build/php7/64bits/php_phalcon.h:58:2: error: unknown type name 'zend_array'
  zend_array *symbol_table;

解决方案:

首先要安装好


安装Zephir

支持PHP7版本的Phalcon2.1.x不支持普通方式的编译安装,只能通过zephir安装。因此安装phalcon之前,请先安装Zephire。安装方法如下:

$zypper in re2c #Opensuse 安装zephir解释器
$git clone https://github.com/phalcon/zephir.git
$cd zephir
$./install -c #-c表示全局安装,需要root密码

其他版本的linux可以自己搜索安装re2c,Mac通过brew也可以安装。
安装完成后可以通过zephir命令查看相关的命令参数与功能

编译安装phalcon

编译之前请确认which php 和which phpize指向PHP7版本
安装代码如下:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
zephir build --backend=ZendEngine3

编译完成后将extension=phalcon.so加入php.ini文件,重启php-fpm和nginx(我装的是lnmp)。
可以通过php -i|grep phalcon查看是否安装成功,也可以通过web页面输出phpinfo()来查看

详情请看 https://segmentfault.com/a/1190000005131614

小编在此说下,phalcon 2.1还属于beta 版本,生产环境还是建议php5.6即可,加上phalcon 足够高性能了

----------------------------------------------若有Zephir 或者-PHP7以下的版本请忽略结束-------------------------------------------------------------------------



或者存在报错情况:

  sudo ./install
./install: line 24: php-config: command not found

php-config is not installed

解决方案:

yum install php-devel




或者存在报错情况:(madan 足足浪费了我几个钟头,各种重装与命令!操)

config.status: executing libtool commands

/bin/bash /root/cphalcon/build/64bits/libtool --mode=compile gcc -I. -I/root/cphalcon/build/64bits -DPHP_ATOM_INC -I/root/cphalcon/build/64bits/include -I/root/cphalcon/build/64bits/main -I/root/cphalcon/build/64bits -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DPHALCON_RELEASE -DHAVE_CONFIG_H -march=native -mtune=native -O2 -finline-functions -fomit-frame-pointer -fvisibility=hidden -c /root/cphalcon/build/64bits/phalcon.c -o phalcon.lo libtool: compile: gcc -I. -I/root/cphalcon/build/64bits -DPHP_ATOM_INC -I/root/cphalcon/build/64bits/include -I/root/cphalcon/build/64bits/main -I/root/cphalcon/build/64bits -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DPHALCON_RELEASE -DHAVE_CONFIG_H -march=native -mtune=native -O2 -finline-functions -fomit-frame-pointer -fvisibility=hidden -c /root/cphalcon/build/64bits/phalcon.c -fPIC -DPIC -o .libs/phalcon.o 这个地方,不动弹

 找到了一个解决方案:

大家不妨试试:(可以)

cd cphalcon/ext
export CFLAGS="-O2 -finline-functions -fvisibility=hidden"
phpize 
./configure --enable-phalcon
make
sudo make install


[root@root ~]# cd cphalcon/ext
[root@root ext]# export CFLAGS="-O2 -finline-functions -fvisibility=hidden"
[root@root ext]# phpize 
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
[root@root ext]# ./configure --enable-phalcon
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php
checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -


I/usr/local/php/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable phalcon... yes, shared
checking whether HAVE_BUNDLED_PCRE is declared... yes
checking for ext/pcre/php_pcre.h... yes
checking whether HAVE_JSON is declared... yes
checking for ext/json/php_json.h... yes
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no


creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
[root@root ext]# make
/bin/sh /root/cphalcon/ext/libtool --mode=install cp ./phalcon.la /root/cphalcon/ext/modules
cp ./.libs/phalcon.so /root/cphalcon/ext/modules/phalcon.so
cp ./.libs/phalcon.lai /root/cphalcon/ext/modules/phalcon.la
PATH="$PATH:/sbin" ldconfig -n /root/cphalcon/ext/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /root/cphalcon/ext/modules


If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'


See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------


Build complete.
Don't forget to run 'make test'.
[root@root]# sudo make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
Installing header files:          /usr/local/php/include/php/

增加php.ini 扩展 

extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so

接下来重启服务器


重启nginx

[root@root ~]# cd /usr/local/nginx/sbin
[root@root sbin]# ./nginx -s reload

重启php-fpm

[root@root]#  /etc/init.d/php-fpm restart

检测是否可运行

[root@root sbin]# php -i|grep phalcon
phalcon
phalcon => enabled
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On
phalcon.orm.events => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.virtual_foreign_keys => On => On
到处服务器的phalcon 完成了



phalcon-devtools安装

  phalcon的脚手架工具,支持一组命令

git clone git://github.com/phalcon/phalcon-devtools.git
cd phalcon-devtools/ && sudo ln -s ~/devtools/phalcon.php /usr/bin/phalcon

执行phalcon commands

执行create-project

cd /srv/www/htdocs/ && phalcon create-project store

启动服务器

#重启fpm和nginx
sudo service php-fpm restart
sudo service nginx restart




欢迎关注我的github:   https://github.com/xingwen93


版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_14997169/article/details/52282691
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 18:14:18
  • 阅读 ( 995 )
  • 分类:Linux

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢