In order to build a working website on your computer that is powered by PHP, you’ll need to first have PHP installed and know some basic HTML. In this tutorial we will make a website that displays variables written in PHP code to users in an HTML document. Let’s get started!
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My PHP Website</title>
</head>
<body>
<h1>My PHP Website</h1>
<p>Here is some static content.</p>
</body>
</html>
This is HTML code, which can be seen in a web browser. You can open this file in Google Chrome or Firefox and you should see a website like this:
It’s not very pretty, but it’s a simple website!
Right now this website is static, meaning that there’s not a server or any PHP code powering it. Next, we’ll convert this simple static web page into a dynamic one with PHP:
index.html
file to index.php
index.php
file.php -S localhost:8000
http://localhost:8000
in your web browser. You should see the same
thing we saw before with the static HTML page.Open the index.php
file in a text editor. Below the first <p>
tags, create a
new set of <p>
tags and add the following PHP code:
Now when you refresh http://localhost:8000
you will see a new line. This line
was generated in PHP, and now our site is truly dynamic!
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My PHP Website</title>
</head>
<body>
<h1>My PHP Website</h1>
<p>Here is some static content.</p>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My PHP Website</title>
</head>
<body>
<h1>My PHP Website</h1>
<p>Here is some static content.</p>
<p><?php echo "Here is some dynamic content"; ?></p>
</body>
</html>
In this book, PHP developers will learn everything they need to know to start building their applications on Docker, including:
You can buy this book on Leanpub today.