Lesson 1.2: Setting Up Your Development Environment
Your PHP Workshop
Time to build your development environment. Think of this like setting up a professional kitchen before cooking. You need the right tools, properly configured, ready to create amazing things.
Here's what we're installing:
- PHP itself (the engine)
- A code editor (your workspace)
- A local web server (to run your creations)
- Composer (PHP's package manager)
Don't worry if these terms sound foreign. By lesson's end, you'll have everything running smoothly.
Operating System Considerations
PHP runs everywhere: Windows, macOS, Linux. However, setup differs slightly. I'll cover all three operating systems. Skip to your relevant section, though reading all three helps understand PHP's flexibility.
One crucial note: PHP development happens most naturally on Unix-like systems (macOS and Linux). Windows works fine, but you'll occasionally hit quirks. If you're on Windows, consider using WSL2 (Windows Subsystem for Linux) for a smoother experience.
Installing PHP
Windows Installation
Windows doesn't include PHP by default. Let's fix that.
Option 1: XAMPP (Easiest)
- Download XAMPP - choose the latest PHP 8.x version
- Run the installer (ignore antivirus warnings - they're false positives)
- Select components: Apache, MySQL, PHP, phpMyAdmin
- Install to
C:\xampp
(avoid Program Files - spaces cause issues) - Launch XAMPP Control Panel
- Start Apache and MySQL
That's it! PHP now runs at http://localhost
.
Option 2: Native PHP (More Control)
- Visit windows.php.net
- Download the Thread Safe x64 zip
- Extract to
C:\php
- Add
C:\php
to your system PATH:
- Right-click "This PC" → Properties
- Advanced system settings → Environment Variables
- Edit Path → New →
C:\php
- Rename
php.ini-development
tophp.ini
- Open command prompt, type
php -v
See version info? Success!
macOS Installation
macOS includes PHP, but it's usually outdated. Let's install modern PHP properly.
Using Homebrew (Recommended)
# Install Homebrew if you haven't
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install PHP
brew install php
# Verify installation
php -v
Alternative: MacPorts
# Install MacPorts from macports.org
# Then run:
sudo port install php82 +apache2
# Select PHP version
sudo port select --set php php82
Linux Installation
Linux makes PHP installation trivial. Commands vary by distribution:
Ubuntu/Debian:
sudo apt update
sudo apt install php8.2 php8.2-cli php8.2-common php8.2-mysql php8.2-xml php8.2-curl php8.2-mbstring
# Verify
php -v
Fedora/CentOS/RHEL:
sudo dnf install php php-cli php-common php-mysqlnd php-xml php-curl php-mbstring
# Verify
php -v
Arch Linux:
sudo pacman -S php
# Verify
php -v
Choosing Your Code Editor
Your editor shapes your coding experience. Choose wisely.
Visual Studio Code (Recommended)
VS Code dominates PHP development for good reasons. It's free, fast, and incredibly powerful.
- Download from code.visualstudio.com
- Install these essential extensions:
- PHP Intelephense (bmewburn.vscode-intelephense-client)
- PHP Debug (xdebug.php-debug)
- PHP DocBlocker (neilbrayfield.php-docblocker)
- DotENV (mikestead.dotenv)
Configure PHP executable path:
- Open Settings (Ctrl/Cmd + ,)
- Search "PHP executable"
- Set path:
- Windows:
C:\xampp\php\php.exe
orC:\php\php.exe
- macOS/Linux:
/usr/local/bin/php
or result ofwhich php
PHPStorm (Professional Choice)
JetBrains PHPStorm offers unmatched PHP intelligence. It's paid ($89/year) but offers a 30-day trial. Students get it free through GitHub Student Pack.
PHPStorm advantages:
- Superior code completion
- Built-in database tools
- Incredible refactoring capabilities
- Integrated debugging
- Framework-specific features
Other Options
- Sublime Text: Lightning fast, minimalist
- Vim/Neovim: For terminal enthusiasts
- Zed: High-performance editor with a focus on AI & collaboration
- NetBeans: Free IDE with good PHP support
- Notepad++: Windows-only, lightweight
Start with VS Code. You can always switch later.
Setting Up a Local Server
PHP needs a web server to shine. Let's explore options.
Built-in PHP Server (Quickest)
PHP includes a development server. Perfect for learning:
# Navigate to your project folder
cd /path/to/your/project
# Start server
php -S localhost:8000
# Visit http://localhost:8000 in your browser
Limitations: Single-threaded, development only. Never use in production!
XAMPP/WAMP/MAMP (Beginner-Friendly)
These packages bundle Apache, MySQL, and PHP:
- XAMPP: Cross-platform (Windows, macOS, Linux)
- WAMP: Windows only
- MAMP: macOS focused (Windows version exists)
Already installed XAMPP? Your documents go in:
- Windows:
C:\xampp\htdocs\
- macOS:
/Applications/XAMPP/htdocs/
- Linux:
/opt/lampp/htdocs/
Docker (Modern Approach)
Docker containerizes your environment. Steeper learning curve, but worth it:
- Install Docker Desktop
- Create
docker-compose.yml
:
version: "3.8"
services:
php:
image: php:8.2-apache
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- Run
docker-compose up
- Access at
http://localhost:8080
Laravel Valet (macOS Only)
Valet offers zero-configuration development:
brew install php
composer global require laravel/valet
valet install
cd ~/Sites
valet park
Any folder in ~/Sites
becomes http://foldername.test
automatically!
Installing Composer
Composer manages PHP dependencies. Think npm for PHP. You'll use it constantly.
Windows Installation
- Download Composer-Setup.exe
- Run installer (it finds PHP automatically)
- Open new command prompt
- Type
composer --version
macOS/Linux Installation
# Download installer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
# Verify installer (optional but recommended)
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
# Install globally
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
# Clean up
php -r "unlink('composer-setup.php');"
# Verify
composer --version
Creating Your First PHP File
Everything's installed? Let's test it!
- Create a new folder called
php-course
- Inside, create
index.php
:
<?php
phpinfo();
- Run your chosen server:
- Built-in:
php -S localhost:8000
- XAMPP: Copy to htdocs, visit
http://localhost/php-course/
- Docker: Place in mounted volume
- Open your browser to the appropriate URL
See a purple PHP information page? Congratulations! PHP works.
Understanding phpinfo()
That phpinfo()
page contains valuable information:
- PHP Version: Ensure it's 8.x
- Configuration File: Where
php.ini
lives - Loaded Extensions: Available PHP features
- Environment Variables: System settings
Bookmark this function. When debugging server issues, phpinfo()
provides crucial details.
Configuring PHP
PHP's behavior lives in php.ini
. Find yours:
- Run
php --ini
in terminal - Check
phpinfo()
output under "Loaded Configuration File"
Key settings to adjust for development:
; Display errors (NEVER in production!)
display_errors = On
error_reporting = E_ALL
; Increase memory for complex scripts
memory_limit = 256M
; Extend execution time for debugging
max_execution_time = 60
; Show startup errors
display_startup_errors = On
; Log errors for later review
log_errors = On
error_log = /path/to/error.log
Save changes, restart your web server.
File Organization
Establish good habits early. Here's a sensible structure:
php-course/
├── module-01/
│ ├── lesson-01/
│ ├── lesson-02/
│ └── project/
├── module-02/
│ ├── lesson-01/
│ └── ...
├── assets/
│ ├── css/
│ ├── js/
│ └── images/
└── README.md
Each lesson gets its own folder. Projects live separately. Assets stay organized.
Testing Your Setup
Create test.php
in your project folder:
<?php
// Variables
$name = "PHP Developer";
$version = phpversion();
// Array
$skills = ['HTML', 'CSS', 'JavaScript', 'PHP'];
// Add another skill
$skills[] = 'MySQL';
// Current date
$today = date('l, F j, Y');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Setup Test</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #f4f4f4;
}
.success {
background-color: #4CAF50;
color: white;
padding: 15px;
border-radius: 5px;
}
.info {
background-color: #2196F3;
color: white;
padding: 10px;
margin: 10px 0;
border-radius: 3px;
}
</style>
</head>
<body>
<div class="success">
<h1>✓ PHP is working!</h1>
</div>
<h2>Hello, <?php echo $name; ?>!</h2>
<div class="info">
<strong>PHP Version:</strong> <?php echo $version; ?>
</div>
<div class="info">
<strong>Today's Date:</strong> <?php echo $today; ?>
</div>
<h3>Your skillset includes:</h3>
<ul>
<?php foreach ($skills as $skill): ?>
<li><?php echo $skill; ?></li>
<?php endforeach; ?>
</ul>
<p>If you can see this page with dynamic content, your PHP environment is properly configured!</p>
</body>
</html>
Run this file through your web server. See personalized content? Perfect! Your environment works.
Troubleshooting Common Issues
"PHP is not recognized" error:
- PATH not set correctly
- Restart terminal/command prompt after PATH changes
- Use full path to PHP:
C:\php\php.exe -v
Blank white page:
- Check error logs
- Ensure
display_errors = On
in php.ini - Add
error_reporting(E_ALL);
at script start - Look for syntax errors (missing semicolons, unclosed brackets)
"Port already in use" error:
- Another service uses port 80/8000
- Change port:
php -S localhost:8080
- Stop conflicting services (Skype, IIS, other web servers)
Extension missing errors:
- Install required extensions
- Enable in php.ini (remove semicolon from
;extension=name
) - Restart web server
File not found errors:
- Check file paths (case-sensitive on Linux/macOS)
- Ensure correct document root
- Verify file permissions
Development Workflow Tips
Use Version Control: Install Git. Track changes from day one:
git init
git add .
git commit -m "Initial setup"
Browser DevTools: Learn them! F12 opens developer tools. Network tab shows requests. Console displays JavaScript errors.
Multiple Browsers: Test in Chrome, Firefox, Safari, Edge. Each renders slightly differently.
Code Formatting: Configure your editor for PSR-12 standard. Consistent code reads easier.
Backup php.ini: Before modifying configuration, copy php.ini
to php.ini.backup
.
Security Notes
Development environments prioritize convenience over security. NEVER use these settings in production:
display_errors = On
(reveals sensitive information)- Built-in PHP server (not designed for production)
- Default XAMPP passwords (change immediately if exposed to network)
phpinfo()
accessible publicly (exposes system details)
We'll cover production configuration later. For now, keep development servers local only.
Next Steps
Your environment is ready! You can:
- Write PHP code in your editor
- Run it through a web server
- See results in your browser
- Debug when things break
Take a moment to celebrate. Setting up development environments frustrates many beginners. You pushed through!
Try modifying test.php
:
- Change the name variable
- Add more skills to the array
- Display the current time, not just date
- Style it differently with CSS
Experimentation builds confidence. Break things. Fix them. That's learning!
Summary
You've accomplished a lot:
- ✅ Installed PHP 8.x
- ✅ Configured a code editor
- ✅ Set up a local web server
- ✅ Installed Composer
- ✅ Created your first PHP files
- ✅ Verified everything works
Your development environment matches what professionals use. The only difference? Experience. Let's start building that experience.
Ready to write your first real PHP script? Lesson 1.3 awaits!
Quick Reference
Start/Stop Services:
- XAMPP: Use control panel
- Built-in server:
Ctrl+C
to stop - Docker:
docker-compose down
Important Paths:
- Windows XAMPP:
C:\xampp\htdocs\
- macOS XAMPP:
/Applications/XAMPP/htdocs/
- Linux XAMPP:
/opt/lampp/htdocs/
- php.ini location: Run
php --ini
Useful Commands:
php -v
- Check PHP versionphp -m
- List installed modulesphp -S localhost:8000
- Start built-in servercomposer --version
- Check Composerphp -i
- Command line phpinfo()
VS Code Shortcuts:
Ctrl/Cmd + S
- Save fileCtrl/Cmd + P
- Quick file openCtrl/Cmd + Shift + P
- Command paletteCtrl/Cmd + /
- Toggle comment