Book Image

Learning PHP 7

By : Antonio L Zapata (GBP)
Book Image

Learning PHP 7

By: Antonio L Zapata (GBP)

Overview of this book

PHP is a great language for building web applications. It is essentially a server-side scripting language that is also used for general purpose programming. PHP 7 is the latest version with a host of new features, and it provides major backwards-compatibility breaks. This book begins with the fundamentals of PHP programming by covering the basic concepts such as variables, functions, class, and objects. You will set up PHP server on your machine and learn to read and write procedural PHP code. After getting an understanding of OOP as a paradigm, you will execute MySQL queries on your database. Moving on, you will find out how to use MVC to create applications from scratch and add tests. Then, you will build REST APIs and perform behavioral tests on your applications. By the end of the book, you will have the skills required to read and write files, debug, test, and work with MySQL.
Table of Contents (17 chapters)
Learning PHP 7
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Setting up the environment on Windows


Even though it is not very professional to pick sides based on personal opinions, it is well known among developers how hard it can be to use Windows as a developer machine. They prove to be extremely tricky when it comes to installing all the software since the installation mode is always very different from OS X and Linux systems, and quite often, there are dependency or configuration problems. In addition, the command line has different interpreters than Unix systems, which makes things a bit more confusing. This is why most developers would recommend you use a virtual machine with Linux if you only have a Windows machine at your disposal.

However, to be fair, PHP 7 is the exception to the rule. It is surprisingly simple to install it, so if you are really comfortable with your Windows and would prefer not to use Vagrant, here you have a short explanation on how to set up your environment.

Installing PHP

In order to install PHP 7, you will first download the installer from the official website. For this, go to http://windows.php.net/download. The options should be similar to the following screenshot:

Choose x86 Thread Safe for Windows 32-bit or x64 Thread Safe for the 64-bit one. Once downloaded, uncompress it in C:\php7. Yes, that is it!

Installing MySQL

Installing MySQL is a little more complex. Download the installer from http://dev.mysql.com/downloads/installer/ and execute it. After accepting the license agreement, you will get a window similar to the following one:

For the purposes of the book—and actually for any development environment—you should go for the first option: Developer Default. Keep going forward, leaving all the default options, until you get a window similar to this:

Depending on your preferences, you can either just set a password for the root user, which is enough as it is only a development machine, or you can add an extra user by clicking on Add User. Make sure to set the correct name, password, and permissions. A user named test with administration permissions should look similar to the following screenshot:

For the rest of the installation process, you can select all the default options.

Installing Nginx

The installation for Nginx is almost identical to the PHP 7 one. First, download the ZIP file from http://nginx.org/en/download.html. At the time of writing, the versions available are as follows:

You can safely download the mainline version 1.9.10 or a later one if it is stable. Once the file is downloaded, uncompress it in C:\nginx and run the following commands to start the web server:

$ cd nginx
$ start nginx

Installing Composer

To finish with the setup, we need to install Composer. To go for the automatic installation, just download the installer from https://getcomposer.org/Composer-Setup.exe. Once downloaded, execute it in order to install Composer on your system and to update your PATH environment variable.