SITERAW

Introduction to PHP

So, you've made up your mind? You're diving into PHP? Well then — welcome aboard! :)

Let me introduce myself right away: I'll be your guide throughout this course. I'll walk you through the world of PHP in this first section, and I'll do my best to keep everything as clear as possible. Stick with me, and I promise PHP won't hold any secrets from you for long...

What makes the Web so successful today is how simple and accessible it is. The average internet user doesn't need to know "how it all works behind the scenes." And honestly, good for them.

But you? You're an aspiring webmaster. And that means you do need to understand the basics of how a website functions.

What is a server? A client? How do you make a site dynamic? What do PHP and MySQL even mean?

This first chapter is here to answer all of that — and more. It's here to show you that yes, you can learn to build dynamic websites. And trust me, by the end, every reader will feel reassured knowing they're starting out on the same level.

What is PHP?

Do you know what a website is? No, I don't think you're clueless, don't worry — but I did promise to start from scratch, so I've got to follow through on that ^^

A website? You're looking at one right now — mine, for instance. To visit a website, you type in its address, something like: https://www.siteraw.com. When you do that, your browser (maybe Brave or Edge) takes you there and displays the page.

And you can do a lot on a website: learn (like you're doing now), play games, chat, share, look up info, and so on...

Static vs. Dynamic Sites

There are basically two kinds of websites: static sites and dynamic sites.

  • Static sites: These are built only with HTML and CSS. They work just fine, but the content doesn't update on its own — you have to manually go into the code and change things if you want to add something new. That's not super convenient when you need to update your site multiple times a day! Static sites are great for simple "showcase" pages, like a company profile, but not much beyond that. And honestly, they're becoming pretty rare nowadays. The moment you add something interactive — like a contact form — it's no longer static. It becomes a dynamic site.
  • Dynamic sites: These are more complex. In addition to HTML and CSS, they use other languages — like PHP, Ruby, or ASP.NET Core — and often rely on databases like MySQL. What makes them "dynamic" is that their content can update on its own, without the webmaster doing anything! Most websites you visit today — including the legendary SiteRaw — are dynamic. The only real requirement to start learning how to build these is to already know how to make static sites with HTML and CSS (and don't worry — you can catch up with my HTML & CSS course if needed!).

The goal of this course is to teach you how to build dynamic websites all by yourself, step by step.

These sites offer way more exciting features than static ones. Here's just a taste of what you'll be able to create:

  • A member area: Let visitors register and access exclusive sections of your site.
  • A forum: Very common nowadays — a discussion space for people to ask questions, help each other out, or just hang out.
  • A visitor counter: Track how many people visited your site today — or even how many are browsing it right now!
  • News updates: Automate the posting of news articles, and let visitors write or comment on them.
  • A newsletter: Email all your members with updates to keep them coming back for more.
  • A chatroom: Talk with other users in real-time! You could even add a role system (regular members, moderators, admins, etc.).

Of course, these are just examples. You can go way beyond that — everything depends on your imagination and needs. Nearly all online games, for example, are built as dynamic websites. From virtual pet games, to amusement park simulators to space conquest warfare — there is some for everyone.

You could even build your own social network if you felt like it. Yes, even X (formerly Twitter) and TikTok are dynamic websites that use the same kinds of tools I'll be teaching you in this tutorial.

So, what's the big takeaway here? PHP lets you build dynamic web pages — pages that can update and evolve on their own, without you lifting a finger. That means you could be chilling on a beach in Miami, and your website will keep running, updating, and doing its thing!

Another bonus: with PHP, you're stepping into the world of the Lazy Webmaster (capital L, capital W). Once your site is up and running, it takes care of itself. It updates, transforms, evolves — without you having to touch a thing. :D

But hey... let's not get ahead of ourselves. Before we reach that point, you've got a bit of reading to do, and a lot of new things to learn!

So let's start with the very basics: do you know what really happens when you open a web page?

How Does a Website Work?

When you want to visit a website, you type its address into your web browser — whether it's Edge, Safari, Brave, or another one. But have you ever stopped to wonder how that web page actually makes its way to your screen?

First things first: the internet is a giant network made up of computers. These computers fall into two main categories:

  • Clients: These are the computers of internet users — like yours. So your computer is what we call a client. Each client is a visitor to a website.
  • Servers: These are powerful computers that store websites and send them out to users — that is, to clients. Most people have never actually seen a server in real life. But without them, the internet simply wouldn't work.

Most of the time, a server doesn't even have a screen. It's just sitting there, running on its own, quietly doing its job 24/7. A real workhorse.

To sum up: your computer is the client, and the machine hosting the website is the server. But how do these two talk to each other?

That's where the difference between a static and a dynamic website really starts to matter. Let's take a closer look.

The Case of a Static Site

When a site is static, the process is super simple. It works in two steps:

  • The client asks the server for a web page.
  • The server responds by sending the requested page.

The exchange looks something like this:

  • "Hello, I'm the client. I'd like to see this web page, please."
  • "Here you go — here's the page you asked for."

And... that's it. Nothing fancy.

With a static site, the server simply stores ready-made web pages and hands them out as-is to whoever asks.

The Case of a Dynamic Site

Now, with a dynamic site, there's an extra step involved: the page gets generated on the fly.

Here's how it works:

  • The client asks the server for a web page.
  • The server builds the page specifically for that client.
  • The server sends back the freshly generated page.

The magic of dynamic sites lies in that moment of generation. Each time someone visits a page, the server creates a custom version — just for them. That's what makes dynamic websites feel so alive: the content can change from one second to the next, depending on who's looking.

That's how some websites can show your username on every page, for instance. Since the server is building the page every time it's requested, it can personalize it for each visitor — based on their preferences, settings, or login.

Let's take SiteRaw as an example. If your username is "Matt" and mine is "Admin", and we both request the homepage, we'll each get a slightly different version. Yours might say: "Hello Matt, welcome to SiteRaw." While mine might say: "Hello Admin (oh great and magnanimous ruler), welcome to SiteRaw." or something like that.

The Languages of the Web

When building a website, you don't just use one language — you end up working with several. As a webmaster, it's absolutely essential to know them.

There are some programs out there, called WYSIWYG editors (What You See Is What You Get), that help beginners create static websites without touching any code. But if we want to build a dynamic website like we do here, we're going to have to get our hands dirty.

For a static website: HTML and CSS

Many different languages have been invented for making websites. But two of them form the rock-solid foundation every webmaster should know:

  • HTML: This is the core language of the web. HTML is fairly easy to learn and works through a system of tags. Here's a quick example of HTML code: <p>Hello, I'm a <em>paragraph</em> of text!</p>
  • CSS: This one's all about style. While HTML handles your content and its structure, CSS takes care of the design — things like layout, colors, and fonts. Here's a sample CSS snippet: p { color: red; }

These two languages are the backbone of every website. When a server sends a webpage to your browser, what it's actually sending is HTML and CSS code.

The issue is, if you only know HTML and CSS, you're limited to making static sites... and we want to go dynamic! That's going to require a couple more tools alongside HTML and CSS.

So here's the first question: do you know HTML and CSS?

If the answer is yes, great! You're all set to move forward — we'll definitely be using them. If not, don't worry. These languages aren't too tough. In fact, they're very beginner-friendly. You can learn them by reading my HTML and CSS course. Most people can pick them up in just a few short weeks — or even faster if you've got some free time. :)

For a dynamic website: add PHP and MySQL

No matter what kind of site you're making, HTML and CSS are a must. But for anything dynamic, they're just not enough. You'll need a couple more languages.

And that's exactly what this tutorial is all about: learning to use PHP and MySQL to build a dynamic website.

  • PHP: This is a language that only servers understand, and it's what makes your site dynamic. It's PHP that "generates" your pages in real-time, like we saw in the diagram earlier. It'll be the first new language we learn here. It can work on its own, but it becomes even more powerful when paired with a tool like MySQL. Here's a PHP example: <?php echo "You are visitor number " . $n_visitors; ?>
  • MySQL: Technically not a programming language, but rather a DBMS (Data Base Management System). In simple terms, it stores your data in an organized way so you can easily retrieve it later. Thanks to MySQL, you'll be able to save things like member info, forum messages, and more. The language used to interact with it is called SQL. Here's an example SQL query: SELECT id, author, message, msgdate FROM chatroom ORDER BY msgdate DESC LIMIT 0, 10

Both PHP and MySQL are open-source software. That means they're free, and anyone can contribute to improving them. It also means they're not going to disappear overnight, which is super important when you're investing time in learning. And did I mention they're free? You won't need to spend a single cent to build your site! :D

PHP can work by itself and is enough to create a dynamic site. But once you team it up with a DBMS like MySQL, that's when the magic really starts to happen. For now though, let's keep things simple — forget MySQL for a bit and focus on PHP. That's exactly what we'll be doing in the first two parts of this course. We'll dive into databases and MySQL in Part 3. :)

PHP Generates HTML

Web browsers (or "clients") don't understand PHP. They only speak HTML and CSS. Only the server can read and run PHP.

PHP's job is to generate HTML (and sometimes CSS) on the fly, which it then sends to the client — just like in a static site.

PHP is a programming language used on many servers to make decisions. It decides what HTML to generate and send based on the user, time, or any number of conditions. The client has no idea if the HTML it's receiving was handcrafted or dynamically built by PHP behind the scenes.

Let's break it down with an example. In PHP, you can write something like: "if the visitor is a registered member named Kevin, show 'Welcome Kevin' on the page. If they're not a member, just show 'Welcome' and invite them to sign up."

That's a super basic example of a dynamic site. Based on whether or not the user is logged in, they'll see different content — and possibly even have access to different sections of the site.

What Are the Alternatives?

HTML and CSS have no real competition — they're web standards. Everyone uses them, everywhere.

But when it comes to dynamic websites, PHP and MySQL aren't the only players in town. I won't list every single competitor (we'd be here forever and you'd be bored out of your mind), but let's go over a few major ones you should know.

First of all, keep in mind that PHP (a programming language) and MySQL (a database system) are two very different things, so they have different sets of competitors.

PHP Alternatives

Some popular alternatives to PHP include:

  • ASP.NET Core: Developed by Microsoft, this framework runs on .NET and is a natural fit for C# developers. It's powerful and feature-rich, though it's not open source and hosting tends to cost a bit more.
  • Ruby on Rails: A dynamic framework that uses the Ruby language. It's popular for building sites quickly by following specific conventions.
  • Python: With frameworks like Django and Flask, Python is a great option. It's known for its clean syntax and massive library support.
  • JavaScript (Node.js): Thanks to Node.js, JavaScript can now be used on both the client and server side. It's fast, efficient, and boasts a huge ecosystem.
  • Rust: A newer language, Rust focuses on safety and performance, and it's slowly making its way into web dev.
  • Perl: Once a major player, Perl has lost some steam but is still used in certain corners of the web.

I'm not going to go into every alternative out there, but this gives you a solid idea of what's available. And yes — you technically can build web apps with C or C++, though I really wouldn't recommend it. :p

So, which one's the best?

You're probably expecting me to shout "PHP!" since this is a PHP course. But actually, the answer depends on your background. If you already know Perl or Python, you might want to stick with what you know. If you're used to working with C# or other .NET languages, ASP.NET Core might feel more comfortable.

That said, PHP shines in one very important area: its community. If you run into a problem, odds are someone online has already solved it. Plus, PHP is easy to get into, yet powerful enough for big-name websites like Wikipedia, WordPress, and even parts of Facebook.

So there's no one-size-fits-all answer. I recommend using the language that gives you the most support. And in that regard, PHP is often an excellent choice.

Bonus point for PHP: it was made specifically for web development. It's not just a general-purpose language that was adapted for the web — it was designed from the ground up for it, by and for web devs.

MySQL Alternatives

When it comes to databases, you've got lots of choices too. But unlike programming languages, not all database systems are free.

Here are some big names you should know:

  • Oracle: The most well-known and powerful DBMS out there. It's mainly used by large companies, and it's not cheap. That said, they do offer free versions for learning purposes.
  • Microsoft SQL Server: Built by Microsoft and often paired with ASP.NET Core, though it works with any language. Like Oracle, it's powerful but typically used in professional settings. Limited free versions exist.
  • PostgreSQL: Open-source and free, like MySQL, but with more advanced features. Some call it the open-source answer to Oracle. It's better suited for large-scale sites, though its community isn't quite as big as MySQL's.
  • SQLite: The simplest and lightest DBMS. It's also free and open-source, but it's very limited in features. Still, that can be a plus when you need something lightweight.

Again, this list isn't exhaustive, but it'll get you started.

For reference, MySQL is by far the most widely used free and open-source DBMS. Among the paid options, Oracle and Microsoft SQL Server are the top dogs — mainly in enterprise environments.

So, if you're on a budget, MySQL is hands down the best choice. It's fast, reliable, well-documented, and used by tons of people who can help you out when needed.

You Can Mix and Match

As you've seen, there's no shortage of tools for building dynamic websites — and most of them are free.

And yes, you can mix and match them however you like. You could use PHP with Oracle or PostgreSQL instead of MySQL. Or you could pair MySQL with Python, Java, Ruby, Perl, or even ASP.NET Core.

Still, the "PHP + MySQL" combo is by far the most common. And not without reason — they've proven themselves time and again.

Installing PHP on your Computer

There is one last thing I need to mention before concluding this introductory chapter to the world of PHP and dynamic web development...

What programs do we need? I want to start coding in PHP right now!

Depending on whether you're building a static or dynamic website, the software you'll need will vary. And yes — bad news for us dynamic site creators — it does mean a few extra tools! 😅

For a static site

Webmasters who stick to static websites built with XHTML and CSS have it easy. Chances are, they already have everything they need:

  • A text editor: Technically, even something as bare-bones as Notepad (which comes with Windows) can do the trick. But ideally, you'd want something a bit more robust — like Visual Studio Code. We'll chat more about editors at the end of this chapter.
  • A web browser: You'll need one to test your pages. Whether you're using Brave, Edge, Safari, or any other browser you normally use to surf the web, it's totally fine. It's even a good idea to check how your site looks on different browsers from time to time — just to be safe.

But if, like us, you're working on a dynamic site, well... you're going to need a bit more than that.

For a dynamic site

To get your computer to understand PHP, it needs to act like a server. Don't worry — you don't need to buy some fancy new machine. All you need to do is install the same programs that real servers use to serve up websites.

So what are these magical programs?

  • Apache: This is what's called a web server. It's arguably the most important piece of the puzzle, because it's the one responsible for delivering your web pages to visitors. But — and here's the catch — Apache only knows how to handle static websites (in other words, good old HTML). If we want it to process dynamic pages, we'll need to pair it with a few other tools.
  • PHP: This is a plugin for Apache that teaches it how to understand and process PHP pages. In plain English, when you combine Apache and PHP, your computer can now read and run PHP web pages. Boom!
  • MySQL: This is the database management system I mentioned earlier in the intro. It lets you store data in an organized way (think: user accounts, member lists, etc.). We won't need it just yet, but might as well install it now and save ourselves a step later.
  • phpMyAdmin: This handy tool makes it way easier to manage your databases. And if the phrase "database management" already has you breaking into a cold sweat — don't panic! We'll only tackle that beast further down the road.

Now, Apache isn't the only web server out there. There's also Microsoft IIS (Internet Information Services), nginx, Node.js, Cloudflare Server, Tomcat, Cowboy... yep, sounds like we're heading into the Wild West 🤠

The good news? All the tools we just mentioned are open-source and free. Sure, there are alternatives out there — some even with a price tag — but the Apache + PHP + MySQL combo is the gold standard. It's used so widely that people have even bundled them into ready-made "packs" you can install in one go. You could install everything piece by piece, but it's more work and doesn't really gain you much (unless you're moonlighting as a server administrator).

These all-in-one packages are called:

  • WAMP (Windows + Apache + MySQL + PHP) for Windows
  • LAMP (same logic) for Linux
  • MAMP (you get the idea) for Mac
  • and even XAMP ("X" for cross) for cross-platform integration

...and there are plenty of other variations floating around online. You can try out Uniform Server or AMPPS if you want a lightweight version of these tools - and I usually recommend beginners and advanced users alike pick the lighter, bloat-free versions of software when possible... it avoids clutter.

That wraps up this first chapter nicely. :) You should now have a clear idea of what PHP and MySQL can do. If you remember just one thing, let it be this: PHP generates personalized HTML for each visitor, and MySQL stores the data behind the scenes. That's the heart of it.

In the next two parts of this course, we'll dive into PHP — starting with the basics, then moving to more intermediate concepts. We'll hold off on databases and MySQL for now. Once you've got a solid grasp on PHP, we'll bring MySQL into the mix and start building some really cool features for your future website. :)

How to Build a Website in HTML and CSS

Enjoyed this PHP & MySQL course?

If you liked this lesson, you can find the book "How to Build a Website in HTML and CSS" from the same authors, available on SiteRaw, in bookstores and in online libraries in either digital or paperback format. You will find a complete PHP & MySQL workshop with many exclusive bonus chapters.

More information