Locker mit Docker – Heute der Mailserver

Ich selbst habe immer Probleme mit den Mailservern. Die mögen mich einfach nicht. Dank dem Tutorial von Tomas Leister konnte ich ihn dann aber doch noch zum laufen bringen.

Nachdem ich aber einen Server Wechsel vorgenommen habe, ging das Spiel von vorn los. Wenn ich den Mist jetzt noch auf anderen Servern machen muss dreh ich am Rad. Also hab ich nun einen Docker Container gebaut der einfach läuft wie ich das gern hätte. Mit Datenbank, Catch all und mehreren Domains. Die Datenbank und Tabellen werden erstellt. Einige Variablen kann man und muss man dem Container mitgeben.

Das ganze steht natürlich in Git und im Docker Hub zur Verfügung.

Hier die Locker mit Docker PlayList auf Youtube

Build a PHP Docker File with .htaccess and Mod-Rewrite

Hi Guys,

today a write about Docker to share a PHP Project with Mod-Rewrite and no Public Application Code and i try to write it in english. I must learn it. 😀 This How-to is written for Puschel from Cranktube.tv. Maybe he will understand the Docker Commands now.

The PHP Project Folder are

/myProject

/appcode

/Model
/View
/Control

/html

/css
/js
/img
index.php

.htaccess
.gitignore
Dockerfile
httpd.conf

The First Step is to open a File names Dockerfile and write the Build Requirements in it.

Here the full Dockerfile Content.

FROM centos:latest
MAINTAINER Manuel ‚Onko‘ Müller <mueller.m.h@gmail.com>

RUN yum update -y
RUN yum install git curl php -y
RUN yum install httpd -y
RUN yum install php-pdo -y
RUN yum install php-pdo_mysql -y

COPY . /var/www
COPY httpd.conf /etc/httpd/conf/httpd.conf

EXPOSE 80

CMD httpd && tail -f /var/log/lastlog

We need a OS so i choose CentOS in latest version. This is the First Line

FROM centos:latest

The MAINTAINER is only for Information, who has written this holy shit.

The next RUN Commands update the CentOS and install Git, Curl, PHP, httpd, php-pdo, php-pdo-mysql

PDO is the Database Conector and php_pdo_mysql the Connector for MySQL.

The Copy Command take the Content of the actually Folder in the Docker Container. The Target Folder is /var/www. This is the httpd default Webroot.

Then i  copy my own httpd.conf file in the Container to Allow Override and some other Stuff. This File is in the same Folder too.

EXPOSE 80 Open the http Port for the Container so it is possible to connect the container.

CMD httpd && tail -f /var/log/lastlog this command start the httpd service and open a logfile without the tail logfile the httpd will startet and the docker container shutdown if all done.

Now we have a full running PHP Project in this Container.

In my Case i will run it local for development. So i run boot2docker on my Windows Maschine and shared my Development Folder with the Virtual Maschine. So i have access to it with mount Point /c/Users

So i Switch the workdir to my development Project Folder

cd /c/Users/myPHPCode

In this folder are my PHP Code, public code like CSS Images and public PHP Files in subfolder html, my httpd Config and the Dockerfile

So i can build a Container now.

docker build -t myProject .

The dot as the end is the acctually folder i can use follow command too.

docker build -t myProject /c/Users/myPHPCode

Next Command we need is to start the Container.

docker run -p 80:80  -d -i -t myProject

With -p i mapped the container port 80 to the Virtual Maschine Port 80.

Now i have running a PHP Project with the latest code of my Project. But i want to change code and try it out. so i can mount my real local code to the container.

With -v i can mount /var/www with the virtual maschine folder /c/Users/myPHPCode

docker run -p 80:80 -v /c/Users/myPHPCode/var/www -d -i -t myProject

I hope my english is clear enough to understand what i try to explain. 🙂

PHP SOUNDEX mysql php

Ich habe mich heute mal mit der Funktion SOUNDEX auseinander gesetzt.

Sehr interessant wenn man Schreibfehlern emtgegen wirken möchte da diese Funktion prüft ob zwei Werte ähnlich sind.
So habe ich dann einen Test gemacht und musste feststellen das diese Funktionen in MySQL und PHP unterschiedlich arbeiten.Auszug MySQL:

SOUNDEX(str)Gibt einen Soundex-String aus str zurück. Zwei Strings, die fast identisch klingen, sollten identische Soundex-Strings haben. Ein Soundex-String ist standardmäßig vier Zeichen lang, die Funktion SOUNDEX() gibt aber einen beliebig langen String zurück. Sie können SUBSTRING() für das Ergebnis verwenden, um einen Standard-Soundex-String zu erhalten. Alle nicht alphabetischen Zeichen in str werden ignoriert. Alle internationalen alphabetischen Zeichen außerhalb des Bereichs A bis Z werden als Vokale behandelt.
mysql> SELECT SOUNDEX('Hello'); -> ‚H400‘
mysql> SELECT SOUNDEX('Quadratically'); -> ‚Q36324‘
Hinweis: Diese Funktion implementiert den Soundex-Originalalgorithmus und nicht die gängigere erweiterte Version, wie sie auch von D. Knuth beschrieben wird. Der Unterschied besteht darin, dass die Originalversion zuerst Vokale und dann Duplikate verwirft, während die erweiterte Version umgekehrt vorgeht.

Auszug PHP :

 Beschreibung
string soundex ( string $str )
Errechnet den Wert der Laut-Ähnlichkeit von str.
Soundex-Werte haben die Eigenschaft, dass ähnlich ausgesprochene Wörter den gleichen Soundex-Wert erzeugen. Dies kann zur Suche in Datenbanken verwendet werden, wenn Sie zwar die Aussprache aber nicht die genaue Schreibweise kennen. Die Funktion soundex gibt einen String aus 4 Zeichen, beginnend mit einem Buchstaben, zurück.
Diese besondere soundex-Funktion ist u.a. von Donald Knuth in „The Art Of Computer Programming, vol. 3: Sorting And Searching“, Addison-Wesley-Verlag (1973), Seiten 391 bis 392 beschrieben.

Legen wir zum Beispiel eine Tabelle mit Vornamen an und tragen dort

Manuel

Manuela
Michael
Mathias
Peter
Petra
Paul
ein dann bekommen wir von MySQL alle Vornamen mit M zurück, PHP makiert jedoch nur Manuel und Manuela.
mysql_connect(‚localhost‘, ‚root‘, “);
mysql_select_db(‚adressdb‘);
$res = mysql_query(‚SELECT * FROM firstname WHERE SOUNDEX(firstnameData) SOUNDS LIKE SOUNDEX(„manole“);‘);
while ($result = mysql_fetch_assoc($res)) {
var_dump($result);
if (soundex($result[‚firstnameData‘]) == soundex(‚manole‘))
echo „gefunden.“;
}