|
1 | | -ZendSkeletonApplication |
2 | | -======================= |
| 1 | +# ZendSkeletonApplication |
3 | 2 |
|
4 | | -Introduction |
5 | | ------------- |
6 | | -This is a simple, skeleton application using the ZF2 MVC layer and module |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This is a skeleton application using the Zend Framework MVC layer and module |
7 | 6 | systems. This application is meant to be used as a starting place for those |
8 | | -looking to get their feet wet with ZF2. |
| 7 | +looking to get their feet wet with Zend Framework. |
9 | 8 |
|
10 | | -Installation using Composer |
11 | | ---------------------------- |
| 9 | +## Installation using Composer |
12 | 10 |
|
13 | | -The easiest way to create a new ZF2 project is to use [Composer](https://getcomposer.org/). If you don't have it already installed, then please install as per the [documentation](https://getcomposer.org/doc/00-intro.md). |
| 11 | +The easiest way to create a new Zend Framework project is to use |
| 12 | +[Composer](https://getcomposer.org/). If you don't have it already installed, |
| 13 | +then please install as per the [documentation](https://getcomposer.org/doc/00-intro.md). |
14 | 14 |
|
| 15 | +To create your new Zend Framework project: |
15 | 16 |
|
16 | | -Create your new ZF2 project: |
| 17 | +```bash |
| 18 | +$ composer create-project -sdev zendframework/skeleton-application path/to/install |
| 19 | +``` |
17 | 20 |
|
18 | | - composer create-project -n -sdev zendframework/skeleton-application path/to/install |
| 21 | +Once installed, you can test it out immediately using PHP's built-in web server: |
19 | 22 |
|
| 23 | +```bash |
| 24 | +$ php -S 0.0.0.0:8080 -t public/ public/index.php |
| 25 | +``` |
20 | 26 |
|
| 27 | +This will start the cli-server on port 8080, and bind it to all network |
| 28 | +interfaces. |
21 | 29 |
|
22 | | -### Installation using a tarball with a local Composer |
| 30 | +**Note:** The built-in CLI server is *for development only*. |
23 | 31 |
|
24 | | -If you don't have composer installed globally then another way to create a new ZF2 project is to download the tarball and install it: |
| 32 | +## Development mode |
25 | 33 |
|
26 | | -1. Download the [tarball](https://github.com/zendframework/ZendSkeletonApplication/tarball/master), extract it and then install the dependencies with a locally installed Composer: |
| 34 | +The skeleton ships with [zf-development-mode](https://github.com/zfcampus/zf-development-mode) |
| 35 | +by default, and provides three aliases for consuming the script it ships with: |
27 | 36 |
|
28 | | - cd my/project/dir |
29 | | - curl -#L https://github.com/zendframework/ZendSkeletonApplication/tarball/master | tar xz --strip-components=1 |
30 | | - |
| 37 | +```bash |
| 38 | +$ composer development-enable # enable development mode |
| 39 | +$ composer development-disable # enable development mode |
| 40 | +$ composer development-status # whether or not development mode is enabled |
| 41 | +``` |
31 | 42 |
|
32 | | -2. Download composer into your project directory and install the dependencies: |
| 43 | +You may provide development-only modules and bootstrap-level configuration in |
| 44 | +`config/development.config.php.dist`, and development-only application |
| 45 | +configuration in `config/autoload/development.local.php.dist`. Enabling |
| 46 | +development mode will copy these files to versions removing the `.dist` suffix, |
| 47 | +while disabling development mode will remove those copies. |
33 | 48 |
|
34 | | - curl -s https://getcomposer.org/installer | php |
35 | | - php composer.phar install |
| 49 | +## Running Unit Tests |
36 | 50 |
|
37 | | -If you don't have access to curl, then install Composer into your project as per the [documentation](https://getcomposer.org/doc/00-intro.md). |
| 51 | +To run the supplied skeleton unit tests, you need to do one of the following: |
38 | 52 |
|
39 | | -Web server setup |
40 | | ----------------- |
| 53 | +- During initial project creation, select to install the MVC testing support. |
| 54 | +- After initial project creation, install [zend-test](https://zendframework.github.io/zend-test/): |
41 | 55 |
|
42 | | -### PHP CLI server |
| 56 | + ```bash |
| 57 | + $ composer require --dev zendframework/zend-test |
| 58 | + ``` |
43 | 59 |
|
44 | | -The simplest way to get started if you are using PHP 5.4 or above is to start the internal PHP cli-server in the root |
45 | | -directory: |
| 60 | +Once testing support is present, you can run the tests using: |
46 | 61 |
|
47 | | - php -S 0.0.0.0:8080 -t public/ public/index.php |
| 62 | +```bash |
| 63 | +$ ./vendor/bin/phpunit |
| 64 | +``` |
48 | 65 |
|
49 | | -This will start the cli-server on port 8080, and bind it to all network |
50 | | -interfaces. |
| 66 | +If you need to make local modifications for the PHPUnit test setup, copy |
| 67 | +`phpunit.xml.dist` to `phpunit.xml` and edit the new file; the latter has |
| 68 | +precedence over the former when running tests, and is ignored by version |
| 69 | +control. (If you want to make the modifications permanent, edit the |
| 70 | +`phpunit.xml.dist` file.) |
51 | 71 |
|
52 | | -**Note:** The built-in CLI server is *for development only*. |
| 72 | +## Using Vagrant |
| 73 | + |
| 74 | +This skeleton includes a `Vagrantfile` based on ubuntu 14.04, and using the |
| 75 | +ondrej/php PPA to provide PHP 7.0. Start it up using: |
| 76 | + |
| 77 | +```bash |
| 78 | +$ vagrant up |
| 79 | +``` |
| 80 | + |
| 81 | +Once built, you can also run composer within the box. For example, the following |
| 82 | +will install dependencies: |
53 | 83 |
|
54 | | -### Vagrant server |
| 84 | +```bash |
| 85 | +$ vagrant ssh -c 'composer install' |
| 86 | +``` |
55 | 87 |
|
56 | | -This project supports a basic [Vagrant](http://docs.vagrantup.com/v2/getting-started/index.html) configuration with an inline shell provisioner to run the Skeleton Application in a [VirtualBox](https://www.virtualbox.org/wiki/Downloads). |
| 88 | +While this will update them: |
57 | 89 |
|
58 | | -1. Run vagrant up command |
| 90 | +```bash |
| 91 | +$ vagrant ssh -c 'composer update' |
| 92 | +``` |
59 | 93 |
|
60 | | - vagrant up |
| 94 | +While running, Vagrant maps your host port 8080 to port 80 on the virtual |
| 95 | +machine; you can visit the site at http://localhost:8080/ |
61 | 96 |
|
62 | | -2. Visit [http://localhost:8085](http://localhost:8085) in your browser |
| 97 | +## Using docker-compose |
63 | 98 |
|
64 | | -Look in [Vagrantfile](Vagrantfile) for configuration details. |
| 99 | +This skeleton provides a `docker-compose.yml` for use with |
| 100 | +[docker-compose](https://docs.docker.com/compose/); it |
| 101 | +uses the `Dockerfile` provided as its base. Build and start the image using: |
| 102 | + |
| 103 | +```bash |
| 104 | +$ docker-compose up -d --build |
| 105 | +``` |
| 106 | + |
| 107 | +At this point, you can visit http://localhost:8080 to see the site running. |
| 108 | + |
| 109 | +You can also run composer from the image. The container environment is named |
| 110 | +"zf", so you will pass that value to `docker-compose run`: |
| 111 | + |
| 112 | +```bash |
| 113 | +$ docker-compose run zf composer install |
| 114 | +``` |
| 115 | + |
| 116 | +## Web server setup |
65 | 117 |
|
66 | 118 | ### Apache setup |
67 | 119 |
|
68 | 120 | To setup apache, setup a virtual host to point to the public/ directory of the |
69 | 121 | project and you should be ready to go! It should look something like below: |
70 | 122 |
|
71 | | - <VirtualHost *:80> |
72 | | - ServerName zf2-app.localhost |
73 | | - DocumentRoot /path/to/zf2-app/public |
74 | | - <Directory /path/to/zf2-app/public> |
75 | | - DirectoryIndex index.php |
76 | | - AllowOverride All |
77 | | - Order allow,deny |
78 | | - Allow from all |
79 | | - <IfModule mod_authz_core.c> |
80 | | - Require all granted |
81 | | - </IfModule> |
82 | | - </Directory> |
83 | | - </VirtualHost> |
| 123 | +```apache |
| 124 | +<VirtualHost *:80> |
| 125 | + ServerName zf2-app.localhost |
| 126 | + DocumentRoot /path/to/zf2-app/public |
| 127 | + <Directory /path/to/zf2-app/public> |
| 128 | + DirectoryIndex index.php |
| 129 | + AllowOverride All |
| 130 | + Order allow,deny |
| 131 | + Allow from all |
| 132 | + <IfModule mod_authz_core.c> |
| 133 | + Require all granted |
| 134 | + </IfModule> |
| 135 | + </Directory> |
| 136 | +</VirtualHost> |
| 137 | +``` |
84 | 138 |
|
85 | 139 | ### Nginx setup |
86 | 140 |
|
87 | 141 | To setup nginx, open your `/path/to/nginx/nginx.conf` and add an |
88 | 142 | [include directive](http://nginx.org/en/docs/ngx_core_module.html#include) below |
89 | 143 | into `http` block if it does not already exist: |
90 | 144 |
|
91 | | - http { |
92 | | - # ... |
93 | | - include sites-enabled/*.conf; |
94 | | - } |
| 145 | +```nginx |
| 146 | +http { |
| 147 | + # ... |
| 148 | + include sites-enabled/*.conf; |
| 149 | +} |
| 150 | +``` |
95 | 151 |
|
96 | 152 |
|
97 | 153 | Create a virtual host configuration file for your project under `/path/to/nginx/sites-enabled/zf2-app.localhost.conf` |
98 | 154 | it should look something like below: |
99 | 155 |
|
100 | | - server { |
101 | | - listen 80; |
102 | | - server_name zf2-app.localhost; |
103 | | - root /path/to/zf2-app/public; |
104 | | - |
105 | | - location / { |
106 | | - index index.php; |
107 | | - try_files $uri $uri/ @php; |
108 | | - } |
109 | | - |
110 | | - location @php { |
111 | | - # Pass the PHP requests to FastCGI server (php-fpm) on 127.0.0.1:9000 |
112 | | - fastcgi_pass 127.0.0.1:9000; |
113 | | - fastcgi_param SCRIPT_FILENAME /path/to/zf2-app/public/index.php; |
114 | | - include fastcgi_params; |
115 | | - } |
| 156 | +```nginx |
| 157 | +server { |
| 158 | + listen 80; |
| 159 | + server_name zf2-app.localhost; |
| 160 | + root /path/to/zf2-app/public; |
| 161 | +
|
| 162 | + location / { |
| 163 | + index index.php; |
| 164 | + try_files $uri $uri/ @php; |
| 165 | + } |
| 166 | +
|
| 167 | + location @php { |
| 168 | + # Pass the PHP requests to FastCGI server (php-fpm) on 127.0.0.1:9000 |
| 169 | + fastcgi_pass 127.0.0.1:9000; |
| 170 | + fastcgi_param SCRIPT_FILENAME /path/to/zf2-app/public/index.php; |
| 171 | + include fastcgi_params; |
116 | 172 | } |
| 173 | +} |
| 174 | +``` |
117 | 175 |
|
118 | 176 | Restart the nginx, now you should be ready to go! |
0 commit comments