Overview
Setting up a development environment for PHP programming is easy. Download the code editor you prefer, I personally lượt thích atom.io text editor.
Bạn đang xem: How to run a php file in xampp
Next is to install XAMPP, the most popular PHP development environment. This package contains Apache, PHP & MariaDB or MySQL database applications.
Many people emailed me with a main question: Mike, how khổng lồ run a PHP script? This post is my answer to you guys and to those people who will need this in the future.
In the following tutorial, we will learn how to lớn install XAMPP, how to run a PHP script, manage database with PhpMyAdmin & run a sample PHP script that fetches a record from the database.
Install XAMPP
Go to lớn this links and download XAMPP for your operating system. XAMPP is available for Windows, Linux or Mac.
Here’s a video clip about how you can install và use XAMPP.
Run Your First PHP Script
The following is an example about how to lớn run a PHP script. What this program does is show a “Hello World!” text on the screen or webpage.
Go to lớn XAMPP server directory
I’m using Windows, so my root vps directory is “C:xampphtdocs”.
Create hello.php
Create a file & name it “hello.php“
Code Inside hello.php
Open hello.php and put the following code.
Open New Tab
Run it by opening a new tab in your browserLoad hello.php
On you browser window, type http://localhost/hello.php
Output
You should see the following output.

Create a Table
Click “my_first_database” on the left side of the screenOn the “Create Table” section, fill out the Name with “products” and Number of Columns with “6“Click “Go” button
Insert Data
Click the “products” table.

Click the “Insert” tab.
Xem thêm: What We Do - Day Trading: Your Dollars At Risk

Fill out the form, mimic the data on the following image. Click the “Go” button.

Great job! We now have a database, a table inside the database & a record inside the table.

Useful Videos
1. Create a database & import MySQL file.
2. Create a database và create table.
Run PHP Script with Database
In the following steps, we will run a PHP script that fetches one record from the MySQL database.
Go to lớn XAMPP server directory
Go to lớn your “C:xampphtdocs” directory
Create read_one.php
Create a file and name it “read_one.php“
Code Inside read_one.php
The numbers 1-8 in the following code are called “code comments”. It explains each part of our simple code below. Open read_one.php & put the following code.
prepare( $query ); // 4. Sample product ID$product_id=1; // 5. This is the first question mark in the query$stmt->bindParam(1, $product_id); // 6. Execute our query$stmt->execute(); // 7. Store retrieved row to lớn the "row" variable$row = $stmt->fetch(PDO::FETCH_ASSOC); // 8. Show data to lớn userecho "
Name: " . $row["name"> . "
";echo "
Description: " . $row["description"> . "
";echo "
Price: $" . $row["price"> . "
";?>
Open Your Browser
Run it by opening you your browserLoad read_one.php
On you browser window, type http://localhost/read_one.php
Output
You should see the following output.

Online Resources
Here in darkedeneurope.com, we want to simplify learning for you lớn actually build something. But it is also important for you lớn read và study more. The following are my suggestions where lớn learn more.
You can always go back khổng lồ the menu above while you go along our series of web programming tutorials.
What’s Next?
Learn our JavaScript tutorial for beginners.
Related Tutorials
We listed all our high chất lượng full-stack website development tutorials here: Click here.
Some Notes
Found An Issue?
If you found a problem with this code, please send us an email. Before you send an email, please read our our code of conduct. Our team"s thư điện tử address is
Please be descriptive about your issue. Please provide the error messages, screenshots (or screen recording) and your chạy thử URL. Thanks!
Subscribe lớn darkedeneurope.com
Receive valuable web development tutorials khổng lồ your email. Subscribe now for FREE!