Start learning PHP from the very beginning

Step by Step, Start from right-clicking on your desktop!

In this tutorial, you will learn

How to create your first PHP file in windows and run it. For creating PHP files in windows, we use Notepad++. Then we run a local server on our computer using Wamp Server which can run PHP files. If you already know these things, please go to the end of this page and see the next tutorial.

What you should know before starting?

You should know a little HTML, JavaScript, and CSS. If you don't know anything about these, first do some research and find out what these things are and what the use-case of them is. Also, you need a windows based PC to write and run codes. Of course, Mac or Linux is OK.

Let's get started

For getting started, I assume you know a little HTML, JavaScript, and CSS. You don't need to know everything and be a pro. You just need to know a little about these techniques and know what does any of them and what for created. If you don't know anything, first read some articles and tutorials on this website or other resources to be ready to become a PHP programmer.
To start programming, I assume that you are currently using the Windows operating system. I'm using Windows 10 - 64 bit, just right click on your desktop and create a new folder named "start". In the folder, right-click and select "Text Document" from the "New" menu to create a text file. Then rename it to "index".

Create new PHP file

Now you have a text file that you can open it with "Notepad". The extension of this file is ".txt" but in the default setting of windows, you can’t see the extensions.

can’t see the extensions

First, before doing anything, you must make a change in windows to show the extension of files. Go to "Control Panel" and choose "File Explorer Option". From the "View" tab, you need to uncheck "Hide Extensions for Known File Types" and click OK.

Show the extension of files

Now again take a look at your "index" file.

See the extension of file

You can see the extension of the file. Rename the file and change it to "index.php". Congratulations, you just created your first PHP file!

First PHP file

If you run this file with "double click", Windows will probably open it with "Notepad". All you need for PHP programming is the same text editor called "Notepad"! With Notepad, you can code big and complex PHP applications, but it's a bit difficult. A better solution is to use professional text editors designed for programming. Today, there are many text editors and even complex IDEs created for PHP programming you can use, but when I started 17 years ago, there weren't such things. I used to use a text editor called "Notepad ++" and still I'm using it. This text editor is a simple, free and good text editor for programming. To start, I recommend you use it, and when you become a professional, you can use other tools or maybe IDEs.

So Download and install it from below link:

After installation, your "index.php" file probably will open with this but if not, tell the windows to always use this application to open PHP files. Then open "index.php" and paste the following code to it and save the file.

<title>PHP Programming</title>  
<p>Hello PHP!</p>

As you can see, it is a few lines of simple HTML code, so, yes, you can use HTML in PHP and run it simply. Now it's time to run this file. As you probably know, PHP is a server-side language and you need a server to run it. Once again, rename the file to "index.html" and try to run it by double click. Probably internet browser installed on your computer will run the file successfully. Because we change the file type to HTML and HTML is a client-side language. But to run PHP we need a server that could run PHP. Change the file's name back to "index.php". If you have a Linux hosting on the internet, you can upload the file right now and then run it by typing its address in an internet browser like Chrome and see the result. But we want to do something this file could be run on our computer with windows so we can code and test PHP on our computer. Here a magical tool comes to help us and with installing it, we have a local server on our computer that can run PHP files on our installed Chrome. The name of this tool is Wamp Server and it’s an installable program for windows and it's free. From the address below you can download and install it:

This program will run a server like a Linux hosting on your computer that can run PHP and it's all you need to become a professional PHP developer.
After installation completed, run your Chrome and type "" in the address bar and press the Enter. Yes! You have a server on your computer.

Wamp Server running

The "" is running a file in a folder with the name "www" in your C drive. The folder is located somewhere like here:
Locate it and then open it. You will see some other folders and some PHP files in it. Don't do anything with them, just right-click in the "www" folder and create a new folder with the name "start" and place your "index.php" file in it. Now open this address in Chrome:

Bingo! your PHP file ran successfully and you see the result.

First PHP running

From now on, all your life will be is this "www" folder.  You will create new projects as new folders in this magical "www" folder and place your PHP files in those folders and then run their address in Chrome to see the results.

Challenge yourself

  1. Try to run the "start" folder directly without entering "index.php". What will happen? Do you know why?
  2. Try to change the name of the file to "test.php" and once again, run the "start" folder directly!

What’s next?

Introduction to PHP, Using PHP and HTML on the same page

In the next tutorial, we will learn how to write PHP codes and use variables and data, operators, conditional structures, and loops. We combine PHP codes with HTML codes and try to use the features that PHP programming language provides us to create dynamic HTML codes and understand the difference between using PHP or not.

Read next

Any Question?