Environment Setup
Overview
Before you can start PHP development, you need to set up a development environment. This chapter will guide you through installing PHP and the necessary tools on different operating systems.
Installation Options
Option 1: All-in-One Solutions (Recommended for Beginners)
XAMPP (Cross-Platform)
XAMPP includes Apache, MySQL, PHP, and phpMyAdmin in one package.
Windows/macOS/Linux:
- Download from https://www.apachefriends.org/
- Run the installer
- Start Apache and MySQL from the control panel
- Visit
http://localhostto test
WAMP (Windows)
Windows-specific solution with Apache, MySQL, and PHP.
Installation:
- Download from http://www.wampserver.com/
- Install and start services
- Access via system tray icon
MAMP (macOS)
Mac-specific development environment.
Installation:
- Download from https://www.mamp.info/
- Install and configure ports
- Start server from the application
Option 2: Standalone Installation
Windows
Using Chocolatey:
Manual Installation:
- Download PHP from https://windows.php.net/download/
- Extract to
C:\php - Add
C:\phpto system PATH environment variable - Copy
php.ini-developmenttophp.ini
macOS
Using Homebrew:
Using MacPorts:
Linux (Ubuntu/Debian)
Linux (CentOS/RHEL)
Verifying Installation
Check PHP Version
Expected output:
Check PHP Configuration
Test PHP in Browser
Create a file named info.php:
Place it in your web server's document root, then visit http://localhost/info.php
Essential Extensions
Core Extensions (Usually Included)
- mysqli/pdo: Database connectivity
- curl: HTTP client functionality
- json: JSON data handling
- mbstring: Multibyte string handling
- xml: XML processing
Installing Additional Extensions
Ubuntu/Debian:
Windows (Using Composer):
Development Tools
Code Editors and IDEs
Visual Studio Code (Free)
Recommended Extensions:
- PHP Intelephense
- PHP Debug
- Bracket Pair Colorizer
- GitLens
PhpStorm (Paid)
Professional IDE with advanced features:
- Intelligent code completion
- Built-in debugger
- Database tools
- Framework support
Sublime Text (Paid)
Lightweight with PHP packages:
- SublimeLinter-php
- PHPCompanion
- DocBlockr
Composer (Dependency Manager)
Composer is essential for modern PHP development.
Verify Installation:
Basic Usage:
Xdebug (Debugger)
Installation:
Configure in php.ini:
Web Server Configuration
Built-in Development Server
PHP includes a built-in web server for development:
Apache Configuration
Enable PHP Module:
Virtual Host Example:
Nginx Configuration
Basic PHP Configuration:
Database Setup
MySQL/MariaDB
Installation:
Basic Configuration:
PostgreSQL
Installation:
Development Workflow Setup
Project Structure
Composer Configuration
Git Configuration
Common Troubleshooting
Permission Issues (Linux/macOS)
PHP Extension Not Loading
- Check
php.inilocation:php --ini - Verify extension path in
php.ini - Restart web server after modifications
Port Conflicts
Next Steps
Now that your environment is set up, let's create your first PHP script in Quick Start.
Verification Checklist
- PHP is installed and accessible from command line
- Web server is running (Apache/Nginx or built-in server)
- Composer is installed and working
- Code editor is configured with PHP extensions
- Database server is running (if needed)
-
phpinfo()page is accessible in browser