Mike McGrath
PHP 7
In easy steps is an imprint of In Easy Steps Limited
16 Hamilton Terrace . Holly Walk . Leamington Spa
Warwickshire . United Kingdom . CV32 4LY
www.ineasysteps.com
Copyright 2016 by In Easy Steps Limited. All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without prior written permission from the publisher.
Notice of Liability
Every effort has been made to ensure that this book contains accurate and current information. However, In Easy Steps Limited and the author shall not be liable for any loss or damage suffered by readers as a result of any information contained herein.
Trademarks
All trademarks are acknowledged as belonging to their respective companies.
Contents
Getting started
Welcome to the exciting world of the interactiveweb with PHP. This chapter demonstrates how to create a dynamic development environment with a webserver and the PHP engine.
Introducing PHP
The most appealing modern websites provide a customized user experience by dynamically responding to some current condition user name, time of day, latest blog, shopping cart contents, etc. Many of these dynamic websites are created using PHP.
What is PHP?
PHP is a widely-used general purpose scripting language that is especially suited for web development and can be embedded into HTML. It was created by programmer Rasmus Lerdorf, as a set of scripts to maintain his website that he released as Personal Home Page Tools (PHP Tools) version 1.0 on June 8, 1995.
This is the official logo of the PHP project the official online home of PHP can be found at php.net
The tools were extended in the version 2 release of 1997, and the name changed to become a recursive acronym PHP: Hypertext Preprocessor in version 3 the following year. Performance, reliability and extensibility was improved in 2000 with the release of PHP4, which was powered by the Zend engine virtual machine.
Subsequently, PHP5 was released in 2004 powered by the new Zend II engine and produced as free software by the PHP group. A planned experimental version PHP6, that intended to introduce native Unicode support throughout PHP was abandoned. The current version PHP7 was released in 2015, and is powered by the latest Zend 3 engine that offers improved performance. Today PHP is installed on over 20 million websites and 1 million web servers.
This is the elePHPant the mascot of the PHP project, designed by Vincent Pontier.
Why is PHP popular?
PHP is extremely simple for a newcomer, but offers many advanced features for a professional programmer.
PHP code is enclosed in special start and end processing tags that allow you to jump into and out of PHP mode, to implement instructions within an HTML document.
PHP code is executed on the server (server-side), unlike JavaScript code that is executed in the browser (client-side). The client receives the results of running the script without knowing what the underlying code was. Recently, server-side has become to be known as The Cloud.
The New icon pictured above appears in this book to indicate new features introduced in PHP version 7.
Understanding The Cloud
Whenever a user asks to view a web page in their browser, it requests the page from the web server and receives the page in response, via the HTTP protocol. Where a web page contains PHP script, the web server will first call upon the PHP engine to process the code before sending the response to the web browser:
HTTP (HyperText Transfer Protocol) is the common communication standard that allows any computer connected to any web server to access files across the web.
The ensuing pages describe how to create a development environment for interactive websites by installing the following server-side technologies on your own computer:
Web Server Abyss Web Server X1 Free Personal Edition
PHP Engine PHP 7.0.4
The examples in this book are created and tested with these software versions but may require modification for other versions.
Installing the Abyss server
Abyss X1 is a free compact web server available for Windows, Mac OS X, and Linux operating systems available for download at aprelium.com
Despite its small footprint, Abyss supports many powerful features including dynamic content generation with server-side scripts so is an ideal companion for PHP.
Further guidance on installation of the Abyss Web Server is available at aprelium.com/abyssws/start.html
The Abyss Web Server can be installed on your own computer to provide an environment for interactive PHP website development:
Download the Abyss X1 Web Server setup package for your system from aprelium.com/abyssws/download.php
Run the setup installer and Agree the License terms, then select the Abyss Web Server component and click Next
The Abyss setup package for Windows is an executable file named abwsx1.exe that you run to install the web server.
Accept the suggested location of C:\Abyss Web Server then choose to Install as a Windows Service
After the installation process completes, your systems default web browser will open, displaying the Abyss Web Server Console.
Select your preferred language, then enter a name and password for future access to the Abyss Console