Wat is DevOps?
DevOps is een gebruik die de samenwerking tussen het Development- en OperationsTeam bevordert om code sneller en op een geautomatiseerde en herhaalbare manier in te zetten voor productie. Het woord ‘DevOps’ is een combinatie van twee woorden ‘development’ en ‘operations’. DevOps helpt om de snelheid waarmee een organisatie applicaties en diensten kan leveren te verhogen. Het stelt organisaties in staat om hun klanten beter van dienst te zijn en sterker te concurreren in de markt.
In eenvoudige bewoordingen kan DevOps worden gedefinieerd als een afstemming van ontwikkeling en IT-operaties met betere communicatie en samenwerking.
Waarom is DevOps nodig?
Voor DevOps werkte het Development en Operations Team volledig geïsoleerd, een ieder voor zich. Testen en Deployment(opleveren en uitrollen) waren geïsoleerde activiteiten die werden uitgevoerd na het ontwerpen en bouwen deze namen meer tijd in beslag dan de eigenlijke bouwen. Zonder gebruik te maken van DevOps besteden teamleden een groot deel van hun tijd aan het testen, implementeren en ontwerpen in plaats van het bouwen van het project.
Handmatige opleveren en uitrollen van code leiden nogal eens tot menselijke fouten in de productie. Development- en OperationsTeams hebben hun eigen tijdlijnen en zijn niet synchroon waardoor verdere vertragingen ontstaan. Er is vraag naar een verhoging van het tempo van de levering van software door het bedrijfsleven. Volgens Forrester Consulting Study kan slechts 17% van de teams vaak en snel genoeg gebruik maken van geleverde software. Dit bewijst de noodzaak.
In de praktijk zijn er drie belangrijke thema’s die steeds genoemd worden in het kader van DevOps:
- Continuous Integration
- Het snel, geautomatiseerd en efficiënt mogelijk integreren van nieuw ontwikkelde code met bestaande code(basis) en bestaat uit het opslaan en omzetten van uw code tot bruikbare uitvoerbare code. Ook het en het uitvoeren van enkele basis controles en testen is een onderdeel van CI.
- Continuous Delivery
- Een uitbreiding van Continuous Integration, extra automatisering en testen toe, zodat u de code niet alleen vaak samenvoegt met bestaande code en omzet tot bruikbare uitvoerbare code, maar u de code klaar krijgt om in te zetten zonder menselijke tussenkomst. Continu in een kant-en-klare staat hebben.
- Continuous Deployment
- Een evolutie van Continuous Delivery. Het is de wens om zonder menselijke tussenkomst helemaal in productie te gaan. Nieuw gecreëerde code wordt door middel van geautomatiseerde tests uitgevoerd voordat deze naar de productie wordt uitgerold.
Veelgestelde vragen in het kader van DevOps
Voorbeeldplanning
Ontwerp
===
08:30 – 08:50 20 bestudeer aangeleverd materiaal/documentatie
08:55 – 08:55 05 stel indien nodig vragen
08:55 – 09:05 10 maken van de planning in trello
09:05 – 09:20 15 ontwikkelomgeving opzetten
09:20 – 10:05 45 creeer databasescript adhv TO
10:05 – 10:10 05 rol de database uit
10:10 – 10:20 10 vul de database met testgegevens
10:20 – 10:35 15 quickwins en prio bepalen
10:35 – 10:40 05 planning bijwerken/splitsen in trello
10:40 – 10:50 07 wireframe maken
10:50 – 11:00 10 scaffolding directory structuur inrichten
Realisatie
===
11:00 – 11:30 30 header en footer maken
11:30 – 11:45 15 algemene styling bepalen
11:45 – 12:15 30 pauze
12:15 – 14:20 125 Eerste functionaliteit
12:15 – 12:20 05 — wireframe
12:20 – 12:25 05 00 documenteren: technische benodigdheden en conventies in TO
12:25 – 12:40 15 00 controller: class en handleRequest of router maken
12:40 – 12:45 05 — controller: handleRequest switch/case en verwijzing of route bepalen
12:45 – 12:50 05 — controller: nieuwe method maken en naar model sturen
12:50 – 12:55 05 — model: DataHandler requiren
12:55 – 13:00 05 — model: nieuwe class maken indien nodig
13:00 – 13:05 05 — model: nieuwe class voorzien van __construct() en __destruct()
13:05 – 13:15 10 20 model: nieuwe method maken
13:15 – 13:20 05 — model: db data fetchen en var_dump testen
13:20 – 13:25 05 — view: nieuwe view maken
13:25 – 13:40 15 10 view: styling toepassen
13:40 – 13:45 05 — model: db data fetchen en ‘return‘ naar controller
13:45 – 13:50 05 — controller: db data klaarzetten voor view
13:50 – 13:55 05 — controller: include view in method
13:55 – 14:00 05 — documenteren: code
14:00 – 14:10 10 — testplan: functioneel en technische test uitvoeren
14:10 – 14:15 05 — documenteren: testresultaat in testplan
14:15 – 14:20 05 — documenteren: trello planning bijwerken
Port 80 in use, Apache WILL NOT start without the configured ports free!
Apache listens for requests on TCP/IP port 80 and cannot share the same port with another TCP/IP application, you may need to stop, uninstall or reconfigure certain other services before running Apache. These conflicting services include other webservers, some firewalls, and even some client applications (such as Skype) which will use port 80 to attempt to bypass firewall issues. To switch Skype off, start Skype and choose Tools > Options > Advanced > Connection
. Ensure you untick “Use port 80 and 443 as alternatives for incoming connections”.
Runtime Error! httpd.exe
When an application has made an attempt to load the C runtime library a runtime error could occur. This issue is caused by a faulty Visual C++ Runtime Library or certain applications which use the Runtime. To fix this issue, reinstall Visual C++ Runtime. Download a fresh copy of Microsoft Visual C++ Runtime from https://www.microsoft.com/en-us/download/details.aspx?id=48145 and then install it. Be sure !! that you have install the latest (14.16.27024.1) C++ Redistributable Visual Studio 2017 : vc_redist_x64 or vc_redist_x86.
Apache HTTP Server for Windows 32 and 64bit unavailable
We are going to need to use the unofficial Windows binary from Apache Lounge. This version has performance and stability improvements over the official Apache distribution, it is provided as a manually installable ZIP file from www.apachelounge.com/download/. Select the 32bit or the 64bit binary.
Apache detected with wrong path
Apache can be installed anywhere on your Windows OS, but you will need to change the configuration file paths accordingly…
Apache is configured with the text file httpd.conf contained in the Apache folder. Open it with your favourite text editor.
Note that all file path settings use a ‘/’ forward-slash rather than the Windows backslash. If you installed Apache anywhere other than C:\Apache24, now is a good time to search and replace all references to “C:/Apache2″.
There are several lines you should change for your production environment:
Line 37, listen to all requests on port 80:
Define SRVROOT "c:/Apache24"
Line 60, listen to all requests on port 80:
Listen *:80
Line 162, enable mod-rewrite by removing the # (optional, but useful):
LoadModule rewrite_module modules/mod_rewrite.so
Line 226, specify the server domain name:
ServerName localhost:80
Line 271, allow .htaccess overrides:
AllowOverride All
Best htdocs location for backups and re-installation
By default, Apache returns files found in its htdocs folder. I would recommend using a folder on an another drive or partition to make backups and re-installation easier. For the purposes of this example, we will create a folder called D:/apps and change httpd.conf accordingly:
Line 250, specify the new DocumentRoot:
DocumentRoot "D:/apps"
Line 251, and change <Directory “${SRVROOT}/htdocs”> to:
<Directory "D:/apps">
Apache does not display any PHP files
Be sure !! that you have installed the latest PHP binary for Windows : php-7.3.1-Win32-VC15-x64 or php-7.3.1-Win32-VC15-x86.
Line 284 of your httpd.conf
, tell the Apache Web Server to display the either the ‘index.php’ or ‘index.html’ file:
DirectoryIndex index.php index.html
We will install the PHP files to C:\Php7
, so create that folder and extract the contents of the ZIP file into it.
PHP can be installed anywhere on your system, but you will need to change the paths referenced in the following steps. To check the PHP version enter the following command:
cd c:\Php7\ php -v // Result should resemble PHP 7.3.1 (cli) (built: Jan 9 2019 22:43:14) ( ZTS MSVC15 (Visual C++ 2017) x86 ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
Copy C:\Php7\php.ini-production
to C:\Php7\php.ini
.. There are several lines you will need to change in a text editor (use search to find the current setting). Where applicable, you will need to remove the leading semicolon to uncomment these setting.
Define the extension directory:
Line 757, and change extension_dir = “ext” to:
extension_dir = "c:\Php7\ext\"
Enable extensions. This will depend on the libraries you want to use, but the following extensions should be suitable for the majority of applications:
Between Lines 910 and 943 uncomment:
extension=curl ; optional extension=gd2 ; optional extension=mbstring ; optional extension=mysqli extension=pdo_mysql extension=xmlrpc ; optional
‘php’ is not recognized as an internal or external command
To ensure Windows can find PHP, you need to change the path environment variable. Open Settings, type ‘environment variables’ NL ‘Omgevingsvariabelen’ into the search field and open the result. Select the “Advanced” tab, and click the “Environment Variables” button.
Scroll down the “System variables” list and click on “Path” followed by the “Edit” button. Click “Edit text” and add ;C:\Php7
to the end of the Variable value line (remember the semicolon). Now click OK until you’re out. You need to reboot at this stage.
Configure PHP as an Apache module
Ensure Apache is not running. Open c:\Apache24\conf\httpd.conf
configuration file in an editor. The following lines should be changed:
On line 239, add index.php as a default file name:
<IfModule dir_module> DirectoryIndex index.php index.html </IfModule>
At the bottom of the file line 537, add the following lines (change the PHP file locations if necessary):
# Tell apache where to look for a php.ini file. PHPIniDir "C:/Php7" # Link in the named object file or library. LoadFile "C:/Php7/php7ts.dll" #Loading of executable code and modules into the server. LoadModule php7_module "C:/Php7/php7apache2_4.dll" # Maps the filename extensions to the specified handler. AddHandler application/x-httpd-php .php # Maps the given filename extensions onto the specified content type. AddType application/x-httpd-php .php
Testing your Apache configuration
Your Apache configuration can be tested. Open a command box (Start > Run > cmd) and enter:
cd Apache24/bin httpd -t
Result should say Syntax OK
if not correct any httpd.conf configuration errors and retest.
For an overview of possible params such as -t
check out https://httpd.apache.org/docs/2.4/programs/apachectl.html
Create a file named index.html
in Apache’s web page root (either htdocs or D:/apps) and add a little HTML code:
<html> <head> <title>testing Apache</title> </head> <body> <p>Apache is working!</p> </body> </html>
Ensure Apache has started successfully, open a web browser and enter the address http://localhost/. If all goes well, your test page should appear.
Run Apache as a console application
Sometimes it is easier to work from the command line, especially during initial configuration and testing. To run Apache from the command line as a console application, use the following command:
cd Apache24/bin httpd
You will receive a Windows Defender Firewall notification, make sure Private networks checkbox is checked and continue to Allow access.
Testing your PHP configuration
Create a file named index.php
in Apache’s web page root (either htdocs or D:/apps) and add this code:
<html> <head> <title>testing PHP</title> </head> <body> <p>PHP is working!</p> <?php phpinfo() ?> </body> </html>
Ensure Apache has started successfully, open a web browser and enter the address http://localhost/. If all goes well, a “PHP version” page should appear showing all the configuration settings.
Configure MySQL
Download MySQL from https://dev.mysql.com/downloads/mysql/. Follow MySQL Community Server, Windows and download the “Without installer” version.
We will install MySQL to C:/mysql, so extract the ZIP to your C: drive and rename the folder from “mysql-8.0.14-winx64” to “mysql”.
MySQL can be installed anywhere on your system. If you want a lightweight installation, you can remove every sub-folder except for bin, data, scripts and share.
Best MySQL data location for backups and re-installation
Place the data folder on another drive or partition to make backups and re-installation easier. For the purposes of this example, we will create a folder called D:/MySQL/data and move the contents of C:/mysql/data into it.
You should now have two folders, D:/MySQL/data/mysql and D:/MySQL/data/test. The original C:/mysql/data folder can be removed.
MySQL provides several configuration methods but, in general, it is easiest to to create a my.ini file in the mysql folder. There are hundreds of options to tweak MySQL to your exact requirements, but the simplest my.ini file is:
[mysqld] # installation directory basedir="C:/mysql/" # data directory datadir="D:/MySQL/data/"
(Remember to change these folder locations if you have installed MySQL or the data folder elsewhere.)
Testing your MySQL configuration
The MySQL server is started by running C:/mysql/bin/mysqld.exe. Open a command box (Start > Run > cmd) and enter the following commands:
cd mysql/bin mysqld --initialize --console
This will generate all files needed for a first initialisation.
cd mysql/bin mysqld --console
This will start the MySQL server which listens for requests on localhost port 3306.
MySQL login not starting
You can start the MySQL command line tool and connect to the database. Open another command box and enter:
cd mysql/bin mysql -u root -p
After logging in with your generated password, it will show a welcome message and the mysql> prompt. Enter “show databases;” to view a list of the pre-defined databases.
Change the MySQL root user
The MySQL root user is an all-powerful account that can create and destroy databases. If you are on a shared network, it is advisable to change the default (blank) password. From the mysql> prompt, enter:
UPDATE mysql.user SET password=PASSWORD("my-new-password") WHERE User='root'; FLUSH PRIVILEGES;
You will be prompted for the password the next time you start the MySQL command line.
If any errors occur regarding password denials, try the following:
ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';
If a running service prevents your installation and/or configuration of your environment.
Open an elevated command prompt(Win+X)
cmd
services.msc;
Lookup the name of the service to kill, back at the command prompt execute the following commands to stop and remove the service:
cmd
SC STOP [shortservicename]; SC DELETE [shortservicename];
If by any chance ports seem to be in use by some other process.
Execute the following command to find and stop the process:
cmd
netstat -aon | findstr :[PortInUse];
In the result, the last column represents the process identifier (PID), execute the following commands to stop the process:
cmd
taskkill /pid [PID];
Set Environment Variables
To set persistent environment variables at the command line, execute the following commands:
cmd
setx PHP "d:\xampp\php\";
If by any chance ports seem to be in use by some other process.
Execute the following command to find and stop the process:
cmd
netstat -aon | findstr :[PortInUse];
In the result, the last column represents the process identifier (PID), execute the following commands to stop the process:
cmd
taskkill /pid [PID];
Installation and configuration phpMyAdmin on Windows
To the d:\apps\ folder copy the content of phpMyAdmin-4.6.5.2-all-languages.zip. Rename phpMyAdmin-4.6.5.2-all-languages to phpmyadmin (for brevity).
In the c:\apps\phpmyadmin\ folder create config.inc.php file and copy there:
Open in your browser http://localhost/phpmyadmin/
Enter root as name, do not fill password.
Backup your Apache, MySQL and PHP installation
8. Usage and backup web-server
In the c:\Server\data\htdocs\ folder put your local web sites, create HTML, PHP and another files. For instance, I created c:\Server\data\htdocs\test\ajax.php file, so this file will be available at the address http://localhost/test/ajax.php and so on.
To create full backup including all web sites and databases, just copy data folder in a save place. If you will need restore your information, with backup you can do it easily.
Before updating web-server modules, backup bin folder, if you will have issues you can fallback to previous versions.
Make backup of the following files, with them you can deploy new instance of the server faster.
- c:\Server\bin\Apache24\conf\httpd.conf
- c:\Server\bin\mysql-8.0\my.ini
- c:\Server\bin\PHP\php.ini
- c:\Server\data\htdocs\phpmyadmin\config.inc.php
These files keep all settings and when we are installing new web server instance most of the time we are engaged in their editing