How to create a simple demo PHP website

If you already do not know what this PHP is all about, PHP is a language that is used at the backend of a web application to control the flow of the application. Based on the inputs that the user enters in the front-end, the script prepares, understands, manipulates, calculates and returns relevant data. That’s where we have the concept of a static and a dynamic website.

A demo PHP website may help you understand better, the concept of server side scripting. If you are new to web development and want to learn PHP as your first server side scripting language, then creating demo sites will prove very helpful.

Believe me, you actually get to experiment with so much of it, when you are creating a demo PHP website.

Building a demo site is simple. First, you need to chalk out what you want from your demo PHP website. After that, it is just the HTML CSS designing and running them with PHP.

Building our first demo PHP website

Where will you write? An editor? No, just open a notepad file and name it as “.php”

For the first demo, we obviously do the “Hello World” program. For this program, we do not require extensive HTML and CSS. The simple “echo” statement or “print” statement of PHP can do this.

However, since we need the HTML structure for further proceedings, we might create a frame of a website that will be helpful to us further down the line.

At the moment, we just create a container “div” in our PHP file. PHP tags are very friendly and can be implemented within HTML tags.

So, we create a file called “index.php” and store it in a folder. The file will contain the script for our first demo PHP website along with the HTML. The PHP tags will be in between the HTML tags. So, whatever data we need to display into a particular HTML area, we write the respective PHP code inside that HTML tag.

It’s simple.

Have a look at the below code. In our beginner’s demo PHP website, we have created a “container div” in HTML. Inside that, we have a header tag. Inside the tag, we print “Hello World” with the help of PHP.

Doing another demo PHP website – applying conditional statements

Applying conditions, iterations and data from the backend – that’s what all server side scripting languages are about. So, this time, we will provide some data from the front-end to our backend script and get output accordingly.

In this tutorial, our target is to create an HTML form. From the form, we will pass the user filled data to the server end, and then according to the user’s input, a conditional output shall be displayed.

This is not achievable with only HTML.

So, first we create the form. Creation of a form is very simple. So, we would not focus too much on that here.

Once the form is created, in the “action” attribute of the form tag, we will supply our PHP destination file that will handle the data. In the method attribute of the form, we will have “GET”.

Once the codes are ready, just keep all the files inside a folder with your custom provided name.

Now, how to test your demo PHP project?

Every server side scripting language requires a server configuration to be set up. Server configuration software include Apache and Tomcat. These software are used to transmit data in the form of HTTP requests.

Step 1: In our case we need not worry about all those complexities. Just install wampserver software and it will take care of the rest.