Learning PHP 7 High Performance - Altaf Hussain - E-Book

Learning PHP 7 High Performance E-Book

Altaf Hussain

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Improve the performance of your PHP application to ensure the application users aren't left waiting

About This Book

  • Make the optimum use of PHP coding to improve your programming productivity
  • Leverage the potential of PHP for server-side programming, memory management, and object-oriented programming
  • Packed with real-life examples to help the readers implement concepts as they learn

Who This Book Is For

This book is for those who have basic experience in PHP programming. If you are developing performance-critical applications, then this book is for you.

What You Will Learn

  • Setup high performance development and production environment for PHP 7
  • Discover new OOP features in PHP 7 to achieve high performance
  • Improve your PHP applications' performance
  • Attain improved database performance
  • Benchmark PHP applications to optimize them
  • Write quality code by learning to improve code reusability, simplicity, and expressiveness
  • Get rid of the bottlenecks in your PHP 7 applications by writing PHP code optimally
  • Tackle issues related to web applications, such as high user dependency and large datasets

In Detail

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, providing major backward-compatibility breaks and focusing on high performance and speed.

This fast-paced introduction to PHP 7 will improve your productivity and coding skills. The concepts covered will allow you, as a PHP programmer, to improve the performance standards of your applications. We will introduce you to the new features in PHP 7 and then will run through the concepts of object-oriented programming (OOP) in PHP 7. Next, we will shed some light on how to improve your PHP 7 applications' performance and database performance. Through this book, you will be able to improve the performance of your programs using the various benchmarking tools discussed.

At the end, the book discusses some best practices in PHP programming to help you improve the quality of your code.

Style and approach

The book is a step-by-step guide to improve the quality of your code in PHP through real-time examples. The book takes a practical approach to improving the quality of your code.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 219

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Learning PHP 7 High Performance
Credits
About the Author
Acknowledgement
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Setting Up the Environment
Setting up Windows
Setting up Debian or Ubuntu
Debian
Ubuntu
Setting up CentOS
Installing NGINX
Installing PHP 7
Installing Percona Server
Setting up Vagrant
Summary
2. New Features in PHP 7
OOP features
Type hints
Scalar type hints
Return type hints
Namespaces and group use declaration
Non mixed group use declarations
Mixed group use declarations
The compound namespace declaration
The anonymous classes
Old-style constructor deprecation
The throwable interface
Error
New operators
The Spaceship operator (<=>)
The null coalesce operator(??)
Uniform variable syntax
Miscellaneous features and changes
Constant arrays
Multiple default cases in the switch statement
The options array for session_start function
Filtered unserialize function
Summary
3. Improving PHP 7 Application Performance
NGINX and Apache
Apache
NGINX
HTTP server optimization
Caching static files
Apache
NGINX
HTTP persistent connection
Apache
NGINX
GZIP compression
Apache
NGINX
Using PHP as a separate service
Disabling unused modules
Apache
NGINX
Web server resources
NGINX
Content Delivery Network (CDN)
Using CDN
CSS and JavaScript optimization
Merging
Minifying
Minify
Grunt
Full page caching
Varnish
The infrastructure
Web servers
The database server
Load balancer (LB)
HAProxy load balancing
HAProxy installation
HAProxy load balancing
Summary
4. Improving Database Performance
The MySQL database
Query caching
Storage engines
The MyISAM storage engine
The InnoDB storage engine
innodb_buffer_pool_size
innodb_buffer_pool_instances
innodb_log_file_size
The Percona Server - a fork of MySQL
Installing the Percona Server
MySQL performance monitoring tools
phpMyAdmin
The MySQL workbench
Percona Toolkit
pt-query-digest
pt-duplicate-key-checker
Percona XtraDB Cluster (PXC)
Redis – the key-value cache store
Connecting with the Redis server
Storing and fetching data from the Redis server
Redis management tools
Memcached key-value cache store
Summary
5. Debugging and Profiling
Xdebug
Debugging with Sublime Text
Debugging with Eclipse
Profiling with Xdebug
PHP DebugBar
Summary
6. Stress/Load Testing PHP Applications
Apache JMeter
ApacheBench (ab)
Siege
Load testing real-world applications
Magento 2
WordPress 4
Drupal 8
Summary
7. Best Practices in PHP Programming
Coding styles
Test-driven development (TDD)
Design patterns
Service-oriented architecture (SOA)
Being object-oriented and reusable always
PHP frameworks
Version control system (VCS) and Git
Deployment and Continuous Integration (CI)
Summary
A. Tools to Make Life Easy
Composer – A dependency manager for PHP
Composer installation
Using Composer
Git – A version control system
Git installation
Using Git
Creating new branches and merging
Cloning a repository
Webhooks
Desktop tools to manage repositories
Grunt watch
Summary
B. MVC and Frameworks
The MVC design pattern
Model
Views
Controllers
Laravel
Installation
Features
Routing
Eloquent ORM
Artisan CLI
Migrations
Blade templates
Other features
Lumen
Apigility
Summary
Index

Learning PHP 7 High Performance

Learning PHP 7 High Performance

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: April 2016

Production reference: 1190416

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78588-226-5

www.packtpub.com

Credits

Author

Altaf Hussain

Reviewer

Raul Mesa Ros

Commissioning Editor

Kunal Parikh

Acquisition Editor

Vinay Argekar

Content Development Editor

Priyanka Mehta

Technical Editor

Ravikiran Pise

Copy Editor

Shruti Iyer

Project Coordinator

Izzat Contractor

Proofreader

Safis Editing

Indexer

Rekha Nair

Graphics

Abhinash Sahu

Production Coordinator

Manu Joseph

Cover Work

Manu Joseph

About the Author

Altaf Hussain is a fullstack web and mobile app developer with over 6 years of experience in PHP development. He received his degree in electrical engineering and specialized in computer and communications from Pakistan. Altaf is an electrical engineer on paper and a software engineer by heart.

He worked as a system programmer in his team, developing control software for small test robots using assembly languages and C. After this, Altaf got interested in web technologies and never looked back. He has worked with numerous PHP frameworks, including Zend, Laravel, and Yii, and open source systems such as Drupal, WordPress, PrestaShop, and Magento. Altaf designed and built two proprietary CMS systems with full support for multiple languages and models, permissions, and translations, as well as different kinds of multilingual content management. Now, he works in the fashion industry as the head of IT at shy7lo.com, where his role is to manage the development team on the premises and abroad, in order to manage Magento and Laravel applications development and the deployment life cycle. Besides web apps, Altaf has worked on iOS and Android applications, including building APIs in Lumen. He is a big fan of service-oriented architecture (SOA) and successfully uses it in different applications.

Altaf actively researches on website performance and has deployed the latest technologies, such as PHP 7, NGINX, Redis, Varnish, and others, in production environments for high-speed and scalable applications. He is a Debian lover and uses it for all of his web application deployments.

When not working, Altaf writes articles for programmingtunes.com and techyocean.com. He has reviewed several books for Packt Publishing, including Learning Phalcon PHP, Mastering jQuery Mobile, and PrestaShop Module Development.

Acknowledgement

I would like to thank my parents, wife, and son, Haashir Khan, who were all very helpful during the development of this book and my overall career. Without their help and support, this book would not have been possible to complete. I would also like to thank the PHP community for creating such awesome and beautiful tools and making the life of a web developer easy.

About the Reviewer

Raul Mesa has been writing software for the Web since 2006. He started with Java, later moved on to PHP, and obtained several certifications such as Zend Engineer and Zend Framework. Having worked on several high-traffic web projects, Raul is nowadays very interested in the DevOps philosophy.

He currently works as a senior web developer at EuroMillions.com using DevOps and PHP technologies. Raul also leads various small-to-medium sized projects.

His twitter handle is @rmrbest.

I would like to thank my wife, Noemi, and my daughter, Valeria, for their support and love, and also my father who bought me my first computer back in 1992.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

The PHP community faced a huge problem over decades: performance. No matter how powerful hardware they got, in the end, PHP was a bottleneck in itself. With PHP 5.4.x, 5.5.x, and 5.6.x, PHP's performance started to improve, but still it was a huge problem in high-load applications. The community developed caching tools such as Alternative PHP Cache (APC) and Zend OpCache, which cached the opcode for high performance, and these tools had a good effect on the performance.

To get rid of the performance issues of PHP, Facebook built their own open source tool called HHVM (HipHop Virtual Machine). According to their official website, HHVM uses the Just In Time (JIT) compilation to achieve superior performance while maintaining the development flexibility that PHP provides. HHVM had great performance compared to PHP, and it is widely used in production for heavy applications such as Magento.

PHP went to war with HHVM using PHP Next Generation (PHPNG). The whole purpose of PHPNG is to increase performance and focus on the rewriting and optimization of the Zend engine memory allocation and PHP data types. People around the world started benchmarking PHPNG and HHVM, and according to them, PHPNG was outperforming HHVM.

At last, PHPNG was merged with the master branch of PHP, and after a tremendous amount of optimization and complete rewriting, PHP 7 was released with huge performance improvements. PHP 7 is still not JIT, but its performance is great and similar to HHVM. This is a huge performance increase from the older versions of PHP.

What this book covers

Chapter 1, Setting Up the Environment, covers how to set up different development environments, including the installation of NGINX, PHP 7, and Percona Server on Windows, different Linux distros, and setting up the Vagrant virtual machine for development purposes.

Chapter 2, New Features in PHP 7, covers the major new features introduced in PHP 7, including Type Hints, Group use Declarations, Anonymous classes, and new operators, such as Spaceship operator, Null Coalesce operators, and the Uniform variable syntax.

Chapter 3, Improving PHP 7 Application Performance, covers different techniques to increase and scale a PHP 7 application's performance. In this chapter, we cover optimization of NGINX and Apache, CDN, and CSS/JavaScript, such as merging and minifying them, full-page caching, and installing and configuring Varnish. At last, we discuss an ideal infrastructure setup for application development.

Chapter 4, Improving Database Performance, covers techniques to optimize MySQL and Percona Server configuration for high performance. Also, it covers different tools to monitor the performance of a database. It also covers Memcached and Redis for caching objects.

Chapter 5, Debugging and Profiling, covers debugging and profiling techniques including the use of Xdebug for debugging and profiling, debugging with Sublime Text 3 and Eclipse, and the PHP DebugBar.

Chapter 6, Stress/Load Testing PHP Applications, covers different tools to stress and load test the application. It covers Apache JMeter, ApacheBench, and Siege for load testing. It also covers how to load test different open source systems such as Magento, Drupal, and WordPress on PHP 7 and PHP 5.6, and compares their performance on PHP 7 and PHP 5.6.

Chapter 7, Best Practices in PHP Programming, covers a few best practices for producing quality standard code. It covers coding styles, design patterns, service-oriented architecture, test-driven development, Git, and deployments.

Appendix A, Tools to Make Life Easy, discusses three of these tools in much more detail. The tools we will discuss are Composer, Git, and Grunt watch.

Appendix B, MVC and Frameworks, covers MVC design patterns and the most popular frameworks that are used in PHP development, which include Laravel, Lumen, and Apigility.

What you need for this book

Any hardware specification that is compliant to run the latest versions of the following software should be enough to get through this book:

Operating systems: Debian or UbuntuSoftware: NGINX, PHP 7, MySQL, PerconaDB, Redis, Memcached, Xdebug, Apache JMeter, ApacheBench, Siege, and Git

Who this book is for

This book is for those who have basic experience in PHP programming. If you are developing performance-critical applications, then this book is for you.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME complete_path_webroot_folder$fastcgi_script_name; include fastcgi_params; }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

server { … … root html; index index.php index.html index.htm; …

Any command-line input or output is written as follows:

php-cgi –b 127.0.0.1:9000

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

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.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

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

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/LearningPHP7HighPerformance_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Setting Up the Environment

PHP 7 has finally been released. For a long time, the PHP community was talking about it and has still not stopped. The main improvement in PHP 7 is its performance. For a long time, the PHP community faced performance issues in large-scale applications. Even some small applications with high traffic faced performance issues. Server resources were increased, but it did not help much because in the end the bottleneck was PHP itself. Different caching techniques were used, such as APC, and this helped a little. However, the community still needed a version of PHP that could boost the application's performance at its peak. And this is where PHPNG comes in.

PHPNG stands for PHP next generation. It is a completely separate branch and is mainly targeted for performance. Some people thought that PHPNG is JIT (Just In Time) compilation, but in reality, PHPNG is based on a refactored Zend Engine, which was highly optimized for performance. PHPNG is used as a base for PHP 7 development, and according to the official PHP wiki page, the PHPNG branch is now merged into the master branch.

Before starting to build an application, the development environment should be finalized and configured. In this chapter, we will discuss setting up the development environment on different systems, such as Windows and different flavors of Linux.

We will cover the following topics:

Setting up WindowsSetting up Ubuntu or DebianSetting up CentOSSetting up Vagrant

All other environments can be skipped, and we can set up the environment that we will use.

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:

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.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.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.

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 WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux
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 /.

Now, restart NGINX by issuing the following command in the root of the NGINX folder:
nginx –s restart
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.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(); ?>
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.

Setting up Debian or Ubuntu

Ubuntu is derived from Debian, so the process is the same for both Ubuntu and Debian. We will use Debian 8 Jessie and Ubuntu 14.04 Server LTS. The same process can be applied to desktop versions for both.

First, add the repositories for both Debian and Ubuntu.

Debian

As of the time we're writing this book, Debian does not provide an official repository for PHP 7. So, for Debian, we will use dotdeb repositories to install NGINX and PHP 7. Perform the following steps:

Open the /etc/apt/sources.list file and add the following two lines at the end of the file:
deb http://packages.dotdeb.org jessie all deb-src http://packages.dotdeb.org jessie all
Now, execute the following commands in the terminal:
wget https://www.dotdeb.org/dotdeb.gpgsudo apt-key add dotdeb.gpgsudo apt-get update

The first two commands will add dotdeb repo to Debian and the last command will refresh the cache for sources.

Ubuntu

As of the time of writing this book, Ubuntu also does not provide PHP 7 in their official repos, so we will use a third-party repo for the PHP 7 installation. Perform the following steps:

Run the following commands in the terminal:
sudo add-apt-repository ppa:ondrej/phpsudo apt-get update
Now, the repositories are added. Let's install NGINX and PHP 7.

Note

The rest of the process is mostly the same for both Debian and Ubuntu, so we wont list them separately, as we did for the adding repositories section.

To install NGINX, run the following command in the terminal (Debian and Ubuntu):
sudo apt-get install nginx
After the installation is successful, it can be verified by entering the hostname and IP of the Debian or Ubuntu server. If we see something similar to the following screenshot, then our installation is successful:

The following is a list of three useful NGINX commands:

service nginx start: This starts the NGINX serverservice nginx restart: This restarts the NGINX serverservice nginx stop: This stops the NGINX server
Now, it's time to install PHP 7 by issuing the following command:
sudo apt-get install php7.0 php7.0-fpm php7.0-mysql php7.0-mcrypt php7.0-cli

This will install PHP 7 along with the other modules mentioned. Also, we installed