Why I like PHPStorm
Advantages of Using Docker
Client, Docker Host, Registry
Docker Usage
Solr Docker File
Every Day Docker Commands
Docker Search
One Line Scripts
Portainer
Kinematic
Docker Compose
Grafana
Coding style guide
PHPCS/MD
Documentation Rules
Xdebug
Postman
2. Why I like PHPStorm
● You can develop applications in PHP versions 5.3/5.4/5.5/5.6/7.0/7.1, SQL & PL/SQL,
JavaScript, XML, HTML, CSS.
● You can add functionality to our IDE by installing plugins (Bash, Symfony, Laravel,
Magento 2, NodeJS, LiveEdit, Spy-JS, Meteor).
● Support for Vagrant and Docker, Docker Compose, SSH console & remote tools.
● Databases and SQL Editor in PhpStorm (MySQL, PostgreSQL, Oracle, SQLite, etc)
● Coding style Support PSR1/PSR2, PHPDoc support.
● Version control systems integration Git, Subversion, Mercurial, Perforce, CVS, TFS
● Duplicated Code Detector. PHP Code Sniffer (phpcs) that checks for code smells on
the fly. Local History. Debugging with Xdebug and ZendDebugger.
3. Advantages of Using Docker
Portability across machines – an application and all its dependencies
can be bundled into a single container that can be transferred to
another machine that runs Docker, and executed there without
compatibility issues.
Version control and component reuse – you can track successive
versions of a container, inspect differences, or roll-back to previous
versions.
Sharing – you can use a remote repository to share your container
with others.
6. Docker File Example
FROM php:5.6-fpm
RUN apt-get update && apt-get install -y libfreetype6-dev libicu-dev libjpeg62-turbo-dev
libmcrypt-dev libpng-dev libxslt1-dev
RUN docker-php-ext-install gd mcrypt mbstring sockets zip xsl soap
RUN pecl install xdebug-2.5.5 && docker-php-ext-enable xdebug
ADD ./etc/init.d/php/run.sh /run.sh
RUN curl -Lsf 'https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz'
| tar -C '/usr/local' -xvzf -
ENV PATH /usr/local/go/bin:$PATH
RUN go get github.com/mailhog/mhsendmail
RUN cp /root/go/bin/mhsendmail /usr/bin/mhsendmail
7. Solr Docker File
FROM java:6
RUN mkdir -p /opt/solr
RUN cd /tmp && curl https://archive.apache.org/dist/lucene/solr/3.6.1/apache-solr-3.6.1.tgz | tar xvz &&
mv -v apache-solr-3.6.1/* /opt/solr
EXPOSE 8983
VOLUME ["/opt/solr/example/solr/data", "/opt/solr/example/solr/conf"]
WORKDIR /opt/solr/example
CMD java -jar start.jar
8. Every Day Docker Commands
~$ docker ps -a
~$ docker stop|start|restart container_name
~$ docker run --name ubuntu -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"
~$ docker exec -it ubuntu bash
~$ docker logs ubuntu
~$ docker history ubuntu
~$ docker stats
9. Docker Search
~$ docker search node
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
node Node.js is a JavaScript-based platform for... 5829 [OK]
mhart/alpine-node Minimal Node.js built on Alpine Linux 366
mongo-express Web-based MongoDB admin interface, written... 269 [OK]
nodered/node-red-docker Node-RED Docker images. 168 [OK]
iojs io.js is an npm compatible platform origin... 126 [OK]
prom/node-exporter 83 [OK]
readytalk/nodejs Node.js based off the official Debian W
10. One Line Scripts
~$ curl -s https://registry.hub.docker.com//v1/repositories/php/tags | php -r
'print_r(json_decode(file_get_contents("php://stdin")));' | grep fpm | head -20
~$ sudo nano /usr/local/bin/docker-tags
~$ sudo chmod +x /usr/local/bin/docker-tags
#!/usr/bin/env bash
curl -s https://registry.hub.docker.com//v1/repositories/$1/tags | php -r
'print_r(json_decode(file_get_contents("php://stdin")));' | grep name | grep $2 | head -$3
16. docker-compose up
Runs services via docker-compose util:
● db - MySql database service
● app - PHP5.6-FPM service
● web - Nginx web server
● redis - Redis session and cache storage
● mongo - Mongo NoSql storage used for price service
● rabbit - RabbitMQ queue server
● solr -Apache Solr service for fulltext search
● bps - Backend price service on Python Tornado
● fps - Frontend price service on PHP
● worker - PHP worker for background jobs
● cron - Run application schedule tasks
● mailservice - Caught all mail from application
19. Coding style guide PSR-1
● Files MUST use only <?php and <?= tags.
● Files MUST use only UTF-8 without BOM for PHP code.
● Files SHOULD either declare symbols (classes, functions, constants, etc.) or cause
side-effects (e.g. generate output, change .ini settings, etc.) but SHOULD NOT do both.
● Namespaces and classes MUST follow an “autoloading” PSR: [PSR-0, PSR-4].
● Class names MUST be declared in StudlyCaps.
● Class constants MUST be declared in all uppercase with underscore separators.
● Method names MUST be declared in camelCase.
20. Coding style guide PSR-2
● Code MUST use 4 spaces for indenting, not tabs.
● There MUST NOT be a hard limit on line length; the soft limit MUST be 120
characters; lines SHOULD be 80 characters or less.
● There MUST be one blank line after the namespace declaration, and there
MUST be one blank line after the block of use declarations.
● Opening braces for classes MUST go on the next line, and closing braces MUST
go on the next line after the body.
● Opening braces for methods MUST go on the next line, and closing braces MUST
go on the next line after the body.
● Visibility MUST be declared on all properties and methods; abstract and
final MUST be declared before the visibility; static MUST be declared
after the visibility.
● Control structure keywords MUST have one space after them; method and
function calls MUST NOT.
● Opening braces for control structures MUST go on the same line, and closing
braces MUST go on the next line after the body.
● Opening parentheses for control structures MUST NOT have a space after them,
and closing parentheses for control structures MUST NOT have a space before.
23. PHP CS Setup
Setup PHPCS in PHPStorm:
In PHPStorm open File > Settings > Languages & Frameworks> PHP > Code Sniffer
Click to configuration, in opened popup click to the (+) and provide path to phpcs launcher.
24. PHP MD Setup
Setup PHPMD in PHPStorm:
In PHPStorm open File > Settings > Languages & Frameworks> PHP > Mess Detector
Click to configuration, in opened popup click to the (+) and provide path to phpmd launcher.
27. Document Rules
PHPDocs Rules:
● Each method in project MUST contain - @param, @return, @throws tags, and short method description.
● Each property and constant in project MUST contain - @var tag, and short property description.
● Each class and interface MUST contain - @category, @package, @author, @copyright, @license, @link and
short desc.
● Each file MUST contain - @category, @package, @author, @copyright, @license, @link and NOTICE OF
LICENSE
● Each public method in observe is in the listening to a magento event MUST contain - @see with value
event_name
● All PHP files MUST start with php tag, and MUST contain a empty line in end of file without php close tag.
● Each deprecated method MUST contain - @depricated and @see tags, @see -
class_method_with_new_functionality
29. Xdebug Installation
~$ sudo apt install php-xdebug
~$ sudo phpenmod xdebug && php -m | grep xdebug
~$ sudo nano /etc/php/{php-version}/mods-available/xdebug.ini
[Xdebug]
zend_extension=<full_path_to_xdebug_extension>
xdebug.remote_enable=1
xdebug.remote_host=<the host where PhpStorm is running (e.g. localhost)>
xdebug.remote_port=<the port to which Xdebug tries to connect on the host where PhpStorm is
running (default 9000)>
xdebug.remote_autostart=1
30. Postman Collections
A Postman Collection is an Executable API Description. With Postman collections you can:
● Publishing an API collection can be done via a Run In Postman button, embedded within the publisher’s
site, and downloading a Postman Collection directly into the developer’s Postman instance.
● API Monitoring is a scheduled service to run a Postman Collection, reporting results based on tests
embedded in the collection, and reported in the user’s Postman dashboard.
● API Documentation publishes a shareable, customized view of the API’s Postman Collection - helping
developers onboard quickly to an API.
● Developers can create a Mock Server from a collection, allowing API users to view example request &
response pairs, even before the API is complete.
● Developers can Debug APIs by creating requests, adding tests, and examining responses.
32. Debug PHP in Docker
Our php docker image already contain Xdebug in path/to/project/docker/php-fpm.dockerfile ;
xdebug configuration are in path/to/project/docker/etc/xdebug.ini ;
PHP Environment Variables are in path/to/project/docker/php.env ;
Environment Variables used for PHP Storm and Xdebug:
XDEBUG_CONFIG=remote_host=172.17.0.1 - IDE machine IP address
PHP_IDE_CONFIG=serverName=example - server name in PHPSTORM
Get your IP address in docker network (ifconfig (Unix) or ipconfig (Win)) and put to remote_host
~$ ifconfig
docker0 Link encap:Ethernet HWaddr #########
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0
param
33. Xdebug Configuration In Docker
Mount to the php container xdebug.ini file next content:
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=19000
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.idekey="PHPSTORM"
In PHP dockerfile php-fpm.dockerfile
RUN pecl install xdebug-2.5.5
&& docker-php-ext-enable xdebug
37. Xdebug Profiling
xdebug.profiler_enable=1 or xdebug.profiler_enable_trigger=1 and activate it by XDEBUG_PROFILE
GET/POST parameter. xdebug.profiler_output_dir=/path/to/volume/profiler_output