2. Setting Up Your Development Environment
To write and run PHP code locally, we need a simulated server environment. We will use integrated packages that bundle Apache, MySQL, and PHP.
Choosing Your Package
- XAMPP: (Cross-platform, Apache, MariaDB, PHP, Perl) - Great for Windows, macOS, and Linux.
- WAMP: (Windows, Apache, MySQL, PHP) - Windows specific.
- MAMP: (Macintosh, Apache, MySQL, PHP) - macOS specific.
Installation Steps (General)
- Download: Go to the official XAMPP or MAMP website and download the installer for your operating system.
- Installation: Run the installer. Use the default installation location if possible (e.g.,
C:\xampp). - Control Panel: Once installed, open the XAMPP/MAMP Control Panel.
- Start Services: Start the Apache and MySQL services. They should turn green, indicating they are running.
The Document Root
This is the folder where you must save your PHP files for the server to find them.
- XAMPP (Windows/Linux):
C:\xampp\htdocs - MAMP (macOS):
/Applications/MAMP/htdocs
To test your setup:
- Save a file named
test.phpinside thehtdocsfolder. - In your browser, navigate to:
http://localhost/test.php.
If you see the output of the file, your environment is ready!