5 Best PHP Books for Beginners in 2021
You’re here to learn PHP. You know, the language you need to know if you want to get anywhere with WordPress — if you want to make templates or extensions.
PHP is one of the most popular web languages ever for communicating with servers and building dynamic content. Yes, even in 2020.
And truthfully, PHP can be scary. Words like ‘sessions,’ ‘cookies’, or ‘security’ can get intimidating. The concept of creating a login form and storing sensitive information can be, well, scary.
This article is about dispelling fear and taking action.
In this article, I’ve sourced user- and beginner-friendly books that are designed to not overwhelm and to truly teach you everything you need to know about PHP to be successful as a working web developer.
This is not a stock list just to sell you books. I look at the contents of every book and vet them with high standards. That’s why this list is of only five books and not twenty.
Why Learn PHP?
You may know PHP as the primary language behind your favorite content management system (CMS). WordPress, Drupal, and others communicate with a MySQL database to make managing content easy.
If you are a web developer, you may already encounter your fair share of PHP in templates. Perhaps you’ve kicked the language around a little, but you really want to know what’s going on.
Books can provide an in-depth knowledge that learning on the job is unlikely to provide.
PHP is also unique for its surprising origin story.
In 2015, PHP saw a massive update to PHP 7, which introduced the execution engine, Zend Engine 3.0, and therefore a huge performance upgrade. That’s why in the book recommendations, we’re going to be focusing on books that teach PHP 7 or later.
The Best PHP Books
What makes up the best PHP books?
The year is 2020 and we’re talking about programming. That means the more recent the book, the better. Other articles that slap ‘2020’ on the title will list books that are ancient — like over 10-years-old ancient.
Every book selected in this list is fewer than 5 years old. Some were even published in 2020. Each book teaches PHP 7 or later.
In addition to recent books, I look out for books that are truly beginner-friendly. These books are focused on helping you actually learn. That means these books do not overwhelm. They speak directly to you as a beginner programmer. They may even be fun.
Great books have great examples, too. They not only teach conceptual information, but they dive into the code and get you to code.
For more information on my philosophy selecting books, see How to Choose the Perfect Programming Book.
In addition, you can get complete access to almost all of these books for free with O’Reilly Learning.
Here are the best PHP books for beginners in 2020:
Book 1: Learn PHP in One Day and Learn It Well
This book covers a wide range of topics in PHP, carefully selected to give you broad exposure to the language. If you are an absolute beginner in PHP, you’ll find that this book explains complex concepts in an easy to understand and concise manner.
— Learn PHP in One Day and Learn It Well
Learn PHP in One Day and Learn It Well is an Amazon self-published 2020 book by Jamie Chan, who has taught programming for many years. The book is a part of his Learning Code Fast series, which teaches programming languages in a straight-forward, no-nonsense fashion. The book gives a brief overview of PHP and then dives right into setting up your environment and creating your first web page using PHP. It then proceeds to teach you everything you need to know about PHP. Truly.
If I was starting over with PHP, I would start with this book.
PHP is a language I learned by doing. I appreciate the style of this book and love its clarity and simplicity. On top of that, this book is inexpensive.
The book includes the following chapters:
Chapter 1: Introduction to PHP, which includes a brief explanation of what PHP is and why it is valuable to learn.
Chapter 2: Installing XAMPP, which walks through how to configure a
php.inifile and setup to run your environment locally.
Chapter 3: Basic PHP Tasks, which includes basics such as displaying outputs with
echo, escaping characters, and using basic methods like
Chapter 4: Constants, Variables, Data Types, and Operators in PHP, which is self explanatory, defining each of the items in the chapter title.
Chapter 5: More Data Type in PHP, which covers strings, common string functions, setting the timezone, arrays, and common array functions.
Chapter 6: Control Structures in PHP, which includes comparison operators, logical operators, control structures, if statements, the ternary operator, switch statements, for loops, foreach loops, while loops, do-while loops, booleans, break and continue, and more.
Chapter 7: Functions, which covers the definition of a function as well as type declaration.
Chapter 8: PHP Superglobals, which includes PHP form handling, get, post, filtering, sessions, cookies, and more.
Chapter 9: Object-Oriented Programming, which includes the definition of object-oriented programming, writing classes, writing objects, accessing class members and modifiers, gettings and setters, and printing objects.
Chapter 10: Inheritance, which covers writing child classes, creating child class objects, overriding, and more.
Chapter 11: Interacting with a Database, which includes the PDO library, connecting to the database, SQL injection, prepared statements, and more.
Chapter 12: Managing Errors and Exceptions, which includes handling exceptions,
try-catch-finally, handling errors, and more.
Chapter 13: Project, which goes over a complete PHP project, including all files.
Book 2: PHP & MySQL: Novice to Ninja
This book is focused entirely on PHP on MySQL, but don’t fall into the trap of thinking you’re learning PHP, but I’m using PHP to teach you to code.
— PHP & MySQL: Novice to Ninja
PHP & MySQL: Novice to Ninja by Tom Butler and Kevin Yank is a practical, example-driven book published in October 2017 that walks through the process of building a site with PHP and MySQL. The language in this book is informal, personable, and never intimidating. Each chapter is absolutely packed with an overarching example that you build and improve on throughout the book.
You will rarely find a book this friendly and yet this thorough. I most appreciate that the book gradually introduces clean code and pragmatic principles, so that the book not only teaches the ‘how,’ but the realistic thought process behind building up and refactoring code, piece by piece.
The book includes the following chapters:
Preface, which introduces the author, describes the audience who should read the book, describes how PHP programming has changed over time, and gives general advice on learning how to code.
Chapter 1: Installation. “Like baking a cake, you’ll need the ingredients before you can start following the recipe.” This section helps you set up your machine to run PHP, which includes installing all software components, using pre-packaged installations such as XAMPP, MAMP, or LAMP, setting up virtual servers, and more.
Chapter 2: Introducing PHP, which defines what PHP is with code examples. This chapter describes basic syntax and statements, variables, operators, comments, control structures, loops, forms, templating, security, and more.
Chapter 3: Introducing MySQL, which defines what MySQL is through the introduction of databases. The chapter immediately introduces the anatomy of a table, using MySQL workbench to run SQL queries, creating your own database, structured query language, creating a table, adding data, viewing, modifying, and deleting stored data, and more.
Chapter 4: Publishing MySQL Data on the Web helps you use MySQL and PHP together to display on a web page. The chapter first describes the architecture of the relationship between PHP, MySQL, the web server, and the web browser. The chapter then describes creating a MySQL user account, connecting to MySQL with PHP, object-oriented programming, sending queries with PHP, handling
SELECTresult sets, changing data into the database, and more.
Chapter 5: Relational Database Design, which is self-described as an “informal, non-rigorous” introduction to database design. The author acknowledges that “database design is a serious area of research” and “beyond the scope of this text.”
Chapter 6: Structured PHP Programming, which builds on top of the work in Chapter 4 with more advanced technique to hone your “PHP-fu”. The chapter introduces include files, custom functions and function libraries, clean code techniques like breaking up your code into reusable functions, and more with functions.
Chapter 7: Improving the Insert and Update Functions builds on top of the book’s project by improving and refactoring the code.
Chapter 8: Objects and Classes introduces objects and classes. The chapter goes over public vs private classes, class variables, object syntax, constructors, type hinting, private variables, updating the controller, introduces the concept of Don’t Repeat Yourself (DRY), creating the controller class, and more.
Chapter 9: Creating an Extensible Framework builds on the project by allowing users to register as authors and post to the database. The chapter continues to introduce clean code techniques such as making code generic as well as introduce concepts like implementing an autoloader.
Chapter 10: Allowing Users to Register Accounts describes validating email addresses, preventing the same person from registering twice, securely storing passwords, and more.
Chapter 11: Cookies, Sessions, and Access Control, which describes how users can register accounts and make those accounts functional so that they can log in.
Chapter 12: MySQL Administration, whichdescribes backups and access control to the MySQL database.
Chapter 13: Relationships, which describes using object relational mappers (ORM) to further build out the example website.
Chapter 14: Content Formatting with Regular Expressions, which describes what regular expressions are and how to use them to format content.
You may also be interested in these books:
Book 3: PHP and MySQL Web Development, Fifth Edition
We wrote the first edition of this book because we were tired of finding PHP books that were basically function references. These books are useful, but they don’t help when your boss or client has said, ‘Go Build me a shopping cart.’ In this book, we have done our best to make every example useful.
— PHP and MySQL Web Development, Fifth Edition
PHP and MySQL Web Development, Fifth Edition by Laura Thomson and Luke Welling is a 2017 publication and a clear labor of love from the authors of this book who are working engineers wishing to relay their practical experience.
The book declares they wanted to make a book that actually teaches people. With already five editions under its belt, I appreciate the authors revisit this book and continue to make it relevant for learners.
The book includes the following sections:
Part I: Using PHP
Chapter 1: PHP Crash Course
Chapter 2: Storing and Retrieving Data
Chapter 3: Using Arrays
Chapter 4: String Manipulation and Regular Expressions
Chapter 5: Reusing Code and Writing Functions
Chapter 6: Object-Oriented PHP
Chapter 7: Error and Exception Handling
Part II: Using MySQL
Chapter 8: Designing Your Web Database
Chapter 9: Creating Your Web Database
Chapter 10: Working with Your MySQL Database
Chapter 11: Accessing Your MySQL Database from the Web with PHP
Chapter 12: Advanced MySQL Administration
Chapter 13: Advanced MySQL Programming
Part III: Web Application Security
Chapter 14: Web Application Security Risks
Chapter 15: Building a Secure Web Application
Chapter 16: Implementing Authentication Methods with PHP
Part IV: Advanced PHP Techniques
Chapter 17: Interacting with the File System and the Server
Chapter 18: Using Network and Protocol Functions
Chapter 19: Managing the Date and Time
Chapter 20: Internationalization and Localization
Chapter 21: Generating Images
Chapter 22: Using Session Control in PHP
Chapter 24: Other Useful Features
Book 4: Programming PHP, 4th Edition
Programming PHP, 4th Edition by Kevin Tatro and Peter MacIntyre is a March 2020 publication that teaches PHP from the ground up, using the latest features in PHP 7.4. Unlike other books in this list, this book is broad and full-featured, broadening the scope of what you can do with PHP. The book describes using PHP not only with MySQL, but with JSON, XML, and even with creating PDFs.
I recommend this book if you are looking for a book that is new and goes beyond basics.
The book includes the following chapters:
Preface, which talks about the audience, assumptions the book makes, book contents, book conventions, contact information, and acknowledgements.
Chapter 1: Introduction to PHP, which includes what PHP does, a history of PHP, installing PHP, and various components such as the configuration page, forms, and databases.
Chapter 2: Language Basics, which includes everything about lexical structure, data types, variables, expressions and operators, flow-control statements like if and switch, include, embed, and more.
Chapter 3: Functions, which includes calling a function, defining a function, determining variable scope, passing function parameters, and more.
Chapter 4: Strings, which describes constants, printing, accessing individual characters, cleaning strings, encoding and escaping strings, comparing strings, and more.
Chapter 5: Arrays, which describes indexed vs. associative arrays, identifying elements of an array, storing data in arrays, multidimensional arrays, extracting multiple values, converting between arrays and variables, traversing arrays, sorting, and other array methods.
Chapter 6: Objects, which describes object terminology, creating an object, accessing properties and methods, declaring classes, anonymous classes, exampining classes, and more.
Chapter 7: Dates and Times, which describes how to use the
Chapter 8: Web Techniques, which describes HTTP basics, processing forms, setting response headers, maintaining state, and more.
Chapter 9: Databases, which describes using PHP to access a database, relational databases and SQL, the MySQLi object interface, SQLite, direct file-level manipulation, MongoDB, and more.
Chapter 10: Graphics, which includes embedding images as well as creating and drawing images.
Chapter 11: PDF, which describes how to use PDF extensions to convert your documents into PDFs.
Chapter 12: XML, which describes how to generate and parse XML with the DOM, SimpleXML, or XSLT.
Chapter 13: JSON, which describes how to use JSON to serialize PHP objects.
Chapter 14: Security, which describes safeguards, security vulnerabilities, and more.
Chapter 15: Application Techniques, which describes code libraries, templating systems, handling output, performance tuning, and more.
Chapter 16: Web Services, which describes REST clients, XML-RPC, and more.
Chapter 17: Debugging PHP, which describes environments such as the staging and production environment, configuring
php.ini, error handling, debugging, and more.
Chapter 18: PHP on Disparate Platforms, which describes writing portable code for Windows and Unix by determining the platform the user is on and accommodating those differences. The chapter also talks about interfacing with COM.
Book 5: Mastering PHP 7
Mastering PHP 7 by Branko Ajzele is a 2017 publication that focuses on building skills and bringing them to the next level. Because the first four books in this list are so quality and already thoroughly cover the basics, I thought I would introduce your “second book” to learning PHP. This book assumes that you know the programming basics and teaches you how to improve as a PHP developer.
This book has the following chapters:
Chapter 1: The All New PHP, which describes the changes introduced to PHP 7.1, which were the latest changes at the book’s publication.
Chapter 2: Embracing Standards, which describes important standards in the PHP ecosystem. The standards can affect the quality of code and helps you get closer to mastering PHP.
Chapter 3: Error Handling and Logging, which describes how to handle errors and logs.
Chapter 4: Magic Behind Magic Methods, which describes ‘magic’ functions available in PHP classes. This chapter describes every method, its meaning, and its use.
Chapter 5: The Realm of CLI, which describes command-line PHP and its tools and processes. The chapter describes how to use the Symfony Console component to handle processes.
Chapter 6: Prominent OOP Features, which describes a subset of features that turn PHP into an object-oriented programming language.
Chapter 7: Optimizing for High Performance, describes the importance of performance optimization and details about how to achieve it.
Chapter 8: Going Serverless, which describes how to build a serverless infrastructure with PHP.
Chapter 9: Reactive Programming, which describes an emerging reactive programming paradigm that is now in the PHP ecosystem. This chapter teaches basic principles of reactive programming using synchronous coding techniques to write asynchronous code.
Chapter 10: Common Design Patterns, which describes the most common design patterns used in PHP. The chapter covers practical implementation of these patterns.
Chapter 11: Building Services, which walks through REST, SOAP, and RPC services alongside the microservice architecture.
Chapter 12: Working with Databases, which describes several types of databases including SQL, NoSQL, key-value, and search databases. The chapter goes over how to query MySQL, Mongo, and Redis databases.
Chapter 13: Resolving Dependencies, which describes dependency issues and how to resolve them.
Chapter 14: Working with Packages, which describes PHP packages, their creation, and their distribution.
Chapter 15: Testing the Important Bits, which describes several types of testing for PHP web applications.
Chapter 16: Debugging, Tracing, and Profiling, which describes commons tools for debugging, tracing, and profiling PHP applications.
Chapter 17: Hosting, Provisioning, and Deployment, which describes how to make an informed decision for hosting the environment as well as setting up your environments.
Honorable Mention: PHP & MySQL: Server-side Web Development
Below example pages from HTML & CSS:
Needless to say, I’m hyped for the release. The book is available for preorder on Amazon now.
PHP is a very established language, so I was delighted to see that there are so many quality books on the language. With each book I reviewed, I felt like every one of them were my favorite. They checked the boxes of good structure, style, voice, and clarity.
PHP is a worthwhile language to learn as a web developer. You may feel like it is a language not talked about often, as it is so established and there are more options now to communicate with the server through a web browser.
I highly recommend PHP to anyone who expect to be working at marketing agencies on large websites or blogs that rely on a PHP-based content management system.
Also, if you are interested in getting complete access to any of these books digitally, you can read them for free with O’Reilly Learning. Their digital library is insanely vast and I am constantly surprised that almost every book lives digitally on the platform.
In addition to books, you can also learn PHP with inexpensive online classes. I highly recommend the Coursera class Building Web Applications in PHP or the free Codecademy PHP course, just to name a couple.
Once you’re done here, I have another treat for you: there’s a free resource for front-end developers that everyone needs to know about. It’s called the Front-End Developer Handbook. I will see you over there in that article. 👋😁