Dieses Blog durchsuchen

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 /opt/phpstorm $ ln -s /opt/phpstorm/bin/phpstorm.sh /usr/local/bin/phpstorm

    Now you can run php storm via terminal
    $ phpstorm