到官方下載(以1.12.3 version為例),然後解壓縮:
wget https://packages.zendframework.com/releases/ZendFramework-1.12.3/ZendFramework-1.12.3.zip unzip ZendFramework-1.12.3.zip
建置project和copy library:
./ZendFramework-1.12.3/bin/zf.sh project newproject cp -r ./ZendFramework-1.12.3/library ./newproject/library
會產生以下檔案及目錄:
. |-- application | |-- Bootstrap.php | |-- configs | |-- controllers | |-- models | `-- views |-- docs | `-- README.txt |-- library | `-- Zend |-- public | `-- index.php `-- tests |-- application |-- bootstrap.php |-- library `-- phpunit.xml
最後在配置server(apache、nginx…)即可,以下是用nginx設定:
server { listen 80; server_name localhost; #path:/etc/nginx/sites-enabled/default root /var/www/newproject; index index.html index.htm index.php; location / { if (!-f $request_filename) { rewrite "^(.*)$" /public/index.php?q=$1 last; break; } } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/newproject$fastcgi_script_name; include fastcgi_params; } }
從上方配置可看到,使用$request_filename,判斷該檔案路徑存不存在,將所有不存在的url導向index.php,在由index.php去分派給controller,如果存在則直接導向該檔案。
最後打開http://localhost就可以看到配置好的project首頁了。