Learnr

Learn PHP

Build dynamic websites with the language behind WordPress and Laravel.

or browse all courses.

Free to start. Built from a single prompt. No credit card.

PHP is a server-side scripting language built for the web: code runs on the server, often generating HTML, handling form submissions and talking to a database before the page reaches the browser. It powers WordPress and many other content management systems, and modern PHP 8 adds typed properties, match expressions and solid performance. Today most new PHP work uses Composer for packages and frameworks like Laravel or Symfony. Learnr builds a personalized PHP course from your prompt and teaches it through short, interactive lessons, from your first echo statement to a working database-backed app.

How to learn PHP, step by step

  1. Run PHP locally with the built-in server. Install PHP and start a server in your project folder with php -S localhost:8000. Write an index.php that mixes HTML with echo statements, and learn that the browser only ever sees the output.
  2. Learn arrays, which do almost everything. PHP arrays work as both lists and key-value maps. Practice foreach, array_map, array_filter, in_array and associative arrays, since most PHP data, including form input, arrives as arrays.
  3. Handle forms and validate on the server. Read input from $_POST and $_GET, validate and sanitize it, and escape output with htmlspecialchars to prevent cross-site scripting. Build a contact form that shows clear error messages.
  4. Connect to a database with PDO. Use PDO with prepared statements and bound parameters for every query, never string concatenation, which opens the door to SQL injection. Build a guestbook or notes app with create, read, update and delete.
  5. Add sessions and secure logins. Use session_start to remember users, store passwords with password_hash and check them with password_verify. These two functions handle salting and hashing correctly for you.
  6. Move to Composer and Laravel. Learn classes, namespaces and Composer autoloading, then rebuild your app in Laravel with routes, controllers, Blade templates and Eloquent models. Short Learnr lessons help keep core PHP syntax fresh.

What you'll learn

  • Write PHP with variables, arrays, functions and control flow
  • Process HTML forms and validate user input on the server
  • Store and query data securely with PDO prepared statements
  • Manage logins and state with sessions and password hashing
  • Structure a project with Composer and a framework like Laravel

What's inside your PHP course

A sample path Learnr builds for PHP. Your real course adapts to your goal and level.

  • 1. How server-side PHP works and running a local server
  • 2. Variables, strings, arrays and functions
  • 3. Forms, GET, POST and validation
  • 4. Databases with PDO and MySQL
  • 5. Sessions, authentication and security basics
  • 6. Composer, objects and an intro to Laravel

How long does it take to learn PHP?

Basic PHP and form handling take about 3 to 6 weeks at 5 hours a week. A secure database-backed app takes 2 to 4 months, and getting productive in Laravel adds 1 to 3 months. HTML and some programming experience make the start quicker.

What you need before you start

Comfortable HTML and some CSS, since PHP usually generates web pages. Basic SQL helps once you reach databases. You need PHP installed locally or a local stack like XAMPP.

Common mistakes to avoid

  • Building SQL queries by concatenating user input. Always use prepared statements with PDO or your framework's query builder to block SQL injection.
  • Echoing user input straight back into a page. Escape output with htmlspecialchars or a templating engine that escapes by default.
  • Learning from very old tutorials that use mysql_ functions or md5 passwords. Use modern PHP 8 sources with PDO and password_hash.

How Learnr builds your course

Type your topic

Tell Learnr you want to learn PHP, or get as specific as you like.

Get a personalized course

Learnr instantly builds a full PHP course tailored to your goal and skill level.

Learn and level up

Move through bite-sized lessons and interactive practice, earning XP and keeping your streak.

PHP questions, answered

Is PHP still worth learning?

Yes, for web development. WordPress runs on PHP, and Laravel is a productive framework for building web apps. Plenty of freelance and agency work involves PHP sites.

Should I learn PHP or JavaScript for the back end?

Both are solid. PHP is purpose-built for server-rendered websites and pairs naturally with WordPress, while Node.js lets you use JavaScript on both the front and back end.

What is Laravel?

Laravel is a PHP framework that provides routing, an ORM called Eloquent, templating, authentication scaffolding and queues. It is a common next step after learning plain PHP.

Explore more courses

More programming and tech courses

See all programming and tech courses

Ready to learn PHP?

Start your free, personalized PHP course in seconds. .