All right there, my friends! So, you’ve decided to dive into the world of PHP development. The first step? Setting up your environment so you can start tinkering with PHP locally. Let’s get started!
Installing PHP and MySQL
Before we jump into coding, we need to install PHP and a MySQL database. Why MySQL? Because later in the course, we’ll be storing data in this database, whether it’s user data, sports scores, or product reviews. So, it’s a crucial component.
Now, instead of installing each of these components separately, we’re going to use a handy tool called XAMPP (or you can pronounce it as “xampp”). This tool takes care of installing PHP, MySQL, and a local development server for us. Here’s what XAMPP stands for:
- X – Cross-platform (works on Windows, Linux, or Mac)
- A – Apache (the server we’ll use)
- M – MariaDB (similar to MySQL)
- P – PHP
- P – Perl (an added extra)
Simply download XAMPP from the link provided below, run the installer, and follow the steps. Easy, right?
Starting Up the Development Server
Once XAMPP is installed, you’ll see a control panel. This is where we’ll start the services we need.
- First, let’s start Apache, our local development server.
- We’ll also start MySQL, our database server, but we can do that later when we need it.
Now, open your web browser and go to localhost/dashboard
. This page is being served up by our local development server. How cool is that?
Configuring Apache
If you encounter any port errors, you might need to change the port number that Apache listens to. You can do this by editing the Apache config file. Just locate the Listen
directive and change the port number.
Where Are Your Files?
All your PHP files will be served from a folder called htdocs
in the XAMPP directory. So, if you navigate to C:xampphtdocs
, you’ll find this folder. Any PHP or HTML files you place here can be accessed through your browser using localhost
.
Creating Your First PHP File
Now that everything’s set up, it’s time for the exciting part: creating your first PHP file! Open up your favorite text editor (mine’s Sublime Text, but you can use whatever you like) and start coding.
Save your file in the htdocs
folder with a .php
extension. For example, you could create a file called index.php
.
Ready, Set, Code!
Now that you’ve got everything set up, you’re ready to start coding PHP! In the next video, we’ll create our very first PHP file and run it on our computer. Get excited, my friends—this is where the magic begins