This is the first part of a series of tutorials on building a dynamic site using PHP and MySQL. If anything is unclear at any point in this series, please mention so in the comments and I will try to address it ASAP
1) Setting up and testing MAMP (or WAMP etc.)
Question: Why Do I Need MAMP?
Answer: Unlike HTML (Hypertext Markup Language), which is a markup language, PHP is what is called a server-side scripting language. This means that it talks to the server where your site is hosted and renders before your code / markup ever makes it to your web browser (client). With HTML, you could just open your file straight into a web browser and it would render your HTML correctly, but PHP most be run from a server (with PHP installed) which “hosts” the web page. MAMP makes such a server locally on your computer.
- First thing we gotta do to get started with PHP is to download MAMP. Here is a link to the download page (download the free version).
- After you have MAMP downloaded – open the MAMP application and turn on the server (it’s the button that says “start servers”).
- In your file browser or command line navigate to the MAMP folder (by default in your C Drive).
- Go to the folder called
- Create a directory (folder) inside htdocs called
- Make a file within
MC_DewDropzand name it
index.phpin the text editor of your choosing and write:
<h1>I'm writing PHP!</h1>
- Open up your web browser and put in the url
- If you get this:
I’m writing PHP!
your local server is running and we’re ready to move on!
2) Make and “include” a header page
On M.C. DewDropz site, all the pages will have a similar header (a logo and a navbar). Of course, we could copy and paste the markup for the header on each page, but that would be a waste of time, so let’s make a header a page that we will include on every page.
- In your
MC_DewDropzdirectory make a file and name it
- In the file
<p>This is a header</p>.
- Go to
index.phpand on the first line write (or copy and paste if that’s your thing):
<?php include 'header.php'; ?>
When you refresh
localhost/MC_DewDropz in your browser – it should look something like this:
This is a header
I’m writing PHP!
Yay! You have included your header!
Starting tomorrow all the code and image files we use / write will be available in a Github Repository
Here’s a basic game plan as to what our next steps are
Setting Up Bootstrap & Connecting to MySQL
For the sake of saving time on the initial setup we will be using Twitter Bootstrap for some of the styling and behavior of our site. Tomorrow I will be going through setting up Bootstrap and making the header. Then I will be covering how to make, manage and connect to a MySQL database.
PHP Basics: Data Types, Variables, Conditional Statements, Loops and Functions
We’ll learn how to use all of these things to template our site to automatically generate from our MySQL database.
Logins and Web Forms
We’ll make an admin section where M.C. DewDropz can easily update the content his site by filling out forms that make changes to the MySQL database.