Dieses Blog durchsuchen

Sonntag, 28. August 2016

react.js: create a basic table component with bootstrap styles

Today we want to implement a simple task in HTML with css.
A Simple datatable like that:

The tablecomponent has a thead, a tbody and a stripe css set.

In good old html we do that like this:
<table class="table table-striped">
  <thead class="thead-default">
<tr>
    <th>ID</th>
    <th>Name</th>
   </tr>
</thead>
<tbody>
<tr>
  <td>1</td>
  <td>Nikko Laus1</td>
 </tr>
<tr>
  <td>2</td>
  <td>Sam Collins</td>
 </tr>
<tr>
  <td>3</td>
  <td>Carl Smith Wesson</td>
 </tr>
<tr>
  <td>4</td>
  <td>Peter Austin</td>
 </tr>
<tr>
  <td>5</td>
  <td>Tini Titus</td>
 </tr>
<tr>
  <td>6</td>
  <td>Sarra Cams</td>
 </tr>
</tbody>
</table>


Now we want to to this the react way.
We want to split the table in 3 components. One "App" component to wrap all other components. One TableRowComponent, which handles each row and a tablehead component to format the tablehead.

We are using Visual Studio code with all available react plugins on ubuntu 16.04

This tutorial is inspired by this great egghead video from Joe Maddalone:
https://egghead.io/lessons/react-dynamically-generated-components 

Prerequisits

At first, you need to have some tools installed. Here they are.
node.js installed
npm installed

babel react
the facebook react library

babel installed
Babel is a javascript compiler, which transforms latest javascriptstandards to native javascript

webpack installed
Webapck is a modulebundler which  creates statis js assets for the browser

Bootstrap installed
Bootstrap is a common css , component framework from twitter


$ apt-get install nodejs
$ apt-get install npm
$ npm install -g --save babel webpack webpack-server-dev
$ npm install --save babel-core babel- loader babel preset-es2015 babel-preset-react
$ npm install css-loader style-loader file-loader url-loader --save-dev
 

Init your node project

To initialise your project simple type:
$ npm init

This will create your package.json

Fill your projectdata 
My package.json looks like that
{
  "name": "react-redux",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel": "^6.5.2",
    "babel-core": "^6.14.0",
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.14.0",
    "babel-preset-react": "^6.11.1",
    "bootstrap": "^3.3.7",
    "react": "^15.3.1",
    "react-bootstrap": "^0.30.3",
    "react-dom": "^15.3.1",
    "webpack": "^1.13.2",
    "webpack-dev-server": "^1.15.0"
  },
  "devDependencies": {
    "css-loader": "^0.24.0",
    "file-loader": "^0.9.0",
    "style-loader": "^0.13.1",
    "url-loader": "^0.5.7"
  }
}


Add your component files

Create a index.html 
This will contain your main html page

main.js
this will load your components

webpack.config.js 
this will setup your dependencies and loaders and defines the compilingprocess of es2015 babel to native javascript

App.js
Here you will code your components
touch main.js index.html App.js webpack.config.js 

Configure your webpack.config.js

Open your webpack.config.js and add folling code
module.exports=
{
    entry:'./main.js',
    output:
    {
        path:'./',
        filename: 'index.js'
    },
    devServer:
    {
        inline:true,
        port:3333
    },
    module:
    {
        loaders: [
            {
                test:/\.js$/,
                exclude: /node_modules/,
                loader:'babel-loader',
                query:
                {
                    presets:['es2015','react']
                }
            },
            { 
        test: /\.css$/, 
        loader: "style-loader!css-loader" 
      },
      { 
        test: /\.png$/, 
        loader: "url-loader?limit=100000" 
      },
      { 
        test: /\.jpg$/, 
        loader: "file-loader" 
      },
      {
        test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, 
        loader: 'url?limit=10000&mimetype=application/font-woff'
      },
      {
        test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, 
        loader: 'url?limit=10000&mimetype=application/octet-stream'
      },
      {
        test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, 
        loader: 'file'
      },
      {
        test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, 
        loader: 'url?limit=10000&mimetype=image/svg+xml'
      }
        ]
    }
}
- This will tell webpack to pack a index.js with all javascripts in it
- Start a webserver on port 3333
- test all .js files
- Generate native javascript from babel sources.
- Tell webpack to load boostrap filetypes, mimetypes


Load your javascript on your html page

Open your index.html and add folling snippet
<!DOCTYPE html>
<html>

<head></head>

<body>
    <div id="app"></div>
    <script src="index.js"></script>
</body>

</html>

- This will add a div with id "app" which is the container for our app
- include the webpack generated index.js

Create your bootrap react component

Open your App.js and add folling snippet
import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component
{
    constructor() 
    {
        super();
        this.state = {
            data:[
                {id:1, name:"Nikko Laus1"},
                {id:2, name:"Sam Collins"},
                {id:3, name:"Carl Smith Wesson"},
                {id:4, name:"Peter Austin"},
                {id:5, name:"Tini Titus"},
                {id:6, name:"Sarra Cams"}    
            ]
        }
    }
  
    render() {
        
        let rows = this.state.data.map(person =>
        {
            return <TableRow key={person.id} data={person}/>
        });

        return (<table className="table table-striped">
            <TableHead/>
                <tbody>{rows}</tbody>
            </table>
            );
    }
}

class TableHead extends React.Component
{
    constructor()
    {
        super();
    }

    render()
    {
         return (<thead className="thead-default">
        <tr>
            <th>ID</th>
            <th>Name</th>
        </tr>
        </thead>
        );
    }
}

class TableRow extends React.Component
{
    constructor()
    {
        super();
    }

    render()
    {
        return (<tr>
                    <td>{this.props.data.id}</td>
                    <td>{this.props.data.name}</td>
                </tr>
            );
    }
}

export default App

- This adds a the base App Component with a dataset constructed as a state property in the constructor.
- This will add your App Component. This component renders an HTML-table with a seperate <TableRow> and a separate <TableHead> component in boostrap style.
- It also adds a <TableRow> component, which handles the row pattern
- At the end it adds a <TableHead> component, which builds the header of the tablecomponent 

Load your component in main.js

Open your main.js and add folling snippet
import App from './App';
import Bootstrap from 'bootstrap/dist/css/bootstrap.css';
import React from 'react';

import ReactDOM from 'react-dom';

ReactDOM.render( 
    < App / > 
    , document.getElementById('app')
    );

- Import your App component, which you have prevoiusly created and render it to a div with the id 'app'

Start your server and test your app

Open a terminal and type:
npm start 

This will start your webserver on port 3333

Surf to localhost:3333

Thats it, you have created your first bootstrap table component with bootstrap

Nice isn't it?

Samstag, 27. August 2016

react.js: create your first react app with webpack and babel on es2015

Today we want to write our first react Hello world app. Before we can start, we have to setup out dev-enviroment.

We are using Visual Studio code with all available react plugins on ubuntu 16.04

This tutorial is inspired by this great egghead video:

Prerequisits

At first, you need to have some tools installed. Here they are.
node.js installed
npm installed

babel react
the facebook react library

babel installed
Babel is a javascript compiler, which transforms latest javascriptstandards to native javascript

webpack installed
Webapck is a modulebundler which  creates statis js assets for the browser

$ apt-get install nodejs
$ apt-get install npm
$ npm install -g --save babel webpack webpack-server-dev
$ npm install --save babel-core babel- loader babel preset-es2015 babel-preset-react

Init your node project

To initialise your project simple type:
$ npm init

This will create your package.json

Fill your projectdata 
My package.json looks like that
{
  "name": "simplecommand",
  "version": "1.0.0",
  "description": "a simple console command",
  "main": "createUser.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/pboethig/nodejs-lessons.git"
  },
  "keywords": [
    "nodejs",
    "command"
  ],
  "author": "pboethig",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/pboethig/nodejs-lessons/issues"
  },
  "homepage": "https://github.com/pboethig/nodejs-lessons#readme"
}

Add your component files

Create a index.html 
This will contain your main html page

main.js
this will load your components

webpack.config.js 
this will setup your dependencies and loaders and defines the compilingprocess of es2015 babel to native javascript

App.js
Here you will code your components
touch main.js index.html App.js webpack.config.js 

Configure your webpack.config.js

Open your webpack.config.js and add folling code
module.exports=
{
    entry:'./main.js',
    output:
    {
        path:'./',
        filename: 'index.js'
    },
    devServer:
    {
        inline:true,
        port:3333
    },
    module:
    {
        loaders: [
            {
                test:/\.js$/,
                exclude: /node_modules/,
                loader:'babel',
                query:
                {
                    presets:['es2015','react']
                }
            }
        ]
    }
}
- This will tell webpack to pack a index.js with all javascripts in it
- Start a webserver on port 3333
- test all .js files
- Generate native javascript from babel sources.


Load your javascript on your html page

Open your index.html and add folling snippet
<!DOCTYPE html>
<html>

<head></head>

<body>
    <div id="app"></div>
    <script src="index.js"></script>
</body>

</html>

- This will add a div with id "app" which is the container for our app
- include the webpack generated index.js

Create your first component

Open your App.js and add folling snippet
import React from 'react';
class App extends React.Component {
    render() {
        return <div> Hello World</div>
    }
}

export default App
- This will import the react library and add a class App which only renders a div with the text "Hello world"

Load your component in main.js

Open your main.js and add folling snippet
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render( < App / > , document.getElementById('app'));

- main.js is the startup file, you have configured in webpack.config.js
- This will import the react library
- Import your App component, which you have prevoiusly created
- Adds your App component to the "app" div in your html


Start your server and test your app

Open a terminal and type:
npm start 

This will start your webserver on port 3333

Surf to localhost:3333

Thats it, you have created your first simple react app.+

That's awesome !

Mittwoch, 24. August 2016

node.js: create a console command without shell scriptig on ubuntu

Shellscripting for some simple commands are the 90ies. Today we want to setup a console command without any shell scripting. Only with javascript

Prerequisits

At first, you need to have some tools installed. Here they are.
node.js installed
npm installed
$ apt-get install nodejs
$ apt-get install npm

Init your node project

To initialise your project simple type:
$ npm init

This will create your package.json

Fill your projectdata 
My package.json looks like that
{
  "name": "simplecommand",
  "version": "1.0.0",
  "description": "a simple console command",
  "main": "createUser.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/pboethig/nodejs-lessons.git"
  },
  "keywords": [
    "nodejs",
    "command"
  ],
  "author": "pboethig",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/pboethig/nodejs-lessons/issues"
  },
  "homepage": "https://github.com/pboethig/nodejs-lessons#readme"
}

Add you command script

Get you node.js path
which node
This could output:
/usr/bin/node

Create a file "createUser.js" and add the shebang to it
!#/usr/bin/env node 
This will tell the system to use node.js to execute your script

Make your script executable
chmod a+x createUser.js


Tell npm to install your command
Edit your package.json and add the bin object
{
  "name": "simplecommand",
  "version": "1.0.0",
  "description": "a simple console command",
  "main": "createUser.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/pboethig/nodejs-lessons.git"
  },
  "keywords": [
    "nodejs",
    "command"
  ],
  "author": "pboethig",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/pboethig/nodejs-lessons/issues"
  },

 "bin": {
      "createUser": "createUser.js"
    },
"homepage": "https://github.com/pboethig/nodejs-lessons#readme"


Everytime you modifiý your command, you have to run the global installer
npm install -g

Install commander

To get your command running, we need the commander library, wich does the whole parsing thing for us,
npm install --save commander

Add you command code to the scriptfile

Open your createUser.js and add a simple command
#!/usr/bin/env node

var program = require('commander');

program
    .version('0.0.1')
    .usage('<username>')
    .parse(process.argv);

if(!program.args.length) {
    program.help();
} else {
    console.log('Username: ' + program.args);   
}

As you can see, we are requiring  the commander lib, add an option "username" and parse the input on the terminal.

If no argument was set, we display the helpfile.

If the username was given, we are outputting the username. And we succeed

Instead of that simple sample, you can implement your complex logic here.

That's it. Now you can run your command after you have installed your final scriptversion
 
$ npm install -g createUser.js 
$ createUser


This will output the helpfile of your new command. Nice !


Dienstag, 23. August 2016

Symfony3: create a console command and test it

Sometimes you need an easy way to create a console command to add some automation and some admintools to your application. With Symfony3 it is rediculous simple

Install symfony3

Open a console and execute:
$ composer require symfony/symfony

Create a project

Create a project "consoletest" by executing following command on the terminal
$ symfony new consoletest.

Now you have a new project created.

Add your command

Create a file "CreateUserCommand.php" on folder "src/AppBundle/Command" and add following Code
As you can see, this simple command extends from Class Command and implements only 2 methods.
The configure command sets up the command, setup name, description and , prints out helptexts if you want

The execute method does the final work and runs your commandcode. You can manipulate databases, filesystems, get a servicereponse or configure your application with it.

Run your command

At next you can test your command by typing :
$ bin/console app:create-user

You should see your helptext,



Awsome. Isn´t it?

Create a unittest for your command

With symfony it´s very easy to test your new command. Here is a simple test for it:
- Create a folder and a file "test/Appbundle/CreateUserCommandTest.php" with following content in it

And now you can run
$ phpunit symfony

Montag, 22. August 2016

ES6: prevent that = this;

Some days ago I found a solution for following problem in Javascript:

Solve a really ugly problem

I know many lines of code where you find follwing that-this reference
Now with ES6 you can solve this problem with the arrow function like this.

As you can see, you can directly use this in the arrow-function, which is a kind of a shortcut to "function". Thats really nice.

Sonntag, 21. August 2016

node.js: create a contactform with express, jade, boostrap and node-mailer

Today we want to create a contactform and send a message via gmail.
To make the form look good, we add bootstrap to hour project and we are using express to setup the webserver. At the end we want to use node-mailer to send the email. This might sound complicated, but you only have to follow my copy & paste instructions and everythings will be easy.

Prerequisits

At first you need to have some tools installed. here they are.
This should be familliar to you

node.js installed
npm installed
a gmail account with username and passsword
Installed and working express. For that please follow the last tutorial >>here<<.

After that, you have express installed, jade added to express and a routing added

Add the jade contactform

Jade is a templatelanguage like jsx, phptal, velocity etc. There are some facts, which seems to be nice, like the shortened syntax. But there might be some contras against jade too. For now we want to be open for new technologies and give jade a try.

If you want to get more information about jade, visit: http://jade-lang.com/

Create a file named "contact.jade" to your views folder. If you do not have a views folder, create one in your projectfolder and place following code to the contact.jade file.


Create the routes for your form

Open your app.js and add the contact-routes.(See comments in following code).
One route to render the form, and one route to send the email. My complete app.js looks like that

This will bind a route "contact" and "contact/send" to your express webserver app. the simple "contact" route only renders the form.

The more complex route "contact/send" will do a lot of stuff more. At first, it will create a transporter object, which tells the mailer to send the email via googles gmail over a predefined "from account". After that, it defines the mailoptions with the plaintextversion, the htmlversion, the sender and the recipient

At the end, the sendMail function gets called on the transporter object. This will simply send the mail and do the errorhandling. If an error occures, we will log it to the console.


Please make sure to set your own gmailaccount in the mailoptions and in the sendEmail function.

Add bootstrap to the project

Download and extract bootstrap to following folderstructure:
DownloadUrl: getboostrap.com

<yourprojectroot>
|__public
    |__css
    |__js
    |__fonts


create a file layout.jade with following code
This will add the baselayout with a little navigation   

Add a homepage to your project

Create a file named "index.jade" and add it to your view folder


Start your webserver

go to your projectroot and run
$ node app.js

Use your contactform

Now you can surf http://localhost:3000/contact and fill out the form.
After submitting your form you will get a "message send" to your console and you will recieve your email in your gmail account


If your mail gets rejected......

To test your email sending,  you have to allow "less secure apps" in your gmail testaccount:

You can do this by following :

https://support.google.com/accounts/answer/6010255?hl=enhttps://support.google.com/accounts/answer/6010255?hl=en







Samstag, 20. August 2016

node.js: create your first express webserver

In the last tutorial, we have created a simple webserver. That was great as preperation to use the expressframework, which can handle the webserverstuff for us. Let's have a look to express.

Prerequisits

node.js installed
npm installed

Install express globaly

$ npm install -g express

Create a npm project

Create your project rootfolder "express-project" and open a terminal in that folder and typpe:
$ npm init

Follow the intstructions on your terminal.

Add needed dependencies

Open package.json and add your dependencies. My package.json looks like that:

You can just pick the "dependencies" object 

 

Add you dependencies

Create a file "app.js" and paste following code
This will reference your dependencies and setup your express webserver.
As you can see, the webserver will be bound on port 3000 and it will return a simple "Hello world" response and will log the same words to the console.

Start the webserver

Open a terminal in the projectroot and type:
$ node app.js 


Now you can surf http://localhost:3000 and you should see "Hello world"

Thats it

Freitag, 19. August 2016

node.js: create a little bit more complex webserver

In the last tutorial, we have created a simple webserver. Lets create a little bit more complex webserver with node.js, which can serv different filetypes and check for errors on the filesystem.

Prerequisits

node.js installed
npm installed

Create a webserver


This webserver can dispatch a hand full of images , text, javascript and css

Create a file "server.js" and paste following code

This will create the webserver

Create a file to dispatch

Open a terminal in the projectroot and create a file "index.html" with following content
 



Start the webserver

Open a terminal in the projectroot and type:
$ node server.js 


Now you can surf http://localhost:1337/index.html and you should see "Testing"

Thats it

node.js: create the simplest webserver

Let's create a simple webserver with node.js

Prerequisits

node.js installed
npm installed

Create project

Type follwing command in your terminal and follow the instruction
$ npm init


This will create a package.json, which contains all the needed information for your project

Create a webserver


A webserver is just a piece of code in that case, wich allows us to send a message to the users browser.

Create a file "server.js" and paste follwing code

This will require the package http, which contains the server functions.
Then it will bind the server on localhost on port 3000. After that It will send a static returnvalue "Hello world" to the browser, wenn a user calls http://localhost:3000

Start the webserver

Open a terminal in the projectroot and type:
$ node server.js 


Now you can surf http://localhost:3000 and you should see "Hello World"

Thats it

Donnerstag, 18. August 2016

codeception: install on ubuntu 16.04

Today we want to give codeception a try. The installation is pretty simple

Prerequisits

composer. If you do not have composer installed, you can do it >>here<<

php >5.3 with mbstring enabled

Install codeception

create a folder "/var/www/html/codeception"

open a terminal and type:
$ composer require codeception/codeception

Add codeception to your terminal
$ sed -i "$ aalias codeception='/var/www/html/codeception/vendor/bin/codecept'" ~/.bashrc

Reload bash
. ~/.profile


That's pretty much it. Now you can use it.

Type "codeception" to get all options

Mittwoch, 17. August 2016

node.js: install simple sheduler as a rebootsafe service on ubuntu 16.04

There are many situations, in whioch you want to process a serverside workerscript to process queued tasks. Here is a simple solution to setup a nodejs cron script wich runs as a systemd service on ubuntu.

In this sample we are logging a text every second to the console, the filesystem and to the system d status log.


Prerequisits

Installed node.js, npm


Create your project

create a folder "/var/www/html/sheduler"

Init a npm project

create a package.json with following content

open a terminal and run
$ npm install

Install the sheduler

We want to use node-cron for our sheduler.  Node-cron allows us to trigger a script every second. That is ideal, if you want to build a worker wich runs every second. install follwing script 


This simple script creates a logger to log to the filesystem and to console every second. The logfile path is set to /var/www/html/sheduler/all-log.log


Install sheduler as a systemd service


To make our sheduler reboot save we now add the script as a systemd service.

add a file:
/etc/systemd/system/nodecron.service

paste following script in this service unit

This adds a servicedesfinition with the information, what script to execute.

Test your systemd-service

At last we reload our service units by typing:
$ systemctl --system daemon-reload

Enable your service
$ systemctl enable nodecron

 Start your service
$ systemctl start nodecron


Get status
$ systemctl status nodecron 

 If everything works you will get a status like that:

This tells us, that our logger logs every second a info and a debugmessage.
As you can see, our node.js script gets executed successfully. The service is tunning even, if you reboot the machine.

At the end you will find a logfile with your 2 loggings under:
/var/www/html/sheduler/all-logs.log

Disable your service like that
$ systemctl disable nodecron



Montag, 15. August 2016

Xdebug: Part II debugging with phpstorm


Part II First Debug Session

After we installed xdebug in Part I of this post , we now want to test our local debugging.

Prerequisits

Installed IIS or apache, php7, xdebug

Install needed chrome xtensions

Chrome developed some useful browserextensions to make things easier for us. 

Let´s use this nice extensions.

The first extension is "jetbrains-ide-support"
You can install it here https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji

The second extension is "xdebug-helper"
You can install it here https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc

The first plugin from jetbrains connects to chrome and adds a "PHPStorm" icon on the left.
If you click on it, a menue shows you your options



The second plugin connects chrome to xdebug. Thats the green icon left beside the PHPStorm icon.


Let´s add some phpcode to test the debugger.

Add following code to a new phpstorm project:


Now we can start watching the code. Place some breakpoints somewhere in your code an connect the watcher

- Activate the watcher by clicking the "telephone" Icon in the top right
- Set some breakpoints like the following

Now you can open your browser and surfe to your index.php. Your PHPStorm should open up and you should see your debugger working.

You can step-in , step-over your breakpoints and you can directly see what values your variables are, without to use var_dump() and die();

Great Fun!



Xdebug: install on windows with PHP 7


Part I Installation of Xdebug

To prepare the usage of xdebug for php in phpstorm, for using a much better debugworkflow then var_dump or Zend_Debug::dump(),  we have to build and install the php extension.

Prerequisits

Installed IIS or apache, php7

Build xdebug for your system

At the moment I wrote this post i have to build xdebug 2.4.x

  1. Download php_xdebug-2.4.1-7.0-vc14-nts-x86_64.dll
  2. Move the downloaded file to "C:\Program Files\PHP\v7.0\ext"
  3. Edit C:\Program Files\PHP\v7.0\php.ini and add the line
    zend_extension = "C:\Program Files\PHP\v7.0\ext\php_xdebug-2.4.1-7.0-vc14-nts-x86_64.dll 
    xdebug.remote_enable=true
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    xdebug.remote_handler=dbgp
    xdebug.profiler_enable=1
    xdebug.idekey=PHPSTORM "
  4. Restart the webserver


Thats pretty much it. At last, we want to check the build and the installation

Check the installation


Create a info.php

add following line to the info.php
<?php phpinfo();

- open a phpinfo.php in your browser and copy the whole html content.
- visit https://xdebug.org/wizard.php  and paste the content into the textarea there.

on the follwing screen you should see a message like that:






  • Xdebug installed: 2.4.1
  • Server API: CGI/FastCGI
  • Windows: yes - Compiler: MS VC14 - Architecture: x64
  • Zend Server: no
  • PHP Version: 7.0.9
  • Zend API nr: 320151012
  • PHP API nr: 20151012
  • Debug Build: no
  • Thread Safe Build: no
  • Configuration File Path: C:\Windows
  • Configuration File: C:\Program Files\PHP\v7.0\php.ini
  • Extensions directory: C:\Program Files\PHP\v7.0\ext

  • You're already running the latest Xdebug version

     
    Klick this link , if you want to use xdebug in a debugsession 


    Thanks

    Peter

    Win7: activate fastcgi

    For those , who are searching the feature fastcgi, to add it ton IIS

    1. Click Start, and then click Control Panel.
    2. In Control Panel, click Programs, and then click Turn Windows features on or off.
    3. In the Windows Features dialog box, click Internet Information Services to install the default features, and then select the following additional feature in the Application Development Features section:
      • CGI
    4. Click OK to close the Windows Features dialog box.

    To use the command line

    • Type the following command into a script:
      Start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-Security;IIS-RequestFiltering;IIS-HttpCompressionStatic;IIS-WebServerManagementTools;IIS-ManagementConsole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI;IIS-CGI

    Sonntag, 14. August 2016

    Xdebug: install on ubuntu 16.04 with PHP 7



    Part I Installation of Xdebug

    To prepare the usage of xdebug for php in phpstorm, for using a much better debugworkflow then var_dump or Zend_Debug::dump(),  we have to build and install the php extension.

    Prerequisits

    Installed apache2, php7
    If you do not have php7 and apache installed, you can follow this post

    Build xdebug for your system

    At the moment I wrote this post i have to build xdebug 2.4.from sources, just by typing following commands

    $ wget http://xdebug.org/files/xdebug-2.4.1.tgz
    $ tar -xvzf xdebug-2.4.1
    $ cd xdebug-2.4.1
    $ phpize
    $ cp modules/xdebug.so /usr/lib/php/201510/12
    $ nano /etc/php/7.0/apache2/php.ini

    Open your php.ini 
    nano /etc/php/7.0/apache2/php.ini

    and add follwing line at the end  
    zend_extension = /usr/lib/php/20151012/xdebug.so 
    xdebug.remote_enable=true
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    xdebug.remote_handler=dbgp
    xdebug.profiler_enable=1
    xdebug.idekey=PHPSTORM

    Open your cli/php.ini 
    nano /etc/php/7.0/cli/php.ini

    and add follwing line at the end  
    zend_extension = /usr/lib/php/20151012/xdebug.so 
    xdebug.remote_enable=true
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    xdebug.remote_handler=dbgp
    xdebug.profiler_enable=1
    xdebug.idekey=PHPSTORM

    This is necassary to add xdebug support to the comandline. So your phpstorm interpreter is able to run "debug" directly on the file.

    restart your webserver
    $ service apache2 restart
      

    Thats pretty much it. At last, we want to check the build and the installation

    Check the installation


    Create a info.php
    $ nano /var/www/html/info.php

    add following line to the info.php
    <?php phpinfo();

    - open a phpinfo.php in your browser and copy the whole html content.
    - visit https://xdebug.org/wizard.php  and paste the content into the textarea there.

    on the follwing screen you should see a message like that:





  • Xdebug installed: 2.4.1





  • Server API: Apache 2.0 Handler
  • Windows: no
  • Zend Server: no
  • PHP Version: 7.0.8-0
  • Zend API nr: 320151012
  • PHP API nr: 20151012
  • Debug Build: no
  • Thread Safe Build: no
  • Configuration File Path: /etc/php/7.0/apache2
  • Configuration File: /etc/php/7.0/apache2/php.ini
  • Extensions directory: /usr/lib/php/20151012

  • You're already running the latest Xdebug version

     

    In Part II we will configure PHPStorm to use the new php extension


    Thanks

    Peter

    LAMP: install on ubuntu 16.04 with PHP 7


    On ubuntu 16.04 it is very easy to setup a basic lamp.
     
    We will install php 7.0.8, Mysql 5.6 and apache 2.4


    basic install process
    $ apt-get install apache2
    $ apt-get install mysql-server
     - During MySql install you will be asked for your database password. Note it down, if you want.

    $ apt-get install php7.0


    Tell apache to interprete *.php with the zend engine.
    - We will use the apache php module to interprete php files. 

    $ apt-get install libapache2-mod-php

    Test if php is enabled in apache
    $ a2enmod php7.0

    If you get a successmessage everything went fine. Otherwise you can enable it manualy with:
    $ a2enmod php7.0

    Create a testpage to see if php is running on your apache.
    $ nano /var/www/html/info.php

    Place follwing line into the info.php
    <?php phpinfo();

    If you see your phpsettings, you where successful.

    Install further php extensions
    On that point you LAMP Stack is running. But in most of the cases, you will need some extensions more on the server to get applications like wordpress, joomla or magento up and running.

    To see which php extensions are available, you can type:
    $ apt-cache search php7.0

    Now you can choose your extensions to install. I always install follwing extensions by typing:

    $ apt-get install php7.0-intl php7.0-mcrypt php7.0-soap php7.0-xsl php7.0-xmlrpc php7.0-gd

    This will install extensions to communicate via Soap, use xml , use encryption and decryption and use image processing.

    At the end you have to restart your apache server with:
    $ service apache2 restart

    Thats it.

    Mittwoch, 10. August 2016

    phpstorm: install on ubuntu 16.04


    Now let's create an own image with a complete selenium testenviroment on it.

    Prerequisits

    Installed java
    $ apt-get install openjdk-8-jdk


    Install PHPstorm
    $ wget https://download-cf.jetbrains.com/webide/PhpStorm-2016.1.2.tar.gz
    $ tar xfvz Phpstorm-2016.1.2.tar.gz $ mv Phpstorm-2016.1.2.tar.gz /opt/phpstorm $ ln -s /opt/phpstorm/bin/phpstorm.sh /usr/local/bin/phpstorm

    Now you can run php storm via terminal
    $ phpstorm

    Montag, 8. August 2016

    docker: create your first container with selenium 3.0 on ubuntu 16.04



    In the last post, we installed docker on our local ubuntu 16.04

    Now let's create an own image with a complete selenium testenviroment on it.

    Prerequisits

    Installed Docker
    An account on docker hub (https://www.docker.com/)

    Pull an Ubuntu 16.04 image

    We want to install Selenium on a lunux ubuntu image. So we have to pull this image first.

    $ sudo docker pull ubuntu:14.04
    $ sudo docker images

    The first command downloads the ubuntu base image, we want to use.
    The second command "images" shows us the newly installed image. Please remember the Image ID. You will need it now




    Create a new container


    Use Run to create a new container
    "Run" is used to create a new container.

    You can type:
    $ sudo docker run --help
    to get all supported options.

    For our first image we want to use:
    $ docker run-i -t <your ubuntu image id> /bin/bash

    This tells docker to create a container and open a shell on it, so that we can install our selenium tools.

    Now you have a console on the ubuntu machine.

    You can type "exit" to get back to the host.

    Start the new container

    After you have created your container, you can list all containers with
    $ docker ps

    This will output your running processes:

    You now see your container id in the left

    To start our container we type:
    $ docker start <your container id>

    Bind a shell to the container

    At nex we want to bind a shell on our new container with:
    $ docker attach <your container id>

    The next input will be on the container

    Install Selenium 3.0

    After we have binded a shell on the new container, we install our testenviroment on the container
    $ apt-get update

      
    Install Java
    $ apt-get install openjdk-8-jdk

    This could take a while.....

    Install wget
    $ apt-get install wget


    Download and install selenium
    $ mkdir /usr/lib/selenium
    $ wget --output-document=selenium-server-standalone-3.0.0-beta2.jar http://goo.gl/2lZ46z
    $ chmod +x selenium-server-standalone-3.0.0-beta2.jar

    This will download the selenium server and set executable accessrights


    You should have a look for the current downloadurl of selenium under
    http://www.seleniumhq.org/download/

    Install Selenium as a service


    To install the new selium server as a service you only have to save follwing script under "/etc/init.d/selenium"



    Make script rebootsave
    $ update-rc.d selenium defaults

    Create logfiles
    $ mkdir -p /var/log/selenium
    $ touch /var/log/selenium/selenium-output.log

    Install gecko webdriver for firefox

    $ cd /usr/lib/selenium
    $ wget https://github.com/mozilla/geckodriver/releases/download/v0.10.0/geckodriver-v0.10.0-linux64.tar.gz
    $ tar xfvz geckodriver-v0.10.0-linux64.tar.gz
    $ mv geckodriver-v0.10.0-linux64.tar.gz geckodriver


    Install firefox

    $ apt-get install firefox

    Install webdriver for chrome

    $ cd /usr/lib/selenium
    $ wget http://chromedriver.storage.googleapis.com/2.23/chromedriver_linux64.zip
    $ apt-get install unzip
    $ unzip chromedriver_linux64.zip
    $ rm -rf  chromedriver_linux64.zip


    Install headless browsing

    To use headless browser we need xvfb. Headless means, that our server has no UI like a desktop machine. So the browser needs to be started "headless"
    $ apt-get install xvfb
    $ Xvfb :10 -ac
    $ export DISPLAY=:10

    
    


    Test selenium server

    To test, if the serviceinstallation worked, you can simply type:

    $ /etc/init.d/selenium start


    Commit your container to the docker hub

     Your installation on the container is now complete. You now can commit and push it to docker

    $ docker login

    Now you have to enter you accessdata

    $ docker commit -m "add selenium server" <your dockerid><your imageid>
    $ docker push <your dockerid>

    Thats it. Your new image is avalable in the docker hub

    install docker on ubuntu 16.04



    Docker is the most common virtualisation software in the linux world and it's widly used in the webworld. To explain what docker is, seems to be a little off topic. So here is how to install it.

    If you want to have some deeper inforamtion about docker, you can follow this link: 
    https://www.docker.com/what-docker

    Prerequisits

    Install a nonrootuser with sudo rights
    usermod -aG sudo <your username>

    Installation

    Update your APT
    $ apt-get update

    Add a GPG Code  to access Docker Reposotory
    $ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 
    58118E89F3A912897C070ADBF76221572C52609D

    Add docker to the apt sources
    $ echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
    $ apt-get update 
     

    > Install app
    $ apt-get install -y docker-engine

    Test status
    $ sudo systemctl status docker

    it should output something like that:


    Thats it. Docker is running on you machine.

    Samstag, 6. August 2016

    javascript: unittesting with node.js, mocha and chai



    In the  last post, we had setup a unittest enviroment for node.js with mocha and chai. Today we want to use it on our testproject

    Prerequisits

    You have to be installed:
    Node.js
    Chai.js
    Mocha.js

    Our project from the last post:
    $ git clone https://github.com/pboethig/starwarsNames.git
    $ npm install

    Let's start


    This was our code to test. File "src/index.js"
    If you open that file, you see that we have 2 properties in our module. "starwarsNames" from type String Array and "random" from type Random String. Now we want to test this 2 types.

    For that we implement a function "isTypeOfStringArray()" and the describe function to test that in our testfile under "src/index_test.js"

    Here is my "src/index_test.js" You deeply understand how the testcode works, if you have a look on the chai documentation
     


    Run the test

    Now switch to your terminal and type:
    $ npm t

    This will launch the configured testfile "src/index_test.js".We have configured it in "package.json"

    Now you should see something like that
     
     Great. The test was successful.

    Let's create another test

    Now we want to test, if "Luke Skywalker" is in the list with starwarsnames

    I have added the new test to "src/index_test.js"
    As you can see, I have added a second test to the describe "starwars-names" function. This tests uses "to.include()" to check the array for the string "Luke Skywalker". As you can see, you only need to save the testfile, and the test gets executed directly.

    Kent You should now see a terminal like that:

    Awesome. That it!


    And now the final test

    The last test, checks if the "random" function of our library gives us a random starwars-name from the list

    I have added the test "should contain a random name from the list" to the tests.

    Here is my final version of "src/index_test.js"
    If you run the test, you should see 3 passed tests now
    Thats all for now. Thanks to Kent.C.Dots for the great video:
    https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-unit-testing-with-mocha-and-chai

    javascript: setup unittesting with mocka and chai on a node.js module. Building a bridge



    In our last post, we had setup a node.js module and a npm project.
    On this project we now want to setup the enviroment for some unittesting.

    Prerequisits

    1) Node.js
    2) Npm 
    3) gitclient

    If you did not follow the tutorial, you can checkout the project here:
    Open a terminal and type:
    $ git clone https://github.com/pboethig/starwarsNames.git
    $ npm install

    Otherwise:

    Add unittesting libraries

    At first we want to add 2 new node libraries "mocha" and "chai" to our project to bring the unittesting capabilities.

    Open a terminal and navigate to your projectroot and type:
    $ npm install --save-dev mocha chai

    After that you have the 2 new libraries in your local/node_modules


    Create a first dummy-test

    - create a file named "index_test.js" in the folder "src"
    - open this file in your IDE.  I am using vscode with node.js plugins for that.

    In this testfile we add follwing code.

    To explain the code. At first we are referencing the expect method to a local variable "expect". In the second line, we are referencing our main module file "index.js", which we want to test.

    The next lines are our first simple test, in which we want to try, if the testframeworks are loaded correctly.

    Enabling the test in you package.json


    At next we have to extend our package.json to setup our testfile.
    - open the package.json
    - search the line:
    "test": "echo \"Error: no test specified\" && exit 1"
    and replace it with
    "test": "mocha src/index_test.js -w"

    This tells npm to start the testfile under "src/index_test.js" with_ the mocha library.

    Run your first test


    Now you can test that by executing.
    $ npm test

    in your projectroot.

    Yeah your first test is running, if you see something like this:


    Source: https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-setting-up-unit-testing-with-mocha-and-chai. Thanx Kent.C.Dotts for the great video.




    Freitag, 5. August 2016

    create a tag in git and release this tag

    Today we want to create a repo, add a file and create a tag. After that, we want to release this tag.

    This is a everyday process you need, if you want to publish a new version of your software,

    Prerequisits:
    - a git client 
    - a github account

    1) create a repository named "testing-tags" on github. If you do not have an account, you have to create one on github.com


    2) Create a local folder "testing-tags" somewhere on your computer
     
    - open a console an navigate to this folder and type:
     
    echo "# testingtags" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin https://github.com/<youtgithubusername>/testing-tags.git
    git push -u origin master
     
    This will add the README.md to the new github repository.
     
     
    Now we want to tag the first version of your software 
    in your terminal type:
    git tag 1.0.0
    git push --tags
     
    Thats it. You have pushed your first tag 1.0.1 to github you can find it on github here:
     
     

    javascript: create an npm package with a simple node.js module on ubuntu

    Today I want to create a npm package for a simple javascriptlibrary with modules and some tests. Src:https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-configuring-npm-and-creating-a-package-json

    At first we need a git repository on github.

    Create a repository named "starwarsNames"

    Login into your github account and create a new repository "starwarsNames"

    echo "# starwarsNames" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin https://github.com/pboethig/starwarsNames.git
    git push -u origin master
    

    create an account on https://www.npmjs.com, if you dont have one
    You will need an account there to publish your extension. 

    Remember your <npm-username> you will need it.

    Install nodejs
    $ apt-get install nodejs
    $ sudo ln -s /usr/bin/nodejs /usr/bin/node  

    Install npm, if npm is not installed 
    $ apt-get install npm 


    If you are on windows you have to install it manualy, If you are on mac, you can use the packagemanager,

    At next we inititialize the npm project. 
    $ npm set init-author-name 'Your Name'
    $ npm set init-author-email 'your email'
    $ npm set init-author-license 'MIT'
    $ npm set save-exact true

    If you want to check that config, you can do it with
    $ cat ~/.npmrc

    Add your npm user to your project 
    $ npm adduser
    Username: <your npm-username>
    Password: <your npm-password>
    Email: (this IS public) <your npm-email>

    Initilize your npm project
    $ npm init

    this will ask some data from you, and puts outs the package.json for you

    name: (starwars-names-<your npm username>)
    version: (1.0.0)
    license: (MIT)
    About to write to /var/www/html/starwarsNames/package.json:

    {
      "name": "starwars-names",
      "version": "1.0.0",
      "description": "get random starwars names",
      "main": "src/index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "repository": {
        "type": "git",
        "url": "git+ssh://git@github.com/pboethig/starwarsNames.git"
      },
      "keywords": [
        "random",
        "starwars"
      ],
      "author": "pboethig",
      "license": "MIT",
      "bugs": {
        "url": "https://github.com/pboethig/starwarsNames/issues"
      },
      "homepage": "https://github.com/pboethig/starwarsNames#readme"
    }






     


    Okay. Lets create our first module:
    - create a folder "src" in your projectroot to store our module sources.
    - now , create a file "index.js" in the new src folder

    Open this new file in your code editor. I am using vscode for it. That editor  has great node.js plugins.

    Now we want to define our modulestructure. 
    Type following code in index.js

    This tells node that you want to store the "starwars-names.json" list in a variable, that your module will use and it exports 2 properties ("all" and "random")

    At next save the starwarsnames in a file "starwars-names.json" in your "src" folder:


    At next we need a further npm library called unique-random-array.
    Lets install it with:

    $ npm install --save unique-random-array

    This will save the new library to our dependency definition in package.json

    Now lets use the new array library in our index.js

    Our index.js now looks like that
     
    Now that we have the library included, lets use it in our module.

    In the export function, we want to reference all starwars-names to the property "all" and a random startwars-name to the property "random".

    To to that we only have to export the local variable "starwarsNames" to the global scope by referencing the  exportproperty "all" and the array-function uniqueRandomArray(starwarsNames) from our new library to the export-property "random". Here is the code of "index.js".
    Now our index.js looks like that
    Yeah, we havehacked our first node module.

    Lets test it!
    - open a terminal and navigate to the root folder of your app 
    $ node
    $ var starwarsNames = require('./src/index.js');
    $ starwarsNames.all
    $ starwarsNames.random()  

    The single commands will output the whole list of names and a random name from the list. Thats realy great!


    Now we want to publish it in npm as an own package. 
    For that, we have to commit it to our git repository.

    open a terminal:
    $ cmd to your projectroot
    $ touch .gitignore
    $ nano .gitignore

    add "node_modules" to your .gitignore to prevent commiting the node_modules.

    $ git add *
    $ git commit -m "init"
    $ git push origin master

    Thats it.

    Now we can publish it to npm.
    Thats realy simple.

    Just type:
    $ npm publish

    That it. Now you should directly see your new package on npm !

    This is awesome!

    Now we want to test, if our module is directly usable via npm.
    - open a terminal to the desktop 
    $ npm install starwars-names-<your npm_user> 

    Super. Now you can use your library, from anywhere in the world.
    switch to the desktop and create a file named "test.js" with following content:
    Now run a terminal and cd to the directory where you have stored test.js and run:
    $ node test.js

    You will now see the results from your library.

    This is realy cool!


    Thanky to Kent.C.Dotts for the great video!

    In the next lesson, we want to extend the simple sample with unit tests.



    Selenium 3 and phpunit with facebooks webdriver

    Today, we want to extend our simple test, in wichh we have loaded a page and compared its title,  to a litte more comlex test.

    If you do not have the prerequisits installed, you can follow the previous tutorial here:
    http://magento2-tuts.blogspot.de/2016/08/phpunit-simple-tests-with-selenium.html





    Our goal for today is to:

    1) Setup and configure the webdriver, so that all tests are running in Firefox and chrome.

    2) execute our test which fills a searchform and submits it to the server. Gets the searchresult and schecks the result for a specific string

    3) closes the connection to the webdriver

    4) quits the browser.

    sounds interresting or?


    Lets start with the setup:

    As you can see in the setUp() method, the driver gets simply configured. You can setup a list with browsers, which are used for testing by the webdriver.


    Lets repeat a simple test.
    This test will only load the page and search for a String "GitHub" 


    Lets make an automated search.
    The next test will automaticly search the searchfield and type i  a serachterm
    After that the result gets parsed for the searchstring and gets sserted for it


     
    At last we want to sutdown the webdriverconnection and close the window

    Thats it. Both tests are green,

    You can download  the code here:
    https://github.com/pboethig/unittest