Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning PHP 7 High Performance

You're reading from   Learning PHP 7 High Performance Improve the performance of your PHP application to ensure the application users aren't left waiting

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher Packt
ISBN-13 9781785882265
Length 202 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Iltaf (Altaf) Hussain Gul Iltaf (Altaf) Hussain Gul
Author Profile Icon Iltaf (Altaf) Hussain Gul
Iltaf (Altaf) Hussain Gul
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Setting Up the Environment FREE CHAPTER 2. New Features in PHP 7 3. Improving PHP 7 Application Performance 4. Improving Database Performance 5. Debugging and Profiling 6. Stress/Load Testing PHP Applications 7. Best Practices in PHP Programming A. Tools to Make Life Easy B. MVC and Frameworks Index

Setting up Windows

There are many tools available that have Apache, PHP, and MySQL bundled for Windows, provide easy installation, and are very easy to use. Most of these tools already provide support for PHP 7 with Apache, such as through XAMPP, WAMPP, and EasyPHP. EasyPHP is the only one that also provides support for NGINX and provides easy steps to changes webserver from NGINX to Apache or Apache to Nginx.

Note

XAMPP is also available for Linux and Mac OS X. However, WAMP and EasyPHP are only available for Windows. Any of these three can be used for this book, but we recommend EasyPHP as it supports NGINX, and for this book, we mostly use NGINX.

Any of the three tools can be used, but we require more control over every element of our web server tools, so we will also install NGINX, PHP 7, and MySQL individually and then connect them together.

Note

NGINX Windows binaries can be downloaded from http://nginx.org/en/download.html. We recommend using a stable version, though there is no problem with using a mainline version. PHP Windows binaries can be downloaded from http://windows.php.net/download/. Download either 32-bit or 64-bit binaries of the non-thread safe version according to your system.

Perform the following steps:

  1. Download NGINX and PHP Windows binaries mentioned in the information box. Copy NGINX to a suitable directory. For example, we have a completely separate D drive for development purposes. Copy NGINX to this development drive or any other directory. Now, copy PHP either to the NGINX directory or to any other secure folder location.
  2. In the PHP directory, there will be two .ini files, php.ini-development and php.ini-production. Rename either one of them to php.ini. PHP will be using this configuration file.
  3. Hold the Shift key and right click in the PHP directory to open the command-line window. The command-line window will be opened in the same location path. Issue the following command to start PHP:
    php-cgi –b 127.0.0.1:9000

    The –b option starts PHP and binds to the path for external FastCGI servers. The preceding command binds PHP to loop back the 127.0.0.1 IP on port 9000. Now, PHP is accessible on this path.

  4. To configure NGINX, open the nginx_folder/conf/nginx.conf file. The first thing to do is to add root and index to the server block, as follows:
    server {
      root html;
      index index.php index.html index.htm;
    

    Tip

    Downloading the example code

    You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

    You can download the code files by following these steps:

    • Log in or register to our website using your e-mail address and password.
    • Hover the mouse pointer on the SUPPORT tab at the top.
    • Click on Code Downloads & Errata.
    • Enter the name of the book in the Search box.
    • Select the book for which you're looking to download the code files.
    • Choose from the drop-down menu where you purchased this book from.
    • Click on Code Download.

    Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

    • WinRAR / 7-Zip for Windows
    • Zipeg / iZip / UnRarX for Mac
    • 7-Zip / PeaZip for Linux
  5. Now, we need to configure NGINX to use PHP as FastCGI on the path mentioned before on which it is started. In the nginx.conf file, uncomment the following location block for PHP:
    location ~ \.php$ {
      fastcgi_pass    127.0.0.1:9000;
      fastcgi_param    SCRIPT_FILENAME complete_path_webroot_folder$fastcgi_script_name;
    include    fastcgi_params;
    }

    Note the fastcgi_param option. The highlighted complete_path_webroot_folder path should be the absolute path to the HTML directory inside the nginx folder. Let's say that your NGINX is placed at the D:\nginx path; then, the absolute path to the HTML folder will be D:\nginx\html. However, for the preceding fastcgi_param option, \ should be replaced by /.

  6. Now, restart NGINX by issuing the following command in the root of the NGINX folder:
    nginx –s restart
    
  7. After NGINX is restarted, open your browser and enter the IP or hostname of your Windows server or machine, and we will see the NGINX welcome message.
  8. Now, to verify the PHP installation and its working with NGINX, create an info.php file in webroot and enter the following code in it:
    <?php
      phpinfo();
    ?>
  9. Now, in the browser, access your_ip/info.php, and we will be presented with a page full of PHP and server information. Congratulations! We configured NGINX and PHP to work perfectly together.

    Note

    On Windows and Mac OS X, we recommend that you use a virtual machine installed with all the tools on a Linux flavor to get the best performance out of the server. It is easy to manage everything in Linux. There are vagrant boxes available that have everything ready to use. Also, a custom virtual machine configuration with all the tools, including NGINX, Apache, PHP 7, Ubuntu, Debian, or CentOS, and other great ones, can be made at https://puphpet.com, which is an easy-to-use GUI. Another nice tool is Laravel Homestead, which is a Vagrant box with great tools.

You have been reading a chapter from
Learning PHP 7 High Performance
Published in: Apr 2016
Publisher: Packt
ISBN-13: 9781785882265
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image