Building a simple PHP website is a great way to start exploring web development. PHP (Hypertext Preprocessor) is a widely-used open-source scripting language that is especially suited for web development and can be embedded into HTML. In this article, we will guide you through the process of creating a basic PHP website step-by-step.
Also Read: PHP Basics For Beginners With Examples
Prerequisites
Before you begin, ensure you have the following:
---
Web Server: You need a web server like Apache or Nginx installed on your local machine or a hosting service.
PHP: Install PHP on your machine. You can download it from php.net.
Text Editor: Use a text editor or an IDE (Integrated Development Environment) like VS Code, Sublime Text, or PHPStorm.
Basic Understanding: Familiarity with HTML, CSS, and basic programming concepts will be helpful.
Also Read: Advantages of PHP (Over Other Web Programming Languages)

Setting Up Your Environment
Install PHP: After downloading PHP, follow the installation instructions provided for your operating system.
Configure Web Server: If you’re using Apache, ensure it’s running. For Nginx, configure it to process PHP files.
Create Your Project Directory Structure
Create a new directory for your project. Inside this directory, create the following files:
index.php: This will be your main PHP file.style.css: For basic styling (optional).header.php,footer.php(optional): Separate files for header and footer.
Writing Your First PHP Script
Open index.php in your text editor and start with the following basic PHP script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Simple PHP Website</title> <link rel="stylesheet" href="style.css"> </head> <body> <?php include 'header.php'; ?> <div class="container"> <h1>Welcome to My Website</h1> <p>This is a simple PHP website.</p> <p>Today's date is <?php echo date('Y-m-d'); ?></p> </div> <?php include 'footer.php'; ?> </body> </html> |
Adding Header and Footer (optional)
Create header.php and footer.php files. This is header.php
1 2 3 4 5 6 7 8 9 | <header> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav> </header> |
This is footer.php
1 2 3 | <footer> <p>© <?php echo date('Y'); ?> Simple PHP Website. All rights reserved.</p> </footer> |
Adding CSS
In style.css, add basic styling:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | body { font-family: Arial, sans-serif; line-height: 1.6; background-color: #f0f0f0; margin: 0; padding: 0; } .container { width: 80%; margin: 20px auto; background-color: #fff; padding: 20px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } header { background-color: #333; color: #fff; padding: 10px 0; text-align: center; } header nav ul { list-style-type: none; margin: 0; padding: 0; } header nav ul li { display: inline; margin-right: 10px; } header nav ul li a { color: #fff; text-decoration: none; } |
Testing Your Website
Save all files and place them in your web server’s document root (e.g., htdocs in XAMPP).
Open your web browser and navigate to http://localhost/your_project_folder.
Conclusion
You’ve successfully built a simple PHP website! This example covers the basics of creating a dynamic web page using PHP for server-side scripting. From here, you can expand your knowledge by exploring database integration (MySQL with PHP), form handling, session management, and more advanced PHP features. Happy coding!
Please note that, you can always use Laravel framework to create a site.
Tagged With tiei7w