Archiv des Autors: Sascha Presnac

Nodejs und npm auf Windows installieren

Um NodeJS und den darin enthaltenen Package-Manager npm kommt man heute nicht mehr rum. Unter Windows hat es leider den Ruf, dass es schwer bzw. umständlich zu installieren sei und in der Vergangenheit war das auch oft der Fall.

Heute, mit Windows 10 oder Windows 11 sieht dies aber schon deutlich anders aus. Ganz im Linux-Stil geht es aber auch heute (noch) nicht per Kommandozeile.

Die Installation von nodejs ist recht trivial, im folgenden gehe ich von Windows 11 aus. Die Prozedur sollte unter Windows 10 wenn überhaupt, dann nur leicht anderes sein.

Zuerst lädt man sich das richtige binary als Installation runter. Dazu geht man auf die NodeJS Homepage in den Downloadbereich und man wählt am einfachsten den „Windows Installer (.msi)“ mit der passenden bitzahl aus (bei den meisten wird dies 64-bit sein).

Anschließend führt man die Installation aus und läßt diese wie gewohnt komplett durchlaufen. Sobald die Installtion abgeschlossen ist, kann man eine neue Konsole öffnen und wie gewohnt nodejs bzw. npm Befehle ausführen.

Eine kurze Prüfung, ob nodejs und npm erfolgreich installiert wurden.

Wenn diese beiden Kommandos, die einfach nur nach der installierten Version fragen, keine Fehler ausgeben, wurde nodejs mit npm erfolgreich installiert.

Get started with PHP + MariaDB on Windows

Even the longest journey starts with the first steps…

– Some wise guy

Welcome

Hej you ?, you want to start your developer career with php and you have no clue how to start and you do not want to pay hundreds or more dollars to start?

No problem, welcome to this post.

First: You do not have to pay anything to get started and make your first steps. All you need is a computer with windows (for this tutorial) and an internet connection (you can read this, you sure have one ?). And some time …. time is your currency to get into this developer thing.

PHP

To install php, you need to download it from the windows download section of the php homepage. Go to https://windows.php.net/download/ and choose your desired version. I recommend using the latest x64 „threat safe“ version – in most cases, this is the second option to download. You will propably learn about „thread safe“ and „non-thread safe“ in the future, but for starting, choose the „thread safe“ one ?.
Download the ZIP file!

Once downloaded, unzip it to a destination you like. I do have my php in „d:\php“ but the coise is up to you. Once you unzipped it, remember the file path to your php.

Now, you have downloaded php and unzipped it, but you will not be able to work with it properly. We have to setup the „path“ variable to your installation.

⚠ I assume you to be on at least Windows 10 for the next steps, for older versions locations may differ.

Open your system settings by pressing `Win` (the windows logo key) and `i` the same time. In the search field, type `path` and chose `edit system variables`. Chose the middlest tab called „Advanced“ and on the bottom there, click on „System variables„.

You see a new dialog, in the lower one search for „PATH“ and double-click that. Say „New“ and insert the path to your php installation. After that click on „Ok“ and close all dialogs with „Ok“. A reboot might be required (never had that, maybe you need to do it, just saying).

You can test it simply by opening your console (right click onto the windows-logo and chose „PowerShell“) and type `php -v`. You should get a result like this:

If you get an error, check the path you entered in your `path` variable; maybe you are the one who needs the reboot!

So, php is installed and ready to run ?.

MariaDB

The next thing you will need is a local database. For this MariaDB is a very good choise. It’s a fork of MySQL and full compatible with it … and on top: it’s free for you as learner ?.

Go to https://mariadb.org/download and choose your favorite. I recomend using the default (latest version, x64, Windows, MSI Package) for this is the easiest to start with.

After downloading, installed it as normal. The installer will ask you to setup a passwort for the `root` user … for this is a local installtion you can also leave it empty; in all cases, you will need this password in your code often, so choose one you do remember!

Ok, MariaDB is also installed now ?

If you courious how to start it: In the installtion you hopefully set it up as service, so just hit your windows-key, type „service“ and start the „services“ app, there you will find a service called „MariaDB“ and you can start/stop/reload it from there.

Connecting to MariaDB from php

When ever you want to connect from your php to your MariaDB and you let the setup use all as default, your database is reachable with

Host 127.0.0.1
Username root
Passwort whatever you setup
Port 3306

Simple as that.

Next steps?

Now, you are ready to develop great things with php and a database. Let’s finish this post with another quote:

Build something great!

– Some other wise guy

How to fix „SSL certificate problem: unable to get local issuer certificate“ on Windows

Du weißt bestimmt, dass ich auf Windows entwickle. Im Gegensatz zu vielen, die auf Macs oder Linux schwören, bleibe ich hartnäckig auf Windows – auch wenn dies bedeutet, dass ich Probleme sehe, die für andere unsichtbar sind. Ich sehe da allerdings die Chance, mehr zu lernen.

Eins dieser „mehr lernen“ Erfahrungen hatte ich heute. Meine phpunit tests laufen automatisch bei github und travis durch, keine Fehlermeldungen, alles gut.
Bis ich dann eben die Tests auf meiner Konsole ausführen wollte:

Anstelle des Erwarteten Fehlers SSL: no alternative certificate subject name matches target host name 'domain.xyz' erwartet mich:

SSL certificate problem: unable to get local issuer certificate

Wie seltsam … jetzt starte ich phpunit mal in meiner WSL Umgebung und siehe da, die Tests laufen alle durch. Das wieder so ein „Typisch Windows“ Problem.

Die Ursache liegt darin, dass du bei Windows-PHP-mit-Curl keine Zertifikatsinformationen per default eingestellt hast … das kann jetzt gut und schlecht sein, auf jeden Fall führt das zu dem Fehler.

Es gibt dazu allerdings auch eine Lösung und die funktioniert recht einfach:

1. Downloade gültige Zertifikatsinformationen von https://curl.se/ca/cacert.pem
2. Benenne die Datei um in curl-ca-bundle.crt
3. Kopiere die Datei, wo du sie gut verwalten kannst, bei mir liegt die in D:/www
4. Editiere deine php.ini. Du musst folgende Einträge ändern:
4.1. curl.cainfo = D:/www/curl-ca-bundle.crt
4.2. openssl.cafile=D:/www/curl-ca-bundle.crt
5. Speichern und Apache neu starten

Und nun laufen auch meine Tests durch ?

 

Laravel – „production.ERROR: No application encryption key has been specified.“

Puuuh, was habe ich an diesem Fehler gesessen und wie einfach doch die Lösung war.

Aber von Anfang an: Beim Zusammenspiel meiner API mit einer Anwendung, die diese API aufruft lief zuerst alles ganz gut. Allerdings: Sobald ich diese zweite Anwendung testen wollte, erschien sporadisch dieser Fehler. Sporadisch im Sinne von: Er trat auf, und das jedesmal, allerdings immer an völlig zufälligen Stellen.

Lange Geschichte kurz: Bei zu vielen Anfragen konnte die .env nicht mehr korrekt geladen werden. Meine Vermutung ist, dass das Dateisystem von Windows einfach zu lahm ist, weil es bei einem Kollegen auf einem Mac funktioniert und er noch nie diese Meldung zu Gesicht bekam.

Der Fix dazu ist relativ einfach: Du musst die Config cachen, dazu einfach dieses Kommando eingeben:

php artisan config:cache

Und dann hat es wunderbar funktioniert mit dem Zusammenspiel.

SourceTree startet nicht mehr (Fehler CLR20r3)

Mein SourceTree startet nicht mehr.
Das so etwas passiert, ist nicht schön, besonders, wenn man dieses tolle Tool beruflich benötigt. Es macht die Arbeit einfacher, gerade dann, wenn man viele Repos verwaltet und einfach auf dem laufenen bleiben möchte.

Schaut man in die Ereignisanzeige, dann offenbart sich der Fehler CLR20r3. Dieser Fehler liegt tiefer und wenn man ein wenig sucht, dann findet man die Lösung dazu:

  1. Deinstallieren von SourceTree
  2. Nun nicht direkt neu installieren, sondern in das VZ „%localappdata%\Atlassian\“ gehen und dort alle Unterverzeichnisse mit „SourceTree“ löschen!
  3. Nun SourceTree neu installieren.

Nun muss man leider das Programm nochmals neu konfigurieren, aber immerhin läuft es nun wieder 😀

 

Im jQuery tablesorter nach deutschem Datum sortieren

Den jQuery tablesorter kennen bestimmt viele, ich benutze diesen sehr häufig und gern. Allerdings kann das Ding von Haus aus nicht nach dem deutschem Datumsformat (dd.mm.yyyy [hh:mm]) richtig sortieren.

Hier dazu mein „Plugin“, dass in die entsprechende JavaScript Datei gehört:

$.tablesorter.addParser({
 id: 'germanDate',
 is: function(s) {
 return false;
 },
 format: function(s) {
 var dateMatches = s.match(/([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{2,4}) ([0-9]{1,2}):([0-9]{1,2})/i);
 return dateMatches[3]+dateMatches[2]+dateMatches[1]+dateMatches[4]+dateMatches[5];
 },
 // set type, either numeric or text
 type: 'numeric'
 });

$('#tblApps').tablesorter({
 sortList: [[1,0]],
 headers: {
 0: { sorter: false },
 2: { sorter: 'germanDate' },
 3: { sorter: false }
 }
 });

Damit kann mein Frontend nun auch innerhalb von Tabellen nach Terminen im deutschen Datum richtig sortieren.

Verzeichnisse ignorieren bei pdepend und phpdox

Im Zuge der „continuous integration“ setzt du bestimmt auch auf Tools wie pdepend oder phpdox. Allerdings würde ich gern nicht alle Verzeichnisse durchgehen, sondern ein paar davon exkludieren (Vendor-Zeug wie smarty oder das Zend-Framework).

Wer bei pdepend Verzeichnisse ignorieren will, der sollte es nicht wie in der Doku angegeben mit „–exclude“ versuchen, denn diese Option funktioniert schlicht einfach nicht.

Die Lösung ist bei pdepend der Parameter „–ignore=…“ dem man einfach alle Verzeichnisse kommasepariert übergibt, z.B. aus meinem ant-Script:

<arg value="--ignore=${basedir}/smarty,${basedir}/Zend" />

Bei phpdox kann man Verzeichnisse ausnehmen, wenn man diese auf die exclude-Liste des collector-Blocks setzt, den ihr in der entsprechenden phpdox.xml findet. Dieser Block kann dann z.B. so aussehen:

<collector publiconly="false" backend="parser">
<!-- @publiconly - Flag to disable/enable processing of non public methods and members -->
<!-- @backend - The collector backend to use, currently only shipping with 'parser' -->

<!-- <include / exclude filter for filelist generator, mask must follow fnmatch() requirements -->
<include mask="*.php" />
<exclude mask="**Zend**"/>
<exclude mask="**smarty**"/>

<!-- How to handle inheritance -->
<inheritance resolve="true">
<!-- @resolve - Flag to enable/disable resolving of inheritance -->

<!-- You can define multiple (external) dependencies to be included -->
<!-- <dependency path="" -->
<!-- @path - path to a directory containing an index.xml for a dependency project -->
</inheritance>

</collector>

Der „Trick“ dabei sind die beiden * vor und nach dem Namen.
Zumindest in meinem Jenkins läuft nun alles wie es soll 😀