Mac从零安装yaf

加入了新的团队,团队中用到了yaf这个php web framework(听说是目前php web框架中性能最高的),本身也开始学了起来。由于本身以前几乎没有接触过PHP,因此安装yaf的整个过程仍是略显艰辛的。通过本身的折腾和同事的帮忙,终于在Mac上成功安装了yaf,感受须要写一篇简易教程记录一下,以防本身和他人从此再踩坑。php

步骤1:安装XAMPP

XAMPP是Apache + MySQL + PHP + Perl的一键傻瓜安装包,在官网上安装Mac版的安装包。安装完毕以后,打开http://127.0.0.1/,若是看到了xampp的欢迎页面,说明就成功了。
html

好了,咱们须要的Apache和PHP都安装好了,这些先放着,开始安装yafgit

步骤2:安装yaf

先在yaf官网上面下载最新的源码,而后按照官网上的教程进行安装。其实就是这四个命令:github

$PHP_BIN/phpize
./configure --with-php-config=$PHP_BIN/php-config
make
make install

须要注意两个问题:web

  1. $PHP_BIN指的是php所在的bin目录,并且必定要是以前XAMPP安装的php的bin目录,也就是/Applications/XAMPP/bin/
  2. 若是出现权限问题,须要在命令前面加上sudo

make install以后,系统会告诉你编译出一个yaf.so,而且存放在某个文件夹下面,咱们要的就是这个文件。具体存放在哪你能够不用关心,由于php是知道在哪的。接下来,将yaf.so加入配置文件php.ini中。apache

vi /Applications/XAMPP/etc/php.ini

加入如下语句:框架

extension=yaf.so

使用php -m,查看yaf是否已经加入phpide

/Applications/XAMPP/bin/php -m
[PHP Modules]
……
省略一些模块
……
xmlwriter
xsl
yaf
zip
zlib

[Zend Modules]

若是看到了yaf,就说明yaf这个模块已经载入成功了。工具

步骤3:生成一份sample应用

按照yaf官网上面的教程,生成一份样例的yaf应用,具体步骤以下:性能

下载php-yaf源码

git clone https://github.com/laruence/php-yaf/

运行代码生成工具

$PHP_YAF_SRC/tools/cg/yaf_cg sample

将sample文件夹存在一个单独的路径,用做Apache的virtual host的根目录,好比我就放在了/Users/Quxiao/dev/apache_virital_root/sample这个路径。

步骤4:配置Apache

编辑virtual host配置文件

vi /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf

将其中的8080端口的<VirtualHost>配置改掉,修改端口以及DocumentRoot,例如

#端口能够改为本身想要的端口
<VirtualHost *:8081>
    ServerAdmin webmaster@dummy-host2.example.com
    #该路径就是上一步样例yaf应用的路径
    DocumentRoot "/Users/Quxiao/dev/apache_virital_root/sample"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

编辑Apache配置文件

vi /Applications/XAMPP/xamppfiles/etc/httpd.conf

加入上面virtual host的配置,在文件中查找,去掉Include前的注释符号#

# Virtual hosts
Include etc/extra/httpd-vhosts.conf

开启virtual host的端口

#Listen 12.34.56.78:80
Listen 80

# 添加8081端口
Listen 8081

添加访问权限配置,加入如下内容:

<Directory "/Users/Quxiao/dev/apache_virital_root/sample">
    #   
    # Possible values for the Options directive are "None", "All",
    # or any combination of: 
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #   
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #   
    # The Options directive is both complicated and important.  Please see 
    # http://httpd.apache.org/docs/trunk/mod/core.html#options
    # for more information.
    #   
    #Options Indexes FollowSymLinks
    # XAMPP
    Options Indexes FollowSymLinks ExecCGI Includes

    #   
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #   
    #AllowOverride None
    # since XAMPP 1.4:
    AllowOverride All 

    #   
    # Controls who can get stuff from this server.
    #   
    Require all granted
</Directory>

其实就是将本来已有的<Deirectory>部分复制一份,而后把路径改为以前设置的virtual host的DocumentRoot

步骤5:重启Apache并访问yaf应用

在Launchpad中开发XAMPP的管理器,在Manager Servers中将Apache重启

激动人心的时刻到了,访问http://127.0.0.1:8081/,看是否出现了

Hello World! I am Stranger

若是出现了,就表示你已经在Mac上成功安装了yaf!

-- EOF --

相关文章
相关标签/搜索