Skip to content

Commit

Permalink
Installation documentation improved #9 with some minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
edigu committed Jul 18, 2015
1 parent d181d38 commit af825e2
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 36 deletions.
3 changes: 2 additions & 1 deletion config/application.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
'Core',
'DoctrineModule',
'DoctrineORMModule',
'TwbBundle',
],
// Load only on www.* requests
APP_URI_FRONTEND => [
'Frontend',
'TwbBundle',
],
// Load only on api.* requests
APP_URI_API => [
Expand All @@ -51,6 +51,7 @@
// Load only on admin.* requests
APP_URI_ADMIN => [
'Admin',
'TwbBundle',
],
// Development purposes only
'development' => [
Expand Down
168 changes: 134 additions & 34 deletions data/docs/02.Installation.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
# Installation
This is documentation for installation.
This documentation aims to explain all necessary steps in depth for installation.

Firstly, install your PHP libraries with following command.
Firstly, check out your web projects directory, clone the boilerplate and install dependencies by issuing the following commands:

```
$ cd /path/to/projects
$ git clone [email protected]:edigu/zf2-boilerplate.git
$ cd zf2-boilerplate
$ php composer.phar install
```

Lots of library will download and install.
Secondly, install [bower](https://github.com/bower/bower) to front-end package management.
And install [gruntjs](http://gruntjs.com/) to automate compilation and minification of your css files.
Following command require Nodejs. You should install node to your system before execute the following line.
Thanks to [composer](https://getcomposer.org/), all required 3rd party dependencies (including Zend Framework 2) will be automatically downloaded and installed into the `vendor` directory. Keep calm and grab a coffee while waiting..

Now, install [Bower](https://github.com/bower/bower) for javascript related package management and [Grunt](http://gruntjs.com/) for automating various javascript/less related tasks.

> We assumed that you have already installed [Nodejs](https://nodejs.org/) and [Npm](https://docs.npmjs.com/) on your system before. Otherwise, you MUST install Nodejs and Npm before continue.
```
$ npm install -g bower
$ npm install -g bower grunt-cli
$ bower install
$ npm install
$ npm install -g grunt-cli
```

So far, so good. At this point, `node_modules` and `bower_components` directories should be created in the project root.

Now we're ready to run grunt first time with the `dev` option which doesn't uglifies or minifies the javascript & css files for development purposes while compiling less:

```
$ grunt dev
```

That's all. You are ready.
This will create `public/img`, `public/js`, `public/css` and `public/fonts` directories with all related frontend stuff inside by following the directives in [gruntfile](/gruntfile.js) and mainly reading from `assets` folder in the project root.

As you noticed, these directories also ignored via [.gitignore](/.gitignore), this means you should create all further CSS/JS/Image files inside the `assets` directory, not `public/*` one.

> Managing small image assets via grunt is really subjective decision which taken after various bad experiences. You feel free to ignore this detail and apply your own solution if necessary.
## Database
- Create a database named `boilerplate`.
Expand All @@ -32,42 +46,128 @@ cp config/autoload/doctrine.local.{php.dist,php}
```

- And replace the `@dbuser`, `@dbpass` and `@dbname` values with yours.

## System
Defining an `APPLICATION_ENV` environment variable on the host machine which runs the application is good practice. This also required to run application without any problem via CLI.

## HTTP Server
Open the terminal and issue the command below:

```
echo "export APPLICATION_ENV=development" >> ~/.bashrc
source ~/.bashrc
```

**IMPORTANT** - On production server, you should use `production` value instead of `development`. If you wish to run the application on multiple servers for testing purposes, you can use values like `testing`, `staging` etc..

Create a new virtual server on nginx.

Nginx configurations for admin interface :
## HTTP Server
ZF2 Boilerplate contributors uses [Nginx](http://nginx.org/en/) as HTTP server. This documentation explains required configuration for nginx however achieving same result with the [Apache Http](https://httpd.apache.org/) server is possible too.

Create an [upstream pool](http://nginx.org/en/docs/http/ngx_http_upstream_module.html) named `http-servers` in `nginx.conf` file and set default charset to `UTF-8` to reduce localization related headaches:

```
server {
listen 80;
server_name admin.boilerplate.local;
http {
# ... leave other lines as is ...
root /path-your-project/public;
charset UTF-8;
location / {
index index.html index.php index.htm;
autoindex on;
try_files $uri $uri/ /index.php$is_args$args;
proxy_intercept_errors on;
upstream http-servers {
# Switch commented lines if your php-fpm listening TCP port.
# server 127.0.0.1:9000;
server unix:/tmp/php-fpm.sock;
}
}
```

location ~ \.php$ {
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9001;
proxy_intercept_errors on;
Leave the original `nginx/fastcgi_params` as is and create a custom `fastcgi.conf` file in the same (nginx) folder with the contents below. We'll use this custom fastcgi.conf in our server definitions for the sake of DRY principle:

```
location ~ .php$ {
# Add the original fastcgi_params
include fastcgi_params;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME /path-your-project/public/index.php$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /path-your-project/public;
fastcgi_param APPLICATION_ENV staging;
}
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
# Important:
# Change this from "development" to "production" on a REAL SERVER.
fastcgi_param APPLICATION_ENV development;
fastcgi_read_timeout 300;
fastcgi_pass http-servers;
fastcgi_index index.php;
}
```

Finally, define three virtual hosts in a `boilerplate.conf` file and save it as `nginx/sites-enabled/boilerplate.conf`. Contents of the virtual hosts configuration should seem like this:

```
# FRONTEND
server {
listen 80;
server_name www.boilerplate.local;
# Redirect url's with trailing slash to non-trailing slash version
rewrite ^/(.*)/$ /$1 permanent;
# Modify these three paths according to your project directory structure.
root /path/to/boilerplate/public;
access_log /path/to/boilerplate/data/logs/www.access.log;
error_log /path/to/boilerplate/data/logs/www.error.log notice;
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
include fastcgi.conf;
}
# API
server {
listen 80;
server_name api.boilerplate.local;
# Redirect url's with trailing slash to non-trailing slash version
rewrite ^/(.*)/$ /$1 permanent;
# Modify these three paths according to your project directory structure.
root /path/to/boilerplate/public;
access_log /path/to/boilerplate/data/logs/api.access.log;
error_log /path/to/boilerplate/data/logs/api.error.log notice;
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
include fastcgi.conf;
}
# ADMIN
server {
listen 80;
server_name admin.boilerplate.local;
# Redirect url's with trailing slash to non-trailing slash version
rewrite ^/(.*)/$ /$1 permanent;
# Modify these three paths according to your project directory structure.
root /path/to/boilerplate/public;
access_log /path/to/boilerplate/data/logs/admin.access.log;
error_log /path/to/boilerplate/data/logs/admin.error.log notice;
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
include fastcgi.conf;
}
```

Currently domain is `admin.boilerplate.local`. You can use different name but you should change your application.config.php file.
Now restart the nginx and open http://www.boilerplate.local in your favourite browser.
File renamed without changes.
Empty file added data/logs/admin.error.log
Empty file.
Empty file added data/logs/api.access.log
Empty file.
Empty file added data/logs/api.error.log
Empty file.
6 changes: 6 additions & 0 deletions data/logs/www.access.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
127.0.0.1 - - [18/Jul/2015:12:04:43 +0300] "GET / HTTP/1.1" 200 345 "http://www.boilerplate.local/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
127.0.0.1 - - [18/Jul/2015:12:04:43 +0300] "GET /favicon.ico HTTP/1.1" 200 357 "http://www.boilerplate.local/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
127.0.0.1 - - [18/Jul/2015:12:04:44 +0300] "GET / HTTP/1.1" 200 345 "http://www.boilerplate.local/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
127.0.0.1 - - [18/Jul/2015:12:04:44 +0300] "GET /favicon.ico HTTP/1.1" 200 357 "http://www.boilerplate.local/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
127.0.0.1 - - [18/Jul/2015:13:55:19 +0300] "GET / HTTP/1.1" 200 345 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
127.0.0.1 - - [18/Jul/2015:14:02:33 +0300] "GET / HTTP/1.1" 200 37965 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
Empty file added data/logs/www.error.log
Empty file.
2 changes: 1 addition & 1 deletion module/Core/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
),

'translator' => array(
'locale' => ['tr', 'en'], // ['current', 'fallback']
'locale' => ['en', 'en'], // ['current', 'fallback']
'translation_file_patterns' => array(
// Core module, default domain
array(
Expand Down

2 comments on commit af825e2

@hkulekci
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edigu maybe we can add to documentation about log files. Sensitive data should remove.

@edigu
Copy link
Collaborator Author

@edigu edigu commented on af825e2 Jul 19, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I just created documentation for logging. Don't hesitate creating PR's. ;)

Please sign in to comment.