Learning Objectives
By the end of this tutorial, you will be able to:
• Understand the course structure and learning outcomes.
• Install a PHP development environment.
• Configure Visual Studio Code for PHP development.
• Create and run your first PHP program.
• Understand the basic syntax of PHP 8.x.
• Use Git and GitHub to manage your code.
• Use AI tools effectively to support learning.
Why Learn PHP?
PHP is one of the most popular server-side programming languages for developing dynamic websites and web applications. It powers millions of websites, including content management systems, e-commerce platforms, and custom web applications.
Modern PHP (version 8.x) is faster, more secure, and offers many powerful language features such as typed properties, attributes, match expressions, constructor property promotion, union types, and improved error handling.
Whether you want to become a web developer, freelancer, or backend engineer, PHP remains a valuable programming language.
Software Required
Install the following software before beginning the course.
Choose one of the following:
Option 1: XAMPP
Includes:
• Apache Web Server
• PHP
• MySQL (MariaDB)
• phpMyAdmin
Suitable for beginners.
Option 2: Laragon
Includes:
• Apache or Nginx
• PHP
• MySQL
• Composer
• Easy project management
Recommended for modern PHP development.
Installing XAMPP
Step 1: Download XAMPP for your operating system.
Step 2: Run the installer.
Step 3: Select the default components.
Step 4: Finish installation.
Step 5: Open the XAMPP Control Panel.
The following window will appear after installing the XAMPP server successfully. You have to start the Apache for the web server and MySQL for the database server.
After starting Apache and MySQL server open your browser and visit the following URL.
You will see the XAMPP welcome page.
Installing Laragon
Step 1: Download Laragon.
Step 2: Install using the default settings.
Step 3: Launch Laragon.
The following window will appear after install Laragon successfully.
Step 4: Click Start All or start particular application.
According to the following image, Apache and MySQL have been started. When you will start these applications for the first time then it will ask for the permission. You have to press the allow button to start the server.
Step 5: Open the localhost
If you get the following page then your development server is running.
Installing Visual Studio Code
Visual Studio Code is a lightweight and powerful code editor. Install VS Code and then install these extensions.
PHP Intelephense: Provides intelligent code completion.
PHP Debug: Useful for debugging applications.
GitLens: Improves Git integration.
Prettier: Formats code automatically.
Error Lens: Highlights coding errors directly in the editor.
Creating Your First PHP Project
Locate the web server directory and do the following tasks.
- For XAMPP: htdocs
- For Laragon: www
- Create a folder named php_lab
- Inside that folder create a file named index.php
Writing Your First PHP Program
Type the following code.
<?php echo "PHP Programming"; ?>
Save the file with the name first.php.
Open your browser and visit the following URL.
http://localhost/php_lab/first.php
The browser will display the following output.
Congratulations.
You have created your first PHP application.
Understanding PHP Tags
Every PHP program begins with
<?php and ends with ?>
Example
<?php echo “PHP is fun.”; ?>
The opening tag tells the server that PHP code starts here.
Comments
Comments help explain code.
Single-line comment
// This is a comment
Another single-line comment
This is also a comment
Multi-line comment
/*
This is
a multi-line
comment.
*/
Comments are ignored during execution.
PHP Variables
Variables store information.
- PHP variable names begin with $
- Cannot begin with a number
- Case-sensitive
- Meaningful names are better to use
Good examples:
$studentName
$totalMarks
Poor examples:
$a
$x1
$temp123
Basic Data Types
PHP supports several data types.
Integer: $age = 21;
Float: $cgpa = 3.85;
String: $name = “Rahim”;
Boolean: $isPassed = true;
Array: $marks = [80, 85, 90];
Checking the PHP Version
Create a new file inside php_lab folder with the name version.php.
Write the following code in the file.
<?php phpinfo(); ?>
Save the file and open the following URL.
http://localhost/php_lab/version.php
A detailed information page will appear.
Lab Exercise:
Task 1: Install XAMPP or Laragon.
Task 2: Install Visual Studio Code.
Task 3: Create a folder named php_lab.
Task 4: Write a PHP program that displays your ID, name, department and batch.
Task 5: Create a PHP program that display your CGPA.
Task 6: Check your installed PHP version.
Try yourself:
Create a PHP page that prints:
- Your favorite programming language
- Your career goal
- Three reasons why you want to learn PHP
- Modify the page to display today’s date using PHP.
***Search the PHP documentation to learn how the date() function works.
