如何配置nginx支持phalcon及安装phalcon-devtools
最近接到一个需求需要用phalcon,折腾了一上午终于把所有环境都配置好了,在这里记一下配置过程中的坑, 怕以后忘了。
环境:centos 7
PHP版本:php7.0.2
phalcon版本:3.4
需要编译安装phalcon的话,内存最好在2G以上,2G以下的内存编译不了,make的时候会一直卡着
我这里的当前目录是 /tmp
git clone git://github.com/phalcon/cphalcon.git
/*这里需要注意选择对应的php版本,要是不清楚的话可以看看phpinfo的信息
*或者在服务器上输入 file /usr/local/php/bin/php (这里的路径需要对应自己的php路径)
*/
cd cphalcon/build/php7/64bits
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
到上边一步为止,phalcon的安装已经完成了,接下来就是到 /etc/php.ini 上操作了
/* 如果不知道php.ini的位置,那么你可以看看phpinfo的信息
* 或者是输入 /usr/local/php/bin/php --ini 进行查看,
* 路径要按照你php实际安装的地址哦,如果连这个都不知道那就
* whereis php 查看一下就好了
*/
vim /etc/php.ini
//加上一行 extension=phalcon.so
//保存退出,然后重启php-fpm
service restart php-fpm
或者
/usr/local/php/sbin/php-fpm
至此phalcon就完成安装了,查看一下phpinfo.或者 php -m 看看是否已添加成功
接下来就是安装phalcon-devtools,按照官方文档去安装的话,可能会有坑。
第一步,我当前目录是/tmp, git clone git://github.com/phalcon/phalcon-devtools.git
第二步, cd phpalcon-devtools, 执行./phalcon.sh
第三步,这里一步我如果按照文档上是
ln -s ~/phalcon-devtools/phalcon.php /usr/bin/phalcon
chmod ugo+x /usr/bin/phalcon
这里可能会报错,无法创建符号链接,其实不用那么麻烦,直接按照安装完成的提示去操作就行了
输入
source /root/.bash_profile
如无意外你就可以使用相关命令了
$ phalcon commands
Phalcon DevTools (3.0.0)
Available commands:可用命令
commands (alias of: list, enumerate)
controller (alias of: create-controller)
module (alias of: create-module)
model (alias of: create-model)
all-models (alias of: create-all-models)
project (alias of: create-project)
scaffold (alias of: create-scaffold)
migration (alias of: create-migration)
webtools (alias of: create-webtools)
配置nginx支持phalcon,我这里是按照
https://docs.phalconphp.com/zh/latest/webserver-setup#nginx 这里去配置的,一切顺利。
server{
listen 80;
server_name www.testph.com; #这是我自己配置的虚拟域名,往后你在电脑配置一下host文件就可以访问了
root /var/www/html/store/public;
index index.php index.html index.htm;
charset utf-8;
client_max_body_size 100M;
fastcgi_read_timeout 1800;
location / {
# 这里使用$_GET来匹配路径
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
location ~ [^/]\.php(/|$) {
#因为我php-fpm没有去配置,所以用这种设置方法
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
# and set php.ini cgi.fix_pathinfo=0
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
#静态资源的配置
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
access_log off;
}
}
配置保存好之后重启一下nginx, systemctl reload nginx
最后配置phpstorm 支持phlaocn
去 https://github.com/phalcon/phalcon-devtools/releases 下载。解压,不要放在中文路径目录下。
在 ide/gen-stubs.php 文件中的如下三行代码注释掉:
//if (!file_exists(CPHALCON_DIR)) {
// throw new Exception(“CPHALCON directory does not exist”);
//}
然后执行如下命令:
php gen-stubs.php
成功后,会看到 ide 目录下生成了对应的工具库的
我的phalcontools\ide\stubs\Phalcon
然后在
应用确定就可以了(我本地开发的环境是php5.6,请忽略掉,选你自己的)
这样算是大功告成了,在浏览器输入虚拟的域名访问应该没问题了。