Install, Syntax & Comments
Install XAMPP (Windows/Mac/Linux) or use Homebrew: brew install php. Start Apache and MySQL from the XAMPP control panel.
Install PHP — local setup
Install XAMPP (Windows/Mac/Linux) or use Homebrew: brew install php. Start Apache and MySQL from the XAMPP control panel.
Save files in htdocs (e.g. htdocs/knowvora/index.php) and visit http://localhost/knowvora/index.php.
Real-life example: Installing PHP is like setting up a workshop. XAMPP gives you the tools (PHP, Apache, MySQL) on one workbench.
- Check version: php -v in terminal
- Built-in server: php -S localhost:8000
- Use VS Code with PHP Intelephense extension
<?php
// Save as index.php and open via localhost
phpinfo(); // Shows PHP version and modules — remove in production!
?>PHP Syntax
PHP scripts start with <?php and end with ?>. Statements end with a semicolon (;). PHP is not case-sensitive for keywords but is case-sensitive for variables.
Real-life example: Semicolons are like periods at the end of sentences. Without them, PHP gets confused about where one instruction ends.
<?php
// PHP block must start with <?php
echo "Hello, Rishtaara!"; // semicolon required
// Wrong: echo "Hi" (missing semicolon)
?>Comments
Use // for single-line comments and /* ... */ for multi-line blocks. Comments help humans; PHP ignores them.
Real-life example: Comments are pencil notes in your notebook margin — they remind you why you wrote code, but the teacher skips them.
<?php
// This line is a comment
$course = "PHP Fundamentals"; // inline comment
/*
Multi-line comment
for longer explanations
*/
echo $course;
?>