PHP Tutorial [Part 1]

Menu
Installation and Basics
The Basics
Variables
If Statements
For Loops
While Loops

Welcome to the php tutorial!  There are a few things I hope you know before we get started.

  • A basic HTML knowledge, so you can format your outputs how you would like.
  • PHP installed on your computer, preferably with a web server as well to view the html we create.

All you need to run PHP, and all we will use right now, is notepad and php.  You can get php from php.net.  Simply chose the OS you run, download it, and install it.  Since the majority of the internet uses a PC, we will assume for the sake of the tutorial that you are downloading it for windows.  Mac users have it easy because it comes preinstalled on their system.

To access PHP after it has been installed.  Open cmd.exe and navigate to the folder of choice (“cd c:\php\” if you saved it in c:\php\).  Macs just open terminal and you are set to go.

Lets test it now.  Open a new text document and type:

<?php
echo "Hello World!";
?>

Save it as “hello.php”. With cmd.exe or terminal still open, just type:

php hello.php

You should see the output “Hello World!”, and you have just written your first PHP script.

**Installation tips!**

Every operating system has bundled packages, with PHP, MySQL, and Apache (all 3 you will need). I recommend installing that versus just PHP as it will take more time later on to install MySQL and Apache and get them configured appropriately.
For Windows: Wamp Server or XAMPP are both very popular bundles.
For Mac: MAMP or XAMPP are the most popular ones.
For Linux: LAMP or XAMPP are popular.
I would recommend anyone new to PHP and webservers to download one of these packages just because it will set them up without the user having to do very much. Once it is running, you will be able to point your browser to http://localhost/ to view the scripts you have created.

Next up – The Basics

Pages: 1 2 3 4 5 6