PHP Introduction

Beginner
6 min read
Updated: Oct 2026
Server-side language

What Is PHP?

PHP (Hypertext Preprocessor) is a server-side scripting language for dynamic websites and web apps. The server runs PHP and sends the finished HTML to the browser—visitors never see your source.

Remember
Pipeline:
  browser request → web server → PHP engine → HTML response

Tags:     <?php ... ?>
Output:   echo "Hello";
Files:    .php (often mixed with HTML)

PHP handles forms, logins, databases, sessions, and APIs. It powers WordPress, Laravel, Symfony, and millions of custom sites. This page is the gateway to the PHP tutorials on CodeToFun.

Why Use PHP?

Rasmus Lerdorf created PHP in 1994 as tools for his personal home page. It grew into a full language maintained by The PHP Group and a large open-source community.

NeedHow PHP helps
Dynamic pagesGenerate HTML from logic, forms, and databases
Easy hostingMost shared hosts ship PHP ready to use
CMS & frameworksWordPress, Laravel, Symfony, and a huge package ecosystem
Fast to startEmbed PHP in HTML and print with echo

Key milestones

MilestoneYearNotes
PHP created1994Rasmus Lerdorf personal tools
PHP 31998Name: Hypertext Preprocessor
PHP 72015Major speed improvements
PHP 8+2020+JIT, attributes, named arguments

How a PHP Page Runs

PHP executes on the server before the browser gets a response. Keep this flow in mind.

StepWhat happensWho does it
RequestBrowser asks for a .php pageUser / browser
Hand offServer passes the file to the PHP engineApache / Nginx
ExecutePHP runs your code and builds outputPHP runtime
RespondHTML/CSS/JS is sent to the browserWeb server

Cheat sheet — building blocks

ConceptRole
Variables$name, strings, numbers, arrays
Outputecho / print
Control flowif, loops, switch
FunctionsReusable logic
Forms & input$_GET, $_POST
SessionsRemember users across pages

What Does a PHP Program Look Like?

Save this as hello.php. PHP tags wrap the code the server should run:

PHP
<?php
echo "Hello, World!";
?>
PartMeaning
<?php … ?>PHP code block processed on the server
echoSends text (often HTML) to the response
SemicolonsEnd most statements
HTML outside tagsSent to the browser unchanged

You can mix HTML and PHP in one file:

PHP
<!DOCTYPE html>
<html lang="en">
<body>
  <h1>Today is <?php echo date('Y-m-d'); ?></h1>
</body>
</html>

PHP vs JavaScript

Both are popular for the web, but they usually run in different places:

JavaScript (typical)PHP
Runs in the browser (or Node.js)Runs on the web server
Updates the page without a full reloadBuilds HTML before the response is sent
console.log("Hi")echo "Hi";
Client-side interactivityForms, databases, sessions, CMS
Source often visible in DevToolsSource stays on the server

Same idea, two styles

Print a greeting:

JavaScript
console.log("Hello, World!");
PHP
<?php
echo "Hello, World!";
?>

When to choose which

Prefer PHP when…Prefer JavaScript when…
You need server logic, WordPress, or classic web hostingYou need rich UI behavior in the browser
Your stack is Laravel / Symfony / PHP CMSYour stack is Node.js or a JS frontend framework
Secrets and DB access must stay on the serverYou already ship most logic as client JS + APIs

Many sites use both: PHP (or another backend) for the server, JavaScript for the interface.

Run PHP Locally

Install PHP (or a stack like XAMPP / Laragon), save hello.php, then start a quick built-in server in that folder.

terminal
php -v
cd my-project
php -S localhost:8000

How It Works

1. Check install. php -v confirms the PHP CLI is available.

2. Start a server. php -S localhost:8000 serves files from the current folder.

3. Open the page. Visit http://localhost:8000/hello.php. PHP runs echo and the browser shows the text.

Next, learn the most common output statement in PHP echo.

Where Is PHP Used?

Common workloads where server-side PHP fits well:

Use caseWhy PHP fits
Content sites & blogsWordPress and other CMS platforms
E-commerceCarts, checkout, and catalogs with server logic
Business web appsForms, auth, CRUD dashboards
APIs & backendsReturn JSON from Laravel / Symfony apps
Shared hosting projectsCheap, widely available PHP hosting
Legacy modernizationHuge existing PHP codebase worldwide

Key Takeaways

  • PHP is a server-side language that builds HTML before the browser sees it.
  • Pipeline: request → PHP engine → HTML response.
  • Start with: <?php tags and echo.
  • Local test: php -S localhost:8000 or XAMPP / Laragon.

One line: PHP runs on the server and outputs HTML—next, master echo.

Frequently Asked Questions

Dynamic websites, CMS platforms like WordPress, e-commerce, form handling, APIs, and backends with frameworks such as Laravel and Symfony.
Yes. PHP powers WordPress and millions of sites. It remains one of the most deployed server languages for content sites and web apps.
It helps. PHP is often mixed with HTML. Learn basic tags and forms first, then use PHP to generate dynamic content and handle input.
Install XAMPP, WAMP, or Laragon, or install PHP and run php -S localhost:8000 in your project folder. Open the URL in a browser to view .php pages.
Yes. PHP is open source under the PHP License. You can use it freely in personal and commercial projects.
Practice echo, variables, strings, if-else, loops, and forms. Then explore MySQL, sessions, and a framework like Laravel when you build larger apps.

Did you know?

PHP runs on the server before HTML reaches the browser. Wrap code in <?php ... ?>, output with echo, and test locally with XAMPP or php -S localhost:8000.

Next: PHP echo

Learn the main way to send output from PHP to the browser.

PHP echo →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful