0.2Setting up a local environment (XAMPP, Laragon)
The essentials in 30 seconds
- An all-in-one pack installs everything together: web server (Apache) + PHP + database (MySQL) preconfigured — XAMPP or Laragon.
- Your .php files go in the root folder: htdocs or www, accessible via http://localhost (your own machine).
- Check with phpinfo() before coding: an info.php file opened via localhost confirms that everything works.
Running mini-case — Riad sets up his workstation in Constantine
Riad, a web developer in Constantine, receives a blank laptop and must code his first PHP site without putting anything online. He installs an all-in-one pack (web server + PHP + database already connected), starts Apache and MySQL from the control panel, finds the root folder where to drop his .php files, then creates a test info.php file which he opens via localhost. The PHP information page displays: his environment is operational. He installs VS Code for editing and finds phpMyAdmin for his future databases.
Self-contained case for this section: it returns in the lesson, diagram, script and 48h challenge of section 0.2.
1. An all-in-one pack (AMP)
Developing in PHP requires a local environment: three building blocks, summarized by AMP — a web server (Apache), the PHP language (the interpreter), a database (MySQL / MariaDB). Installing and connecting them separately is tedious; all-in-one packs group and configure them together in one installation: XAMPP (cross-platform: Windows, macOS, Linux), Laragon (Windows, lightweight and popular), WampServer (Windows) or MAMP (macOS/Windows). To get started, Riad picks one, installs it, and immediately has a server + PHP + database ready to use — without touching the system configuration.
2. Root folder, localhost, phpinfo
Once installed, you start the services (Apache, MySQL) via the pack's control panel. You place your .php files in the web root folder (htdocs for XAMPP, www for others) and access them via http://localhost — localhost meaning your own machine. For the database, packs include phpMyAdmin, a web interface for managing MySQL without the command line. The first reflex: create info.php containing <?php phpinfo(); ?>, place it in the root and open it via localhost/info.php — if the PHP information page displays, everything works (and you can read the installed version there). Riad checks this way before writing his first line.
3. Editor and local / production caution
For the editor, VS Code is the standard choice (free, excellent PHP extensions), or PhpStorm (paid, very complete). Point of caution: LOCAL is for development and testing; production (going live, section 5-4) is another step — the PHP/MySQL versions should ideally match between the two to avoid the classic "it works locally but not online", just like file-name case (Windows ignores it, Linux respects it). Riad notes the versions shown by phpinfo to compare them later with his hosting.
🔎 Concrete example — 🔎 Concrete example — Checking the installation
The test file.
Reading: Riad opens localhost/info.php and sees the PHP information page: the server does execute his code.
Lesson: a working environment, ready to code locally — then remove info.php, which exposes the configuration.
Section vocabulary
- Local environment (AMP)
- What it takes to run PHP and a database on your machine for developing and testing. AMP = web server (Apache), PHP, database (MySQL) — often installed together via a pack.
Simple example: Riad develops his whole first site in Constantine without putting anything online.
What it is not: the production server accessible to visitors.
Reflex: code and test locally first, put online afterwards.
- All-in-one pack
- Installation bundling web server + PHP + database: XAMPP (cross-platform), Laragon, WampServer (Windows), MAMP (macOS) — the easiest way to get started.
Simple example: Riad installs a pack and gets Apache, PHP and MySQL already connected.
What it is not: three separate installations to configure and connect by hand.
Reflex: start with a pack, move to custom setup only if needed.
- Web root folder / localhost
- Folder where to place your .php files (htdocs, www) so they are served; you access them via http://localhost (your own machine).
Simple example: Riad drops bonjour.php in htdocs and opens it via localhost/bonjour.php.
What it is not: any folder, opened with a double-click without a server.
Reflex: PHP file = always in the root, always via localhost.
- phpMyAdmin
- Web interface (included in packs) for creating and managing MySQL databases without the command line.
Simple example: Riad creates his first database in a few clicks, without knowing SQL by heart.
What it is not: a code editor or a programming language.
Reflex: explore your tables via phpMyAdmin before writing queries.
- phpinfo()
- Function displaying PHP configuration information; an info.php file with phpinfo() checks that the environment works and shows the installed version.
Simple example: Riad reads his PHP version on the info.php page and notes it for his future production.
What it is not: a function that repairs the installation.
Reflex: check with phpinfo, note the version, then remove the file.
In practice — In practice — Installing and checking your PHP environment
- Install an all-in-one pack (XAMPP or Laragon) that bundles web server (Apache) + PHP + database (MySQL).
- Start the services (Apache, MySQL) via the control panel and find the web root folder (htdocs / www).
- Check the installation: create an info.php file with phpinfo(), open localhost/info.php — the PHP info page must display (with the version).
- Install VS Code (with PHP extensions) as your editor, and find phpMyAdmin for managing MySQL databases.
Script ready to say — announcing your workstation is ready (30 s)
"Workstation ready: pack installed, Apache and MySQL started, my files are in the root folder and localhost/info.php does show the PHP page. I edit with VS Code and manage my databases with phpMyAdmin — I can code locally."
Say while showing the phpinfo page displayed in the browser via localhost.
Copy-paste template — checking your PHP workstation
";
echo "PHP version: " . PHP_VERSION;
Windows workstation
On Windows: choose XAMPP (cross-platform) or Laragon (lightweight); after installation, start Apache and MySQL from the control panel before any test.
macOS workstation
On macOS: XAMPP or MAMP are suitable; find the root folder of your pack and always check via localhost/info.php.
Shared room in Constantine
Riad notes the PHP version shown by phpinfo on the shared workstation card: everyone checks the started services on arrival, without blindly reinstalling.
Busy-port recovery
localhost page unreachable: check that Apache is started and that no other software occupies its port, then reload info.php before touching the code.
✓ Best practices
- Choose a pack (XAMPP or Laragon) rather than installing the blocks separately.
- Check with phpinfo() before coding, then remove info.php.
- Align the local PHP/MySQL version with production.
✗ Common pitfalls
- Installing the three blocks separately as a beginner (complex, error-prone).
- Leaving info.php online (it exposes the configuration).
- Ignoring file case (Windows ignores it, Linux respects it).
Key takeaways
- Developing in PHP requires a LOCAL ENVIRONMENT: web server (Apache) + PHP + database (MySQL) = "AMP", installed together via a PACK (XAMPP, Laragon, WampServer, MAMP).
- Place your .php files in the ROOT FOLDER (htdocs / www); access them via http://localhost (your own machine). phpMyAdmin manages MySQL databases.
- Check the installation: an info.php file with `phpinfo()` opened via localhost/info.php displays the PHP info (and version) if everything works.
- Editor: VS Code (free, PHP extensions) or PhpStorm. The LOCAL environment is for dev/test; PRODUCTION (going live) is another step (5-4) — align versions.
48h challenge — apply tomorrow
Create info.php in your root folder, open it via localhost/info.php, note the PHP version displayed, then remove the file.
- My pack displays the phpinfo page via localhost/info.php (version noted).
- I found the root folder and started Apache and MySQL.
- VS Code is installed and phpMyAdmin found — then info.php removed.
Frequently asked questions
Why install an all-in-one pack rather than PHP, Apache and MySQL separately?
A dynamic PHP site needs three building blocks working TOGETHER: a web server receiving requests, the PHP interpreter executing the code, and a MySQL database. They must be installed, configured and above all connected. Installing separately is possible but complex for a beginner: each piece to configure and connect to the others, versions and ports to manage — tedious and discouraging. The all-in-one pack (XAMPP cross-platform, Laragon lightweight on Windows, WampServer, MAMP) bundles the three blocks plus tools (phpMyAdmin) in one preconfigured installation where everything works from the start: a few clicks, a simple control panel, operational in minutes. Separate installation offers more control but is reserved for advanced needs and production. To get started: one pack, one check (phpinfo), and you code.
Should I worry about the difference between my local environment and production?
Yes, it is a real issue — the source of the classic "it works locally but not online" — but to get started, just being aware is enough. Local and production can differ: PHP/MySQL versions, enabled extensions, operating system (Windows locally, often Linux in production), and above all FILE-NAME CASE (Windows ignores it, Linux respects it — a file that works locally may fail online). Good practices: (1) align the PHP/MySQL versions with your hosting; (2) be strict about the case of file names; (3) do not depend on local-specific settings; (4) separate configuration (credentials, keys) from code. The modern answer is Docker (section 5.3); fine mastery will come with deployment (5.4).
How do you check that a local PHP environment works?