PhalApi框架安装与使用

全局安装composer(方便全局访问)

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/
mv composer.phar /usr/local/bin/composer

–install-dir 选项指定 Composer 的安装目录(它可以是一个绝对或相对路径)
注意: 如果上诉命令因为权限执行失败, 请使用 sudo 再次尝试运行 mv 那行命令。

现在只需要运行 composer 命令就可以使用 Composer 而不需要输入 php composer.phar。
更多composer的使用命令,参考 https://www.phpcomposer.com/

快速安装PhalApi

composer一键安装

composer create-project phalapi/phalapi

手动下载安装

或者,也可以进行手动安装。首先下载phalapi项目master-2x分支源代码。下载解压后,进行可选的composer更新,即:

composer update

使用以上命令,可能会遇到以下提示

Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)

第一句可以切换到非root用户运行
另两个可以更换镜像源

composer config -g repo.packagist composer https://packagist.phpcomposer.com

参考:https://pkg.phpcomposer.com/
再执行

composer update

运行结果

Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files

Nginx配置

server {
    listen 80;
    server_name my.phalapi.net;
    root /www/phalapi/public;
    charset utf-8;

    location / {
        index index.php;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    access_log /logs/my.phalapi.net.access.log;
    error_log /logs/my.phalapi.net.error.log;
}

重启Nginx并配置本地HOSTS后,访问

http://my.phalapi.net/

可以看到输出结果

{
    "ret": 200,
    "data": {
        "title": "Hello PhalApi",
        "version": "2.2.2",
        "time": 1524039339
    },
    "msg": ""
}

至此,安装完毕!

你可能感兴趣的:(php,Composer,Phalapi)