| 1 | Apigility Skeleton Application
|
|---|
| 2 | ==============================
|
|---|
| 3 |
|
|---|
| 4 | Requirements
|
|---|
| 5 | ------------
|
|---|
| 6 |
|
|---|
| 7 | Please see the [composer.json](composer.json) file.
|
|---|
| 8 |
|
|---|
| 9 | Installation
|
|---|
| 10 | ------------
|
|---|
| 11 |
|
|---|
| 12 | ### Via release tarball
|
|---|
| 13 |
|
|---|
| 14 | Grab the latest release via the [Apigility website](http://apigility.org/)
|
|---|
| 15 | and/or the [releases page](https://github.com/zfcampus/zf-apigility-skeleton/releases); each release
|
|---|
| 16 | has distribution tarballs and zipballs available.
|
|---|
| 17 |
|
|---|
| 18 | Untar it:
|
|---|
| 19 |
|
|---|
| 20 | ```bash
|
|---|
| 21 | $ tar xzf zf-apigility-skeleton-{version}.tgz
|
|---|
| 22 | ```
|
|---|
| 23 |
|
|---|
| 24 | (Where `{version}` is the version you downloaded.)
|
|---|
| 25 |
|
|---|
| 26 | Or unzip, if you chose the zipball:
|
|---|
| 27 |
|
|---|
| 28 | ```bash
|
|---|
| 29 | $ unzip zf-apigility-skeleton-{version}.zip
|
|---|
| 30 | ```
|
|---|
| 31 |
|
|---|
| 32 | (Where `{version}` is the version you downloaded.)
|
|---|
| 33 |
|
|---|
| 34 | ### Via Composer (create-project)
|
|---|
| 35 |
|
|---|
| 36 | You can use the `create-project` command from [Composer](http://getcomposer.org/)
|
|---|
| 37 | to create the project in one go (you need to install [composer](https://getcomposer.org/doc/00-intro.md#downloading-the-composer-executable)):
|
|---|
| 38 |
|
|---|
| 39 | ```bash
|
|---|
| 40 | $ curl -s https://getcomposer.org/installer | php -- --filename=composer
|
|---|
| 41 | $ composer create-project -sdev zfcampus/zf-apigility-skeleton path/to/install
|
|---|
| 42 | ```
|
|---|
| 43 |
|
|---|
| 44 | ### Via Git (clone)
|
|---|
| 45 |
|
|---|
| 46 | First, clone the repository:
|
|---|
| 47 |
|
|---|
| 48 | ```bash
|
|---|
| 49 | # git clone https://github.com/zfcampus/zf-apigility-skeleton.git # optionally, specify the directory in which to clone
|
|---|
| 50 | $ cd path/to/install
|
|---|
| 51 | ```
|
|---|
| 52 |
|
|---|
| 53 | At this point, you need to use [Composer](https://getcomposer.org/) to install
|
|---|
| 54 | dependencies. Assuming you already have Composer:
|
|---|
| 55 |
|
|---|
| 56 | ```bash
|
|---|
| 57 | $ composer install
|
|---|
| 58 | ```
|
|---|
| 59 |
|
|---|
| 60 | ### All methods
|
|---|
| 61 |
|
|---|
| 62 | Once you have the basic installation, you need to put it in development mode:
|
|---|
| 63 |
|
|---|
| 64 | ```bash
|
|---|
| 65 | $ cd path/to/install
|
|---|
| 66 | $ composer development-enable
|
|---|
| 67 | ```
|
|---|
| 68 |
|
|---|
| 69 | Now, fire it up! Do one of the following:
|
|---|
| 70 |
|
|---|
| 71 | - Create a vhost in your web server that points the DocumentRoot to the
|
|---|
| 72 | `public/` directory of the project
|
|---|
| 73 | - Fire up the built-in web server in PHP(**note**: do not use this for
|
|---|
| 74 | production!)
|
|---|
| 75 |
|
|---|
| 76 | In the latter case, do the following:
|
|---|
| 77 |
|
|---|
| 78 | ```bash
|
|---|
| 79 | $ cd path/to/install
|
|---|
| 80 | $ php -S 0.0.0.0:8080 -ddisplay_errors=0 -t public public/index.php
|
|---|
| 81 | # OR use the composer alias:
|
|---|
| 82 | $ composer serve
|
|---|
| 83 | ```
|
|---|
| 84 |
|
|---|
| 85 | You can then visit the site at http://localhost:8080/ - which will bring up a
|
|---|
| 86 | welcome page and the ability to visit the dashboard in order to create and
|
|---|
| 87 | inspect your APIs.
|
|---|
| 88 |
|
|---|
| 89 | ### NOTE ABOUT USING APACHE
|
|---|
| 90 |
|
|---|
| 91 | Apache forbids the character sequences `%2F` and `%5C` in URI paths. However, the Apigility Admin
|
|---|
| 92 | API uses these characters for a number of service endpoints. As such, if you wish to use the
|
|---|
| 93 | Admin UI and/or Admin API with Apache, you will need to configure your Apache vhost/project to
|
|---|
| 94 | allow encoded slashes:
|
|---|
| 95 |
|
|---|
| 96 | ```apacheconf
|
|---|
| 97 | AllowEncodedSlashes On
|
|---|
| 98 | ```
|
|---|
| 99 |
|
|---|
| 100 | This change will need to be made in your server's vhost file (it cannot be added to `.htaccess`).
|
|---|
| 101 |
|
|---|
| 102 | ### NOTE ABOUT OPCACHE
|
|---|
| 103 |
|
|---|
| 104 | **Disable all opcode caches when running the admin!**
|
|---|
| 105 |
|
|---|
| 106 | The admin cannot and will not run correctly when an opcode cache, such as APC or
|
|---|
| 107 | OpCache, is enabled. Apigility does not use a database to store configuration;
|
|---|
| 108 | instead, it uses PHP configuration files. Opcode caches will cache these files
|
|---|
| 109 | on first load, leading to inconsistencies as you write to them, and will
|
|---|
| 110 | typically lead to a state where the admin API and code become unusable.
|
|---|
| 111 |
|
|---|
| 112 | The admin is a **development** tool, and intended for use a development
|
|---|
| 113 | environment. As such, you should likely disable opcode caching, regardless.
|
|---|
| 114 |
|
|---|
| 115 | When you are ready to deploy your API to **production**, however, you can
|
|---|
| 116 | disable development mode, thus disabling the admin interface, and safely run an
|
|---|
| 117 | opcode cache again. Doing so is recommended for production due to the tremendous
|
|---|
| 118 | performance benefits opcode caches provide.
|
|---|
| 119 |
|
|---|
| 120 | ### NOTE ABOUT DISPLAY_ERRORS
|
|---|
| 121 |
|
|---|
| 122 | The `display_errors` `php.ini` setting is useful in development to understand what warnings,
|
|---|
| 123 | notices, and error conditions are affecting your application. However, they cause problems for APIs:
|
|---|
| 124 | APIs are typically a specific serialization format, and error reporting is usually in either plain
|
|---|
| 125 | text, or, with extensions like XDebug, in HTML. This breaks the response payload, making it unusable
|
|---|
| 126 | by clients.
|
|---|
| 127 |
|
|---|
| 128 | For this reason, we recommend disabling `display_errors` when using the Apigility admin interface.
|
|---|
| 129 | This can be done using the `-ddisplay_errors=0` flag when using the built-in PHP web server, or you
|
|---|
| 130 | can set it in your virtual host or server definition. If you disable it, make sure you have
|
|---|
| 131 | reasonable error log settings in place. For the built-in PHP web server, errors will be reported in
|
|---|
| 132 | the console itself; otherwise, ensure you have an error log file specified in your configuration.
|
|---|
| 133 |
|
|---|
| 134 | `display_errors` should *never* be enabled in production, regardless.
|
|---|
| 135 |
|
|---|
| 136 | ### Vagrant
|
|---|
| 137 |
|
|---|
| 138 | If you prefer to develop with Vagrant, there is a basic vagrant recipe included with this project.
|
|---|
| 139 |
|
|---|
| 140 | This recipe assumes that you already have Vagrant installed. The virtual machine will try to use localhost:8080 by
|
|---|
| 141 | default, so if you already have a server on this port of your host machine, you need to shut down the conflicting
|
|---|
| 142 | server first, or if you know how, you can reconfigure the ports in Vagrantfile.
|
|---|
| 143 |
|
|---|
| 144 | Assuming you have Vagrant installed and assuming you have no port conflicts, you can bring up the Vagrant machine
|
|---|
| 145 | with the standard `up` command:
|
|---|
| 146 |
|
|---|
| 147 | ```bash
|
|---|
| 148 | $ vagrant up
|
|---|
| 149 | ```
|
|---|
| 150 |
|
|---|
| 151 | When the machine comes up, you can ssh to it with the standard ssh forward agent:
|
|---|
| 152 |
|
|---|
| 153 | ```bash
|
|---|
| 154 | $ vagrant ssh
|
|---|
| 155 | ```
|
|---|
| 156 |
|
|---|
| 157 | The web root is inside the shared directory, which is at `/var/www`; this is
|
|---|
| 158 | also the home directory for the vagrant issue, which will be the initial
|
|---|
| 159 | directory you land in once you connect via SSH.
|
|---|
| 160 |
|
|---|
| 161 | The image installs composer during provisioning, meaning you can use it to
|
|---|
| 162 | install and update dependencies:
|
|---|
| 163 |
|
|---|
| 164 | ```bash
|
|---|
| 165 | # Install dependencies:
|
|---|
| 166 | $ vagrant ssh -c 'composer install'
|
|---|
| 167 | # Update dependencies:
|
|---|
| 168 | $ vagrant ssh -c 'composer update'
|
|---|
| 169 | ```
|
|---|
| 170 |
|
|---|
| 171 | You can also manipulate development mode:
|
|---|
| 172 |
|
|---|
| 173 | ```bash
|
|---|
| 174 | $ vagrant ssh -c 'composer development-enable'
|
|---|
| 175 | $ vagrant ssh -c 'composer development-disable'
|
|---|
| 176 | $ vagrant ssh -c 'composer development-status'
|
|---|
| 177 | ```
|
|---|
| 178 |
|
|---|
| 179 | > #### Vagrant and VirtualBox
|
|---|
| 180 | >
|
|---|
| 181 | > The vagrant image is based on `bento/ubuntu-16.04`. If you are using VirtualBox as
|
|---|
| 182 | > a provider, you will need:
|
|---|
| 183 | >
|
|---|
| 184 | > - Vagrant 1.8.5 or later
|
|---|
| 185 | > - VirtualBox 5.0.26 or later
|
|---|
| 186 |
|
|---|
| 187 | For vagrant documentation, please refer to [vagrantup.com](https://www.vagrantup.com/)
|
|---|
| 188 |
|
|---|
| 189 | ### Docker
|
|---|
| 190 |
|
|---|
| 191 | If you develop or deploy using Docker, we provide configuration for you.
|
|---|
| 192 |
|
|---|
| 193 | Prepare your development environment using [docker compose](https://docs.docker.com/compose/install/):
|
|---|
| 194 |
|
|---|
| 195 | ```bash
|
|---|
| 196 | $ git clone https://github.com/zfcampus/zf-apigility-skeleton
|
|---|
| 197 | $ cd zf-apigility-skeleton
|
|---|
| 198 | $ docker-compose build
|
|---|
| 199 | # Install dependencies via composer, if you haven't already:
|
|---|
| 200 | $ docker-compose run apigility composer install
|
|---|
| 201 | # Enable development mode:
|
|---|
| 202 | $ docker-compose run apigility composer development-enable
|
|---|
| 203 | ```
|
|---|
| 204 |
|
|---|
| 205 | Start the container:
|
|---|
| 206 |
|
|---|
| 207 | ```bash
|
|---|
| 208 | $ docker-compose up
|
|---|
| 209 | ```
|
|---|
| 210 |
|
|---|
| 211 | Access Apigility from `http://localhost:8080/` or `http://<boot2docker ip>:8080/` if on Windows or Mac.
|
|---|
| 212 |
|
|---|
| 213 | You may also use the provided `Dockerfile` directly if desired.
|
|---|
| 214 |
|
|---|
| 215 | Once installed, you can use the container to update dependencies:
|
|---|
| 216 |
|
|---|
| 217 | ```bash
|
|---|
| 218 | $ docker-compose run apigility composer update
|
|---|
| 219 | ```
|
|---|
| 220 |
|
|---|
| 221 | Or to manipulate development mode:
|
|---|
| 222 |
|
|---|
| 223 | ```bash
|
|---|
| 224 | $ docker-compose run apigility composer development-enable
|
|---|
| 225 | $ docker-compose run apigility composer development-disable
|
|---|
| 226 | $ docker-compose run apigility composer development-status
|
|---|
| 227 | ```
|
|---|
| 228 |
|
|---|
| 229 | QA Tools
|
|---|
| 230 | --------
|
|---|
| 231 |
|
|---|
| 232 | The skeleton ships with minimal QA tooling by default, including
|
|---|
| 233 | zendframework/zend-test. We supply basic tests for the shipped
|
|---|
| 234 | `Application\Controller\IndexController`.
|
|---|
| 235 |
|
|---|
| 236 | We also ship with configuration for [phpcs](https://github.com/squizlabs/php_codesniffer).
|
|---|
| 237 | If you wish to add this QA tool, execute the following:
|
|---|
| 238 |
|
|---|
| 239 | ```bash
|
|---|
| 240 | $ composer require --dev squizlabs/php_codesniffer
|
|---|
| 241 | ```
|
|---|
| 242 |
|
|---|
| 243 | We provide aliases for each of these tools in the Composer configuration:
|
|---|
| 244 |
|
|---|
| 245 | ```bash
|
|---|
| 246 | # Run CS checks:
|
|---|
| 247 | $ composer cs-check
|
|---|
| 248 | # Fix CS errors:
|
|---|
| 249 | $ composer cs-fix
|
|---|
| 250 | # Run PHPUnit tests:
|
|---|
| 251 | $ composer test
|
|---|
| 252 | ```
|
|---|