Install Apigility skeleton app in remote directory

From IBM i command line:

CALL QP2TERM

Change to /www directory

cd /www

Make php executable available via the PATH environment variable

export PATH=$PATH:/usr/local/zendsvr6/bin

If you’re running php 5.6 then install SSL certificates

mkdir /phpsslcert
php -r "readfile('http://curl.haxx.se/ca/cacert.pem');" > /phpsslcert/cert.pem

In php.ini set the following

openssl.cafile="/phpsslcert/cert.pem"

Install Apigility skeleton app.

php -r "readfile('https://apigility.org/install');" | php

Rename apigility directory to “AcmeAPI”

mv /www/apigility /www/AcmeAPI

Set proper data authorities (IMPORTANT!)

From IBM i command line:

CHGAUT OBJ('/www/AcmeAPI/module') USER(QTMHHTTP) DTAAUT(*RWX) OBJAUT(*NONE) SUBTREE(*ALL)
CHGAUT OBJ('/www/AcmeAPI/config') USER(QTMHHTTP) DTAAUT(*RWX) OBJAUT(*NONE) SUBTREE(*ALL)

These write permissions are only necessary during development. Not needed in production.

Turn off PHP configuration caching for this app

Turn off opcache for this app

Create blacklist file for opcache:

From PASE (QP2TERM) command line:

touch /www/zendsvr6/conf/opcache_blacklist.txt

Include php configuration files in blacklist

From IBM i command line:

EDTF STMF('/www/zendsvr6/conf/opcache_blacklist.txt')

Add the following lines to the file:

/www/AcmeAPI/module/*
/www/AcmeAPI/config/*

From IBM i command line:

EDTF STMF('/usr/local/zendsvr6/etc/php.ini')

Uncomment the opcache.blacklist_filename setting and set it equal to

 /www/zendsvr6/conf/opcache_blacklist.txt

Thus the php.ini setting should look like this:

opcache.blacklist_filename=/www/zendsvr6/conf/opcache_blacklist.txt

Turn off apc cache globally

From IBM i command line:

EDTF STMF('/usr/local/zendsvr6/etc/conf.d/datacache.ini')

Set the zend_datacache.apc_compatibility equal to “0” so that it should appear as follows:

zend_datacache.apc_compatibility=0

Add virtual host to Apache configuration

Add Apache Virtual Host to /www/zendsvr6/conf/httpd.conf. Replace the server ip and port with your own information.

# Acme API Listen *:[port]
NameVirtualHost *:[port]
<VirtualHost *:[port]>
    ServerName [server ip]:[port]
    DocumentRoot "/www/AcmeAPI/public"
    SetEnv APPLICATION_ENV "development"
    AllowEncodedSlashes On 

    # Tell apache to serve index.php if the requested resource doesn't exist 
    # This allows static files to be served directly while "ZF-friendly URLS"
    # are sent to index.php # Doing so is necessary to enable the front controller pattern adhered to by ZF 
    RewriteEngine on
    <Location />
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d 
        RewriteRule ^.*$ - [NC,L]
        RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
        RewriteRule ^(.*) - [E=BASE:%1]
        RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
    </Location>

    # Tell apache which file to serve when no file name is specified
    # This allows you to access the API with [server ip]:[port]/ rather
    # than having to specify [server ip]:[port]/index.php
    <Directory "/www/AcmeAPI/public">
        Options Indexes MultiViews FollowSymLinks
        DirectoryIndex index.php
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Restart Zend Server

This applies the cache configuration changes to PHP and makes the Apache virtual host accessible.

Access Apigility admin UI

In your browser navigate to http://[server ip]:[vhost port]/

This brings you to Apigility welcome screen. Click “Get Started!” button to be taken to admin UI.

If the Apigility welcome screen isn’t displayed then you may need to set the project to “development” mode.

From PASE (QP2TERM) command line:

export PATH=$PATH:/usr/local/zendsvr6/bin
php public/index.php development enable

This creates a file at config/development.config.php and also grants access to the apigility ui from the browser. Of course you don’t want the ui to be accessible in production.

Add config/development.config.php to .gitignore (if you’re using Git)