How do i start learning php programming?

Learn PHP

PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.

PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

Start learning PHP now »

Easy Learning with "PHP Tryit"

With our online "PHP Tryit" editor, you can edit the PHP code, and click on a button to view the result.

Example




Try it Yourself »

Click on the "Try it Yourself" button to see how it works.

PHP Exercises

PHP Examples

Learn by examples! This tutorial supplements all explanations with clarifying examples.

See All PHP Examples

PHP Quiz Test

Learn by taking a quiz! This quiz will give you a signal of how much you know, or do not know, about PHP.

Start PHP Quiz!

My Learning

Track your progress with the free "My Learning" program here at W3Schools.

Log into your account, and start earning points!

This is an optional feature. You can study W3Schools without using My Learning.

PHP References

W3Schools' PHP reference contains different categories of all PHP functions, keywords and constants, along with examples.


Kickstart your career

Get certified by completing the course

Get certified

w3schoolsCERTIFIED.2022



The PHP guide for beginner developers.

Do you want to learn PHP, even if you have no experience?
Then this is the perfect guide for you.

I’m going to show you the exact steps to go from absolute beginner to PHP developer quickly and easily.

Let’s get started.

Contents

  • Before you begin.
  • Step 1: your study environment.
  • Step 2: your first PHP page.
  • Step 3: variables and operations.
  • Step 4: functions.
  • Step 5: control structures.
  • Step 6: the request string.
  • Step 7: Sessions.
  • Next steps?

Before you begin.

In this tutorial I’m going to guide you through all the steps to become a PHP developer, starting from the very beginning.

I’ll show you which tools to install on your computer, which topics to study and in which order, and the important PHP documentation pages to read.

If you prefer an easier, faster and more efficient approach, consider enrolling in my Jump Start course.
It’s a course specifically designed for absolute beginners, 100% written by me.

In Jump Start I take care of explaining every single detail, as well as providing plenty of code examples to make it all super clear.
Look at the details and judge for yourself.

If you prefer to follow this guide for a more “do-it-yourself” approach, then keep reading.

Step 1: your study environment.

You need two things to start coding in PHP:

  • A local development environment.
  • A code editor.

Install a local development environment.

To run a PHP script, you need an interpreter that understands and runs the code.

When you open a PHP webpage online, the remote web server acts as the PHP interpreter executing the PHP code and sending the output to your browser.

A local development environment, or LDE for short, is a software package that lets you run PHP scripts on your computer.

It provides you with everything you need to develop PHP applications: the PHP interpreter, a web server, a SQL database [usually MySQL/MariaDB] and other utilities like PhpMyAdmin.

There are many free LDEs you can choose from, including:

  • XAMPP [for Windows and Mac]
  • MAMP [for Windows and Mac]
  • Laragon [for Windows]

If you’re not sure which one to go with, I suggest you try XAMPP because it’s easy and fast to set up.

This is how the XAMPP control panel looks like:

Install a code editor.

A code editor is an advanced text editor that helps you write your code.

Code editors provide useful functionalities such as:

  • line numbers
  • syntax highlighting
  • code autocompletion and assist
  • advanced search functionalities
  • plugins and extensions

Popular code editors include Atom, Brackets and Notepad++.

For example, here’s a screenshot of a PHP script opened with Atom:

Atom and Brackets are modern and simple editors.
If you prefer a more classic-looking, feature-packed editor, then Notepad++ is the right choice.
In any case, you can’t go wrong with any of them.


When you have chosen and installed your editor, you are ready to move on to the next step.

Side note:

There are also more advanced editors called IDEs [integrated developers environments], such as Eclipse, Visual Studio Code, Netbeans, and more.
They are a better choice for more experienced developers, but as long as you are learning the basics I suggest you use a simpler code editor instead.

Step 2: your first PHP page.

Before you write your first PHP page, it’s worth spending just a few minutes reading about the language basics.

Here are two pages from the official PHP documentation that I want you to read:

  • What is PHP?
    A very short introduction to the language [3 minutes read]
  • What can PHP do?
    An overview of what PHP can do [5 minutes read]

All right, now it’s finally time to write your first PHP Hello World script.

Start your local development environment and make sure the web server is running.

Then, open a web browser and type localhost in the URL bar. You will see the local web server’s homepage. If you are using XAMPP, the page will look like this:

Where to save your PHP scripts.

Your PHP scripts must be placed inside a directory called webserver root.

This directory is usually the htdocs directory located inside the development environment’s own installation directory.

In XAMPP, you can open this directory from the XAMPP Control Panel by clicking on the Explorer button [this will open the XAMPP main directory], and then opening the htdocs directory:

Remember: you must save your scripts in this htdocs directory.

Now open your code editor and paste the following PHP code:

Chủ Đề