Lesson 1 – PHP Environment Setup

You need three vital components or software to run PHP pages. These software include a web server, a database, and a PHP Parser. You can individually install all these software on your computer. The other and better option is to install an open-source cross-platform web server such as XAMPP. XAMPP consists of MariaDB database, Apache HTTP Server and all the interpreters you need to run PHP.

Let us see how you can install XAMPP on Windows. However, you can also install the software on Linux and Mac.

  • Go to the download page of Apache Friends to download XAMPP.
  • Now get the latest version of XAMPP as shown in the image below.
  • Click on the XAMPP exe file to install XAMPP.
  • Just follow the instruction and install XAMPP like any other software on your computer.
  • Once installed, XAMPP’s dashboard will open which looks as follows.

Start the first two services that are Apache and MySQL in the dashboard and we are good to go.

Start the first two services that are Apache and MySQL in the dashboard and we are good to go.

The next step is to locate the XAMPP’s root folder. If you have installed XAMPP in the C drive, the path of the root folder will most likely by c/xamp/htdocs. Now, make a shortcut of htdocs on your desktop. We will put all our application folders and files in this very folder.

Writing Your First Code in PHP

The time has come to write your first code in PHP. Open htdocs folder and create a new folder named demo. Inside the demo folder, create a new file and name it demo.php or anything else you want. However, the extension should always be .php otherwise Apache will not recognize it as a PHP file. Now, open the file with the code editor of your choice.

Now, simply write the following piece of code in the code editor.

<?php 

echo "Hello World!";

?>

The echo function in PHP prints the result of the code. Similarly, you have to put semicolon (;) after every expression for it to work correctly.

The output of the above code is as below.

In the next chapter, we will discuss very basic PHP syntax