编程技术记录

世界你好!

参考连接
1、https://docs.phalcon.io/3.4/en/installation
2、http://phalcondoc.p2hp.com/zh/3.4
3、https://github.com/phalcon/phalcon-devtools

最终环境

  • ubuntu 18.04.1
  • nginx 1.14.0 (Ubuntu)
  • php7.3 和 php7.3-fpm
  • phalcon3.4.4-1

安装nginx

如果已经安装,请忽略

sudo apt-get install nginx

安装php和php-fpm

如果已经安装,请忽略

添加php源

sudo apt-add-repository ppa:ondrej/php
sudo apt-get update

安装

#安装php7.3
sudo apt-get install php7.3
#安装php-fpm
sudo apt-get install php-fpm

安装phalcon

sudo apt-get install php7.3-phalcon

重启php-fpm

这个步骤是要把phalcon模块注册到php-fpm

sudo systemctl reload  php7.3-fpm.service

安装phalcon-devtools(脚手架)

从git安装

#下载
git clone --depth=1 https://github.com/phalcon/phalcon-devtools.git

#进入目录
cd phalcon-devtools/

#创建软连接
sudo ln -s $(pwd)/phalcon /usr/bin/phalcon
#修改权限
sudo chmod ugo+x /usr/bin/phalcon

#执行命令,查看是否安装成功
phalcon commands help

如果提示"phalcon: command not found"
尝试命令

sudo  alias phalcon=git仓库下载目录/phalcon-devtools/phalcon

用phalcon-devtools创建一个phalcon项目

phalcon  create-project  test

配置虚拟主机(web服务)

进入 /etc/nginx/sites-available ,创建一个nginx虚拟主机服务test.conf

sudo vim /etc/nginx/sites-available/test.conf

内容如下

server {

    #端口
    listen        8080;
    #域名或IP地址均可
    server_name   default;

    # 注意路径为使用phalcon-devtools创建后的路径,包括public目录
    root  phalcon工程目录/test/public;
    index index.php index.html index.htm;

    charset utf-8;
    client_max_body_size 1M;
    fastcgi_read_timeout 1800;

    # Represents the root of the domain
    # http://localhost:8000/[index.php]
    location / {
        # Matches URLS `$_GET['_url']`
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }

    # When the HTTP request does not match the above
    # and the file ends in .php
    location ~ [^/]\.php(/|$) {
        # try_files $uri =404;

        #unix socket 路径参见 /etc/php/7.3/fpm/pool.d/www.conf
        fastcgi_pass  unix:/run/php/php7.3-fpm.sock;

        fastcgi_index /index.php;

        include fastcgi_params;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        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;
    }
}

好了,用浏览器打开http://servername:8080 看看

© Beli. All Rights Reserved.