Want to learn how to build a basic website? Once you might have started with HTML, but these days the best solution is PHP. While you'll need some knowledge of HTML to get started, PHP has become the optimum choice for building websites, both static and dynamic.

Looking for answers to the question of how to develop a website using PHP would be a very good way to get started. The best step you can take in your PHP learning journey is to develop a website using PHP.

Why Choose PHP for Website Development?

Various options have been available for web development over the years. It started with plain HTML, then HTML with CSS embedded or a CSS file reference. When dynamic websites came along, there were two main choices: ASP (later ASP.NET) and PHP.

According to figures (such as this W3Techs survey), PHP web development is far more popular, with almost 82 percent of websites using PHP as a server-side programming language. Compare this with just under 16 percent using ASP.NET.

It seems unlikely that ASP.NET will exist further in any official capacity, at least not as a web technology. PHP (a recursive acronym for PHP Hypertext Preprocessor) has proven more successful, mainly thanks to easier integration with Linux.

As Linux open-source operating systems run on most web servers, this should not come as a surprise.

What You'll Need to Build a PHP Website

Before starting, be sure you have a plain text editor or PHP-ready development environment installed. You can start coding PHP with a tool as simple as Windows Notepad. Examples found in this tutorial have been written in Notepad++. You can use any text editor you feel comfortable with to write your PHP website codes.

You should also have a PHP web server to upload your files to. This might be a remote server, or a local computer with a LAMP (Linux, Apache, MySQL, PHP) or WAMP (Windows, Apache, MySQL, PHP) environment installed. If you're using Windows, follow this WAMP installation guide to get started.

Finally, you'll need an FTP program to upload your files to your web server. Alternatively, you can manually drag and drop your files by going directly to the www folder of your PHP web server. However, in cases where you will manage your site remotely, it may be advantageous to use the FTP program.

Understand Syntax to Code a Simple Web Page Using PHP Code

The basic syntax for PHP uses a set of angled brackets, with each function ending with a semi-colon, like this:

        <!--?php [CODE…CODE]; ?-->
    

In terms of web pages, almost every use of PHP relies on the echo statement. This instructs the browser to output the text and content in the quotes. For example:

        <?php echo "Hello World"; ?>
    

Note that the HTML is also included within the quotes. The output for this would typically appear as:

Hello world in PHP

How to Create a Website Using PHP: Get the Structure Right

Whatever code you're writing your website with, you will need to know the structure of the site before proceeding. This tutorial will show you how to create a single page from reusable PHP files. These might be used to make additional pages, or you may choose a different approach.

Whatever shape you foresee the site developing, take the time to jot down a quick plan on a piece of paper. You can then refer to this, perhaps to check the intended content, or see what page to link it to.

Our basic PHP website is going to feature a home page, including biographical information and some images.

For this simple PHP website, you're going to create a single PHP page populated by content from three HTML pages. The index.php file you create can then be edited by adjusting the words and images from the original HTML files.

The code examples shown below are screenshots. You'll find the original code in my GitHub repository, which is free for anyone to download.

Read on to learn how to develop a website using PHP step-by-step.

Make a PHP Website: The Header

To create a website using PHP, you'll need to construct three web pages. These are based on the basic structure of the header, body, and footer.

As you can imagine, the header contains the header information. You can also add the CSS references and standard meta tags you want to use in this field.

Start by creating a file called header.html then add the necessary header information.

how to build a php website

For this example, we've provided a basic CSS file, which you will see is referenced in its own /css/ directory. This file will be called when the page loads in your browser and apply the required font and layout.

Put Content in Your PHP Web Page Body

Every web page consists of a content section known as the "body". This is the part of a page that you read—what you're reading now is the body of this page.

how to create a web page using php

Create a file called body.html and add the information you want to include on the page. I've included biographical details from my MakeUseOf author page, but you can add whatever you like.

The footer section of the web page is next. Create this as footer.html and add some content.

Consider including copyright information to safeguard your work or, even better, incorporate a collection of valuable links to enrich the experience of every visitor to your page.

It might be something like this:

how to make a php website

With the code added, save the file.

Putting Your Simple PHP Website Together

With three separate HTML files in /html/ you can use PHP echo to compile them into a single page.

Create a new PHP file called index.php with the following three lines in it:

        <?php echo file_get_contents("html/header.html"); ?>
<?php echo file_get_contents("html/body.html"); ?>
<?php echo file_get_contents("html/footer.html"); ?>

Save, upload to your server, then browse to index.php. You should see the completed web page in your browser. Keep in mind that the actual PHP file you have open in your browser consists of just three lines.

Finally, you can add a little PHP flourish with the final line. Include a copyright notice, with an always-updated year:

        <p>Copyright &copy; CM Cawley <?php echo date("Y"); ?></p>
    

This will appear in the index.php file following the footer. Notice how the echo date("Y") statement displays the current year in four digits. You can change how this is displayed by referring to the official PHP documentation. For example, a lower-case "y" would display the year in two-digit format, rather than four.

Use CSS to position and style it, as you would with any other element. Find the CSS for this project in the GitHub repository, along with the other simple PHP website code.

Well done—you've just created your first PHP website from scratch. Now it's time to look at more PHP website examples to improve your skills.

Is PHP the Best Choice for Coding Websites?

php website examples

Now you know how to develop a PHP website, you should know that it isn't the only way to develop websites. Many frameworks exist already for dynamic, database-driven web experiences, there's JavaScript and related technologies, and software like Adobe Dreamweaver.

However, if you're looking to get started with PHP web development, it's smart to have an appreciation of the basics. If you understand the website building blocks of HTML, CSS, and PHP, you're well on the way to success.